java.lang.Object | |
↳ | org.springframework.jdbc.datasource.DataSourceUtils |
Helper class that provides static methods for obtaining JDBC Connections from
a javax.sql.DataSource. Includes special support for Spring-managed
transactional Connections, e.g. managed by DataSourceTransactionManager
or JtaTransactionManager
.
Used internally by Spring's JdbcTemplate
,
Spring's JDBC operation objects and the JDBC DataSourceTransactionManager
.
Can also be used directly in application code.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | CONNECTION_SYNCHRONIZATION_ORDER | Order value for TransactionSynchronization objects that clean up JDBC Connections. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Apply the specified timeout - overridden by the current transaction timeout,
if any - to the given JDBC Statement object.
| |||||||||||
Apply the current transaction timeout, if any,
to the given JDBC Statement object.
| |||||||||||
Actually obtain a JDBC Connection from the given DataSource.
| |||||||||||
Actually close the given Connection, obtained from the given DataSource.
| |||||||||||
Obtain a Connection from the given DataSource.
| |||||||||||
Return the innermost target Connection of the given Connection.
| |||||||||||
Determine whether the given JDBC Connection is transactional, that is,
bound to the current thread by Spring's transaction facilities.
| |||||||||||
Prepare the given Connection with the given transaction semantics.
| |||||||||||
Close the given Connection, obtained from the given DataSource,
if it is not managed externally (that is, not bound to the thread).
| |||||||||||
Reset the given Connection after a transaction,
regarding read-only flag and isolation level.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Order value for TransactionSynchronization objects that clean up JDBC Connections.
Apply the specified timeout - overridden by the current transaction timeout, if any - to the given JDBC Statement object.
stmt | the JDBC Statement object |
---|---|
dataSource | the DataSource that the Connection was obtained from |
timeout | the timeout to apply (or 0 for no timeout outside of a transaction) |
SQLException | if thrown by JDBC methods |
---|
Apply the current transaction timeout, if any, to the given JDBC Statement object.
stmt | the JDBC Statement object |
---|---|
dataSource | the DataSource that the Connection was obtained from |
SQLException | if thrown by JDBC methods |
---|
Actually obtain a JDBC Connection from the given DataSource.
Same as getConnection(DataSource)
, but throwing the original SQLException.
Is aware of a corresponding Connection bound to the current thread, for example
when using DataSourceTransactionManager
. Will bind a Connection to the thread
if transaction synchronization is active (e.g. if in a JTA transaction).
Directly accessed by TransactionAwareDataSourceProxy
.
dataSource | the DataSource to obtain Connections from |
---|
SQLException | if thrown by JDBC methods |
---|
Actually close the given Connection, obtained from the given DataSource.
Same as releaseConnection(Connection, DataSource)
, but throwing the original SQLException.
Directly accessed by TransactionAwareDataSourceProxy
.
con | the Connection to close if necessary
(if this is null , the call will be ignored) |
---|---|
dataSource | the DataSource that the Connection was obtained from
(may be null ) |
SQLException | if thrown by JDBC methods |
---|
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 DataSourceTransactionManager
. Will bind a Connection to the
thread if transaction synchronization is active, e.g. when running within a
JTA
transaction).
dataSource | the DataSource to obtain Connections from |
---|
CannotGetJdbcConnectionException | if the attempt to get a Connection failed |
---|
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.
con | the Connection proxy to unwrap |
---|
Determine whether the given JDBC Connection is transactional, that is, bound to the current thread by Spring's transaction facilities.
con | the Connection to check |
---|---|
dataSource | the DataSource that the Connection was obtained from
(may be null ) |
Prepare the given Connection with the given transaction semantics.
con | the Connection to prepare |
---|---|
definition | the transaction definition to apply |
SQLException | if thrown by JDBC methods |
---|
Close the given Connection, obtained from the given DataSource, if it is not managed externally (that is, not bound to the thread).
con | the Connection to close if necessary
(if this is null , the call will be ignored) |
---|---|
dataSource | the DataSource that the Connection was obtained from
(may be null ) |
Reset the given Connection after a transaction, regarding read-only flag and isolation level.
con | the Connection to reset |
---|---|
previousIsolationLevel | the isolation level to restore, if any |