Java Code Examples for org.springframework.jdbc.datasource.ConnectionHandle

The following examples show how to use org.springframework.jdbc.datasource.ConnectionHandle. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: DefaultJpaDialect.java    License: MIT License 5 votes vote down vote up
/**
 * This implementation always returns {@code null},
 * indicating that no JDBC Connection can be provided.
 */
@Override
@Nullable
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	return null;
}
 
Example 2
Source Project: spring-analysis-note   Source File: EclipseLinkJpaDialect.java    License: MIT License 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	// As of Spring 4.1.2, we're using a custom ConnectionHandle for lazy retrieval
	// of the underlying Connection (allowing for deferred internal transaction begin
	// within the EclipseLink EntityManager)
	return new EclipseLinkConnectionHandle(entityManager);
}
 
Example 3
Source Project: spring-analysis-note   Source File: HibernateJpaDialect.java    License: MIT License 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	Session session = getSession(entityManager);
	return new HibernateConnectionHandle(session);
}
 
Example 4
Source Project: java-technology-stack   Source File: DefaultJpaDialect.java    License: MIT License 5 votes vote down vote up
/**
 * This implementation always returns {@code null},
 * indicating that no JDBC Connection can be provided.
 */
@Override
@Nullable
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	return null;
}
 
Example 5
Source Project: java-technology-stack   Source File: EclipseLinkJpaDialect.java    License: MIT License 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	// As of Spring 4.1.2, we're using a custom ConnectionHandle for lazy retrieval
	// of the underlying Connection (allowing for deferred internal transaction begin
	// within the EclipseLink EntityManager)
	return new EclipseLinkConnectionHandle(entityManager);
}
 
Example 6
Source Project: java-technology-stack   Source File: HibernateJpaDialect.java    License: MIT License 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	Session session = getSession(entityManager);
	return new HibernateConnectionHandle(session);
}
 
Example 7
Source Project: lams   Source File: DefaultJpaDialect.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * This implementation always returns {@code null},
 * indicating that no JDBC Connection can be provided.
 */
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	return null;
}
 
Example 8
Source Project: lams   Source File: EclipseLinkJpaDialect.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	// As of Spring 4.1.2, we're using a custom ConnectionHandle for lazy retrieval
	// of the underlying Connection (allowing for deferred internal transaction begin
	// within the EclipseLink EntityManager)
	return new EclipseLinkConnectionHandle(entityManager);
}
 
Example 9
Source Project: lams   Source File: HibernateJpaDialect.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	Session session = getSession(entityManager);
	return new HibernateConnectionHandle(session);
}
 
Example 10
Source Project: spring4-understanding   Source File: DefaultJpaDialect.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This implementation always returns {@code null},
 * indicating that no JDBC Connection can be provided.
 */
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	return null;
}
 
Example 11
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	// As of Spring 4.1.2, we're using a custom ConnectionHandle for lazy retrieval
	// of the underlying Connection (allowing for deferred internal transaction begin
	// within the EclipseLink EntityManager)
	return new EclipseLinkConnectionHandle(entityManager);
}
 
Example 12
Source Project: spring4-understanding   Source File: HibernateJpaDialect.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	Session session = getSession(entityManager);
	return new HibernateConnectionHandle(session);
}
 
Example 13
Source Project: spring-analysis-note   Source File: JpaTransactionManager.java    License: MIT License 4 votes vote down vote up
@Override
protected void doCleanupAfterCompletion(Object transaction) {
	JpaTransactionObject txObject = (JpaTransactionObject) transaction;

	// Remove the entity manager holder from the thread, if still there.
	// (Could have been removed by EntityManagerFactoryUtils in order
	// to replace it with an unsynchronized EntityManager).
	if (txObject.isNewEntityManagerHolder()) {
		TransactionSynchronizationManager.unbindResourceIfPossible(obtainEntityManagerFactory());
	}
	txObject.getEntityManagerHolder().clear();

	// Remove the JDBC connection holder from the thread, if exposed.
	if (getDataSource() != null && txObject.hasConnectionHolder()) {
		TransactionSynchronizationManager.unbindResource(getDataSource());
		ConnectionHandle conHandle = txObject.getConnectionHolder().getConnectionHandle();
		if (conHandle != null) {
			try {
				getJpaDialect().releaseJdbcConnection(conHandle,
						txObject.getEntityManagerHolder().getEntityManager());
			}
			catch (Exception ex) {
				// Just log it, to keep a transaction-related exception.
				logger.error("Could not close JDBC connection after transaction", ex);
			}
		}
	}

	getJpaDialect().cleanupTransaction(txObject.getTransactionData());

	// Remove the entity manager holder from the thread.
	if (txObject.isNewEntityManagerHolder()) {
		EntityManager em = txObject.getEntityManagerHolder().getEntityManager();
		if (logger.isDebugEnabled()) {
			logger.debug("Closing JPA EntityManager [" + em + "] after transaction");
		}
		EntityManagerFactoryUtils.closeEntityManager(em);
	}
	else {
		logger.debug("Not closing pre-bound JPA EntityManager after transaction");
	}
}
 
Example 14
Source Project: java-technology-stack   Source File: JpaTransactionManager.java    License: MIT License 4 votes vote down vote up
@Override
protected void doCleanupAfterCompletion(Object transaction) {
	JpaTransactionObject txObject = (JpaTransactionObject) transaction;

	// Remove the entity manager holder from the thread, if still there.
	// (Could have been removed by EntityManagerFactoryUtils in order
	// to replace it with an unsynchronized EntityManager).
	if (txObject.isNewEntityManagerHolder()) {
		TransactionSynchronizationManager.unbindResourceIfPossible(obtainEntityManagerFactory());
	}
	txObject.getEntityManagerHolder().clear();

	// Remove the JDBC connection holder from the thread, if exposed.
	if (getDataSource() != null && txObject.hasConnectionHolder()) {
		TransactionSynchronizationManager.unbindResource(getDataSource());
		ConnectionHandle conHandle = txObject.getConnectionHolder().getConnectionHandle();
		if (conHandle != null) {
			try {
				getJpaDialect().releaseJdbcConnection(conHandle,
						txObject.getEntityManagerHolder().getEntityManager());
			}
			catch (Exception ex) {
				// Just log it, to keep a transaction-related exception.
				logger.error("Could not close JDBC connection after transaction", ex);
			}
		}
	}

	getJpaDialect().cleanupTransaction(txObject.getTransactionData());

	// Remove the entity manager holder from the thread.
	if (txObject.isNewEntityManagerHolder()) {
		EntityManager em = txObject.getEntityManagerHolder().getEntityManager();
		if (logger.isDebugEnabled()) {
			logger.debug("Closing JPA EntityManager [" + em + "] after transaction");
		}
		EntityManagerFactoryUtils.closeEntityManager(em);
	}
	else {
		logger.debug("Not closing pre-bound JPA EntityManager after transaction");
	}
}
 
Example 15
Source Project: lams   Source File: OpenJpaDialect.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	return new OpenJpaConnectionHandle(getOpenJPAEntityManager(entityManager));
}
 
Example 16
Source Project: spring4-understanding   Source File: OpenJpaDialect.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException {

	return new OpenJpaConnectionHandle(getOpenJPAEntityManager(entityManager));
}
 
Example 17
@Test
public void testTransactionCommitWithDataSource() throws SQLException {
	final DataSource ds = mock(DataSource.class);
	JdoDialect dialect = mock(JdoDialect.class);
	final Connection con = mock(Connection.class);
	ConnectionHandle conHandle = new SimpleConnectionHandle(con);

	given(pmf.getPersistenceManager()).willReturn(pm);
	given(pm.currentTransaction()).willReturn(tx);
	TransactionTemplate tt = new TransactionTemplate();
	given(dialect.getJdbcConnection(pm, false)).willReturn(conHandle);

	JdoTransactionManager tm = new JdoTransactionManager();
	tm.setPersistenceManagerFactory(pmf);
	tm.setDataSource(ds);
	tm.setJdoDialect(dialect);
	tt.setTransactionManager(tm);
	final List l = new ArrayList();
	l.add("test");
	assertTrue("Hasn't thread pm", !TransactionSynchronizationManager.hasResource(pmf));

	Object result = tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			assertTrue("Has thread pm", TransactionSynchronizationManager.hasResource(pmf));
			assertTrue("Has thread con", TransactionSynchronizationManager.hasResource(ds));
			PersistenceManagerFactoryUtils.getPersistenceManager(pmf, true);
			return l;
		}
	});
	assertTrue("Correct result list", result == l);

	assertTrue("Hasn't thread pm", !TransactionSynchronizationManager.hasResource(pmf));
	assertTrue("Hasn't thread con", !TransactionSynchronizationManager.hasResource(ds));

	verify(pm).close();
	verify(dialect).beginTransaction(tx, tt);
	verify(dialect).releaseJdbcConnection(conHandle, pm);
	verify(dialect).cleanupTransaction(null);
	verify(tx).commit();
}
 
Example 18
@Test
public void testTransactionCommitWithAutoDetectedDataSource() throws SQLException {
	final DataSource ds = mock(DataSource.class);
	JdoDialect dialect = mock(JdoDialect.class);
	final Connection con = mock(Connection.class);
	ConnectionHandle conHandle = new SimpleConnectionHandle(con);

	given(pmf.getConnectionFactory()).willReturn(ds);
	given(pmf.getPersistenceManager()).willReturn(pm);
	given(pm.currentTransaction()).willReturn(tx);
	TransactionTemplate tt = new TransactionTemplate();
	given(dialect.getJdbcConnection(pm, false)).willReturn(conHandle);

	JdoTransactionManager tm = new JdoTransactionManager();
	tm.setPersistenceManagerFactory(pmf);
	tm.setJdoDialect(dialect);
	tm.afterPropertiesSet();
	tt.setTransactionManager(tm);
	final List l = new ArrayList();
	l.add("test");
	assertTrue("Hasn't thread pm", !TransactionSynchronizationManager.hasResource(pmf));

	Object result = tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			assertTrue("Has thread pm", TransactionSynchronizationManager.hasResource(pmf));
			assertTrue("Has thread con", TransactionSynchronizationManager.hasResource(ds));
			PersistenceManagerFactoryUtils.getPersistenceManager(pmf, true);
			return l;
		}
	});
	assertTrue("Correct result list", result == l);

	assertTrue("Hasn't thread pm", !TransactionSynchronizationManager.hasResource(pmf));
	assertTrue("Hasn't thread con", !TransactionSynchronizationManager.hasResource(ds));

	verify(pm).close();
	verify(dialect).beginTransaction(tx, tt);
	verify(dialect).releaseJdbcConnection(conHandle, pm);
	verify(dialect).cleanupTransaction(null);
	verify(tx).commit();
}
 
Example 19
Source Project: syncope   Source File: OpenJpaDialect.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionHandle getJdbcConnection(final EntityManager entityManager, final boolean readOnly)
        throws PersistenceException, SQLException {

    return new OpenJpaConnectionHandle(getOpenJPAEntityManager(entityManager));
}
 
Example 20
Source Project: lams   Source File: DefaultJdoDialect.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * This implementation returns a DataStoreConnectionHandle for JDO.
 * <p><b>NOTE:</b> A JDO DataStoreConnection is always a wrapper,
 * never the native JDBC Connection. If you need access to the native JDBC
 * Connection (or the connection pool handle, to be unwrapped via a Spring
 * NativeJdbcExtractor), override this method to return the native
 * Connection through the corresponding vendor-specific mechanism.
 * <p>A JDO DataStoreConnection is only "borrowed" from the PersistenceManager:
 * it needs to be returned as early as possible. Effectively, JDO requires the
 * fetched Connection to be closed before continuing PersistenceManager work.
 * For this reason, the exposed ConnectionHandle eagerly releases its JDBC
 * Connection at the end of each JDBC data access operation (that is, on
 * {@code DataSourceUtils.releaseConnection}).
 * @see javax.jdo.PersistenceManager#getDataStoreConnection()
 * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
 * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
 */
@Override
public ConnectionHandle getJdbcConnection(PersistenceManager pm, boolean readOnly)
		throws JDOException, SQLException {

	return new DataStoreConnectionHandle(pm);
}
 
Example 21
Source Project: spring4-understanding   Source File: DefaultJdoDialect.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * This implementation returns a DataStoreConnectionHandle for JDO.
 * <p><b>NOTE:</b> A JDO DataStoreConnection is always a wrapper,
 * never the native JDBC Connection. If you need access to the native JDBC
 * Connection (or the connection pool handle, to be unwrapped via a Spring
 * NativeJdbcExtractor), override this method to return the native
 * Connection through the corresponding vendor-specific mechanism.
 * <p>A JDO DataStoreConnection is only "borrowed" from the PersistenceManager:
 * it needs to be returned as early as possible. Effectively, JDO requires the
 * fetched Connection to be closed before continuing PersistenceManager work.
 * For this reason, the exposed ConnectionHandle eagerly releases its JDBC
 * Connection at the end of each JDBC data access operation (that is, on
 * {@code DataSourceUtils.releaseConnection}).
 * @see javax.jdo.PersistenceManager#getDataStoreConnection()
 * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
 * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
 */
@Override
public ConnectionHandle getJdbcConnection(PersistenceManager pm, boolean readOnly)
		throws JDOException, SQLException {

	return new DataStoreConnectionHandle(pm);
}
 
Example 22
Source Project: spring-analysis-note   Source File: DefaultJpaDialect.java    License: MIT License 2 votes vote down vote up
/**
 * This implementation does nothing, assuming that the Connection
 * will implicitly be closed with the EntityManager.
 * <p>If the JPA implementation returns a Connection handle that it expects
 * the application to close after use, the dialect implementation needs to invoke
 * {@code Connection.close()} (or some other method with similar effect) here.
 * @see java.sql.Connection#close()
 */
@Override
public void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em)
		throws PersistenceException, SQLException {
}
 
Example 23
Source Project: spring-analysis-note   Source File: JpaDialect.java    License: MIT License 2 votes vote down vote up
/**
 * Retrieve the JDBC Connection that the given JPA EntityManager uses underneath,
 * if accessing a relational database. This method will just get invoked if actually
 * needing access to the underlying JDBC Connection, usually within an active JPA
 * transaction (for example, by JpaTransactionManager). The returned handle will
 * be passed into the {@code releaseJdbcConnection} method when not needed anymore.
 * <p>This strategy is necessary as JPA does not provide a standard way to retrieve
 * the underlying JDBC Connection (due to the fact that a JPA implementation might not
 * work with a relational database at all).
 * <p>Implementations are encouraged to return an unwrapped Connection object, i.e.
 * the Connection as they got it from the connection pool. This makes it easier for
 * application code to get at the underlying native JDBC Connection, like an
 * OracleConnection, which is sometimes necessary for LOB handling etc. We assume
 * that calling code knows how to properly handle the returned Connection object.
 * <p>In a simple case where the returned Connection will be auto-closed with the
 * EntityManager or can be released via the Connection object itself, an
 * implementation can return a SimpleConnectionHandle that just contains the
 * Connection. If some other object is needed in {@code releaseJdbcConnection},
 * an implementation should use a special handle that references that other object.
 * @param entityManager the current JPA EntityManager
 * @param readOnly whether the Connection is only needed for read-only purposes
 * @return a handle for the Connection, to be passed into {@code releaseJdbcConnection},
 * or {@code null} if no JDBC Connection can be retrieved
 * @throws javax.persistence.PersistenceException if thrown by JPA methods
 * @throws java.sql.SQLException if thrown by JDBC methods
 * @see #releaseJdbcConnection
 * @see org.springframework.jdbc.datasource.ConnectionHandle#getConnection
 * @see org.springframework.jdbc.datasource.SimpleConnectionHandle
 * @see JpaTransactionManager#setDataSource
 */
@Nullable
ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException;
 
Example 24
Source Project: spring-analysis-note   Source File: JpaDialect.java    License: MIT License 2 votes vote down vote up
/**
 * Release the given JDBC Connection, which has originally been retrieved
 * via {@code getJdbcConnection}. This should be invoked in any case,
 * to allow for proper release of the retrieved Connection handle.
 * <p>An implementation might simply do nothing, if the Connection returned
 * by {@code getJdbcConnection} will be implicitly closed when the JPA
 * transaction completes or when the EntityManager is closed.
 * @param conHandle the JDBC Connection handle to release
 * @param entityManager the current JPA EntityManager
 * @throws javax.persistence.PersistenceException if thrown by JPA methods
 * @throws java.sql.SQLException if thrown by JDBC methods
 * @see #getJdbcConnection
 */
void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager entityManager)
		throws PersistenceException, SQLException;
 
Example 25
Source Project: java-technology-stack   Source File: DefaultJpaDialect.java    License: MIT License 2 votes vote down vote up
/**
 * This implementation does nothing, assuming that the Connection
 * will implicitly be closed with the EntityManager.
 * <p>If the JPA implementation returns a Connection handle that it expects
 * the application to close after use, the dialect implementation needs to invoke
 * {@code Connection.close()} (or some other method with similar effect) here.
 * @see java.sql.Connection#close()
 */
@Override
public void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em)
		throws PersistenceException, SQLException {
}
 
Example 26
Source Project: java-technology-stack   Source File: JpaDialect.java    License: MIT License 2 votes vote down vote up
/**
 * Retrieve the JDBC Connection that the given JPA EntityManager uses underneath,
 * if accessing a relational database. This method will just get invoked if actually
 * needing access to the underlying JDBC Connection, usually within an active JPA
 * transaction (for example, by JpaTransactionManager). The returned handle will
 * be passed into the {@code releaseJdbcConnection} method when not needed anymore.
 * <p>This strategy is necessary as JPA does not provide a standard way to retrieve
 * the underlying JDBC Connection (due to the fact that a JPA implementation might not
 * work with a relational database at all).
 * <p>Implementations are encouraged to return an unwrapped Connection object, i.e.
 * the Connection as they got it from the connection pool. This makes it easier for
 * application code to get at the underlying native JDBC Connection, like an
 * OracleConnection, which is sometimes necessary for LOB handling etc. We assume
 * that calling code knows how to properly handle the returned Connection object.
 * <p>In a simple case where the returned Connection will be auto-closed with the
 * EntityManager or can be released via the Connection object itself, an
 * implementation can return a SimpleConnectionHandle that just contains the
 * Connection. If some other object is needed in {@code releaseJdbcConnection},
 * an implementation should use a special handle that references that other object.
 * @param entityManager the current JPA EntityManager
 * @param readOnly whether the Connection is only needed for read-only purposes
 * @return a handle for the Connection, to be passed into {@code releaseJdbcConnection},
 * or {@code null} if no JDBC Connection can be retrieved
 * @throws javax.persistence.PersistenceException if thrown by JPA methods
 * @throws java.sql.SQLException if thrown by JDBC methods
 * @see #releaseJdbcConnection
 * @see org.springframework.jdbc.datasource.ConnectionHandle#getConnection
 * @see org.springframework.jdbc.datasource.SimpleConnectionHandle
 * @see JpaTransactionManager#setDataSource
 */
@Nullable
ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException;
 
Example 27
Source Project: java-technology-stack   Source File: JpaDialect.java    License: MIT License 2 votes vote down vote up
/**
 * Release the given JDBC Connection, which has originally been retrieved
 * via {@code getJdbcConnection}. This should be invoked in any case,
 * to allow for proper release of the retrieved Connection handle.
 * <p>An implementation might simply do nothing, if the Connection returned
 * by {@code getJdbcConnection} will be implicitly closed when the JPA
 * transaction completes or when the EntityManager is closed.
 * @param conHandle the JDBC Connection handle to release
 * @param entityManager the current JPA EntityManager
 * @throws javax.persistence.PersistenceException if thrown by JPA methods
 * @throws java.sql.SQLException if thrown by JDBC methods
 * @see #getJdbcConnection
 */
void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager entityManager)
		throws PersistenceException, SQLException;
 
Example 28
Source Project: lams   Source File: DefaultJpaDialect.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * This implementation does nothing, assuming that the Connection
 * will implicitly be closed with the EntityManager.
 * <p>If the JPA implementation returns a Connection handle that it expects
 * the application to close after use, the dialect implementation needs to invoke
 * {@code Connection.close()} (or some other method with similar effect) here.
 * @see java.sql.Connection#close()
 */
@Override
public void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em)
		throws PersistenceException, SQLException {
}
 
Example 29
Source Project: lams   Source File: JpaDialect.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieve the JDBC Connection that the given JPA EntityManager uses underneath,
 * if accessing a relational database. This method will just get invoked if actually
 * needing access to the underlying JDBC Connection, usually within an active JPA
 * transaction (for example, by JpaTransactionManager). The returned handle will
 * be passed into the {@code releaseJdbcConnection} method when not needed anymore.
 * <p>This strategy is necessary as JPA does not provide a standard way to retrieve
 * the underlying JDBC Connection (due to the fact that a JPA implementation might not
 * work with a relational database at all).
 * <p>Implementations are encouraged to return an unwrapped Connection object, i.e.
 * the Connection as they got it from the connection pool. This makes it easier for
 * application code to get at the underlying native JDBC Connection, like an
 * OracleConnection, which is sometimes necessary for LOB handling etc. We assume
 * that calling code knows how to properly handle the returned Connection object.
 * <p>In a simple case where the returned Connection will be auto-closed with the
 * EntityManager or can be released via the Connection object itself, an
 * implementation can return a SimpleConnectionHandle that just contains the
 * Connection. If some other object is needed in {@code releaseJdbcConnection},
 * an implementation should use a special handle that references that other object.
 * @param entityManager the current JPA EntityManager
 * @param readOnly whether the Connection is only needed for read-only purposes
 * @return a handle for the Connection, to be passed into {@code releaseJdbcConnection},
 * or {@code null} if no JDBC Connection can be retrieved
 * @throws javax.persistence.PersistenceException if thrown by JPA methods
 * @throws java.sql.SQLException if thrown by JDBC methods
 * @see #releaseJdbcConnection
 * @see org.springframework.jdbc.datasource.ConnectionHandle#getConnection
 * @see org.springframework.jdbc.datasource.SimpleConnectionHandle
 * @see JpaTransactionManager#setDataSource
 * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
 */
ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
		throws PersistenceException, SQLException;
 
Example 30
Source Project: lams   Source File: JpaDialect.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Release the given JDBC Connection, which has originally been retrieved
 * via {@code getJdbcConnection}. This should be invoked in any case,
 * to allow for proper release of the retrieved Connection handle.
 * <p>An implementation might simply do nothing, if the Connection returned
 * by {@code getJdbcConnection} will be implicitly closed when the JPA
 * transaction completes or when the EntityManager is closed.
 * @param conHandle the JDBC Connection handle to release
 * @param entityManager the current JPA EntityManager
 * @throws javax.persistence.PersistenceException if thrown by JPA methods
 * @throws java.sql.SQLException if thrown by JDBC methods
 * @see #getJdbcConnection
 */
void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager entityManager)
		throws PersistenceException, SQLException;