Save This Page
Home » spring-framework-2.5.6-with-dependencies » org.springframework » jdbc » datasource » [javadoc | source]
org.springframework.jdbc.datasource
abstract public class: DataSourceUtils [javadoc | source]
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 org.springframework.transaction.jta.JtaTransactionManager .

Used internally by Spring's org.springframework.jdbc.core.JdbcTemplate , Spring's JDBC operation objects and the JDBC DataSourceTransactionManager . Can also be used directly in application code.

Field Summary
public static final  int CONNECTION_SYNCHRONIZATION_ORDER    Order value for TransactionSynchronization objects that clean up JDBC Connections. 
Method from org.springframework.jdbc.datasource.DataSourceUtils Summary:
applyTimeout,   applyTransactionTimeout,   doGetConnection,   doReleaseConnection,   getConnection,   getTargetConnection,   isConnectionTransactional,   prepareConnectionForTransaction,   releaseConnection,   resetConnectionAfterTransaction
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.jdbc.datasource.DataSourceUtils Detail:
 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.
 public static  void applyTransactionTimeout(Statement stmt,
    DataSource dataSource) throws SQLException 
    Apply the current transaction timeout, if any, to the given JDBC Statement object.
 public static Connection doGetConnection(DataSource dataSource) throws SQLException 
    Actually obtain a JDBC Connection from the given DataSource. Same as #getConnection , 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 .

 public static  void doReleaseConnection(Connection con,
    DataSource dataSource) throws SQLException 
 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 DataSourceTransactionManager . Will bind a Connection to the thread if transaction synchronization is active, e.g. when running within a JTA transaction).

 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.
 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.
 public static Integer prepareConnectionForTransaction(Connection con,
    TransactionDefinition definition) throws SQLException 
    Prepare the given Connection with the given transaction semantics.
 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).
 public static  void resetConnectionAfterTransaction(Connection con,
    Integer previousIsolationLevel) 
    Reset the given Connection after a transaction, regarding read-only flag and isolation level.