Connections
from a javax.sql.DataSource . Includes special support for Spring-managed
transactional Connections, e.g. managed by DataSourceTransactionManager
or org.springframework.transaction.jta.JtaTransactionManager .
Used internally by Spring's org.,
Spring's JDBC operation objects and the JDBC DataSourceTransactionManager.
Can also be used directly in application code.
getConnection, releaseConnection, org.springframework.jdbc.core.JdbcTemplate , org.springframework.jdbc.support.JdbcTransactionManager , org.springframework.transaction.jta.JtaTransactionManager , org.springframework.transaction.support.TransactionSynchronizationManager
| Modifier and Type | Class and Description |
|---|---|
| private static class | DataSourceUtils.
Callback for resource cleanup at the end of a non-native JDBC transaction (e.g. when participating in a JtaTransactionManager transaction). |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | CONNECTION_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up JDBC Connections. |
| private static final Log |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | applyTimeout(Statement
the JDBC Statement object stmt, DataSource the DataSource that the Connection was obtained from dataSource, int the timeout to apply (or 0 for no timeout outside of a transaction) timeout)Apply the specified timeout - overridden by the current transaction timeout, if any - to the given JDBC Statement object. |
| public static void | applyTransactionTimeout(Statement
the JDBC Statement object stmt, DataSource the DataSource that the Connection was obtained from dataSource)Apply the current transaction timeout, if any, to the given JDBC Statement object. |
| private static boolean | Returns: whether the given Connections are equalthe ConnectionHolder for the held Connection (potentially a proxy) conHolder, Connection the Connection passed-in by the user
(potentially a target Connection without proxy) passedInCon)Determine whether the given two Connections are equal, asking the target Connection in case of a proxy. |
| public static void | doCloseConnection(Connection
the Connection to close if necessary con, DataSource the DataSource that the Connection was obtained from dataSource)Close the Connection, unless a |
| public static Connection | Returns: a JDBC Connection from the given DataSourcethe DataSource to obtain Connections from dataSource)Actually obtain a JDBC Connection from the given DataSource. |
| public static void | doReleaseConnection(Connection
the Connection to close if necessary
(if this is con, DataSource null, the call will be ignored)the DataSource that the Connection was obtained from
(may be dataSource)null)Actually close the given Connection, obtained from the given DataSource. |
| private static Connection | Returns: a JDBC Connection from the given DataSource (nevernull)the DataSource to obtain Connections from dataSource)Actually fetch a |
| public static Connection | Returns: a JDBC Connection from the given DataSourcethe DataSource to obtain Connections from dataSource)Obtain a Connection from the given DataSource. |
| private static int | Returns: the connection synchronization order to usethe DataSource to check dataSource)Determine the connection synchronization order to use for the given DataSource. |
| public static Connection | Returns: the innermost target Connection, or the passed-in one if no proxythe Connection proxy to unwrap con)Return the innermost target Connection of the given Connection. |
| public static boolean | Returns: whether the Connection is transactionalthe Connection to check con, DataSource the DataSource that the Connection was obtained from
(may be dataSource)null)Determine whether the given JDBC Connection is transactional, that is, bound to the current thread by Spring's transaction facilities. |
| public static Integer | Returns: the previous isolation level, if anythe Connection to prepare con, TransactionDefinition the transaction definition to apply definition)Prepare the given Connection with the given transaction semantics. |
| public static void | releaseConnection(Connection
the Connection to close if necessary
(if this is con, DataSource null, the call will be ignored)the DataSource that the Connection was obtained from
(may be dataSource)null)Close the given Connection, obtained from the given DataSource, if it is not managed externally (that is, not bound to the thread). |
| public static void | resetConnectionAfterTransaction(Connection
the Connection to reset con, Integer the isolation level to restore, if any previousIsolationLevel, boolean whether to reset the connection's read-only flag resetReadOnly)Reset the given Connection after a transaction, regarding read-only flag and isolation level. |
| public static void | resetConnectionAfterTransaction(Connection
the Connection to reset con, Integer the isolation level to restore, if any previousIsolationLevel)
Deprecated
as of 5.1.11, in favor of
resetConnectionAfterTransaction(Connection, Integer, boolean)
Reset the given Connection after a transaction, regarding read-only flag and isolation level. |
| CONNECTION_SYNCHRONIZATION_ORDER | back to summary |
|---|---|
| public static final int CONNECTION_SYNCHRONIZATION_ORDER Order value for TransactionSynchronization objects that clean up JDBC Connections. | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| DataSourceUtils | back to summary |
|---|---|
| public DataSourceUtils() | |
| applyTimeout | back to summary |
|---|---|
| public static void applyTimeout(Statement stmt, DataSource dataSource, int timeout) throws SQLException Apply the specified timeout - overridden by the current transaction timeout, if any - to the given JDBC Statement object.
| |
| applyTransactionTimeout | back to summary |
|---|---|
| public static void applyTransactionTimeout(Statement stmt, DataSource dataSource) throws SQLException Apply the current transaction timeout, if any, to the given JDBC Statement object.
| |
| connectionEquals | back to summary |
|---|---|
| private static boolean connectionEquals(ConnectionHolder conHolder, Connection passedInCon) Determine whether the given two Connections are equal, asking the target Connection in case of a proxy. Used to detect equality even if the user passed in a raw target Connection while the held one is a proxy.
| |
| doCloseConnection | back to summary |
|---|---|
| public static void doCloseConnection(Connection con, DataSource dataSource) throws SQLException Close the Connection, unless a
| |
| doGetConnection | back to summary |
|---|---|
| public static Connection doGetConnection(DataSource dataSource) throws SQLException Actually obtain a JDBC Connection from the given DataSource.
Same as Is aware of a corresponding Connection bound to the current thread, for example
when using Directly accessed by
| |
| doReleaseConnection | back to summary |
|---|---|
| public static void doReleaseConnection(Connection con, DataSource dataSource) throws SQLException Actually close the given Connection, obtained from the given DataSource.
Same as Directly accessed by
| |
| fetchConnection | back to summary |
|---|---|
| private static Connection fetchConnection(DataSource dataSource) throws SQLException Actually fetch a
| |
| getConnection | back to summary |
|---|---|
| public static Connection getConnection(DataSource dataSource) throws CannotGetJdbcConnectionException Obtain a Connection from the given DataSource. Translates SQLExceptions into the Spring hierarchy of unchecked generic data access exceptions, simplifying calling code and making any exception that is thrown more meaningful. Is aware of a corresponding Connection bound to the current thread, for example
when using
| |
| getConnectionSynchronizationOrder | back to summary |
|---|---|
| private static int getConnectionSynchronizationOrder(DataSource dataSource) Determine the connection synchronization order to use for the given DataSource. Decreased for every level of nesting that a DataSource has, checked through the level of DelegatingDataSource nesting.
| |
| getTargetConnection | back to summary |
|---|---|
| public static Connection getTargetConnection(Connection con) Return the innermost target Connection of the given Connection. If the given Connection is a proxy, it will be unwrapped until a non-proxy Connection is found. Otherwise, the passed-in Connection will be returned as-is.
| |
| isConnectionTransactional | back to summary |
|---|---|
| public static boolean isConnectionTransactional(Connection con, DataSource dataSource) Determine whether the given JDBC Connection is transactional, that is, bound to the current thread by Spring's transaction facilities.
| |
| prepareConnectionForTransaction | back to summary |
|---|---|
| public static Integer prepareConnectionForTransaction(Connection con, TransactionDefinition definition) throws SQLException Prepare the given Connection with the given transaction semantics.
| |
| releaseConnection | back to summary |
|---|---|
| public static void releaseConnection(Connection con, DataSource dataSource) Close the given Connection, obtained from the given DataSource, if it is not managed externally (that is, not bound to the thread).
| |
| resetConnectionAfterTransaction | back to summary |
|---|---|
| public static void resetConnectionAfterTransaction(Connection con, Integer previousIsolationLevel, boolean resetReadOnly) Reset the given Connection after a transaction, regarding read-only flag and isolation level.
| |
| resetConnectionAfterTransaction | back to summary |
|---|---|
| public static void resetConnectionAfterTransaction(Connection con, Integer previousIsolationLevel)
Deprecated as of 5.1.11, in favor of
Reset the given Connection after a transaction, regarding read-only flag and isolation level.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ConnectionHolder | |
| private final DataSource | |
| private boolean | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterCompletion(int
completion status according to the status)STATUS_* constantsOverrides default org. Invoked after transaction commit/rollback. |
| public void | beforeCompletion()
Overrides default org. Invoked before transaction commit/rollback. |
| public int | getOrder()
Overrides default org. Return the execution order for this transaction synchronization. |
| public void | resume()
Overrides default org. Resume this synchronization. |
| public void | suspend()
Overrides default org. Suspend this synchronization. |
| connectionHolder | back to summary |
|---|---|
| private final ConnectionHolder connectionHolder | |
| dataSource | back to summary |
|---|---|
| private final DataSource dataSource | |
| holderActive | back to summary |
|---|---|
| private boolean holderActive | |
| order | back to summary |
|---|---|
| private final int order | |
| ConnectionSynchronization | back to summary |
|---|---|
| public ConnectionSynchronization(ConnectionHolder connectionHolder, DataSource dataSource) | |
| afterCompletion | back to summary |
|---|---|
| public void afterCompletion(int status) Overrides default org. Doc from org. Invoked after transaction commit/rollback. Can perform resource cleanup after transaction completion. Note The transaction will have been committed or rolled back already,
but the transactional resources might still be active and accessible. As a
consequence, any data access code triggered at this point will still "participate"
in the original transaction, allowing to perform some cleanup (with no commit
following anymore!), unless it explicitly declares that it needs to run in a
separate transaction. Hence: Use
| |
| beforeCompletion | back to summary |
|---|---|
| public void beforeCompletion() Overrides default org. Doc from org. Invoked before transaction commit/rollback. Can perform resource cleanup before transaction completion. This method will be invoked after
| |
| getOrder | back to summary |
|---|---|
| public int getOrder() Overrides default org. Doc from org. Return the execution order for this transaction synchronization. Default is
| |
| resume | back to summary |
|---|---|
| public void resume() Overrides default org. Doc from org. Resume this synchronization. Supposed to rebind resources to TransactionSynchronizationManager if managing any.
| |
| suspend | back to summary |
|---|---|
| public void suspend() Overrides default org. Doc from org. Suspend this synchronization. Supposed to unbind resources from TransactionSynchronizationManager if managing any.
| |