Class ConnectionHolder

  • All Implemented Interfaces:

    public class ConnectionHolder
    extends ResourceHolderSupport
    Resource holder wrapping a JDBC Connection. DataSourceTransactionManager binds instances of this class to the thread, for a specific DataSource.

    Inherits rollback-only support for nested JDBC transactions and reference count functionality from the base class.

    Note: This is an SPI class, not intended to be used by applications.

    Juergen Hoeller
    See Also:
    DataSourceTransactionManager, DataSourceUtils
    • Field Detail


        public static final java.lang.String SAVEPOINT_NAME_PREFIX
        Prefix for savepoint names.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ConnectionHolder

        public ConnectionHolder(ConnectionHandle connectionHandle)
        Create a new ConnectionHolder for the given ConnectionHandle.
        connectionHandle - the ConnectionHandle to hold
      • ConnectionHolder

        public ConnectionHolder(java.sql.Connection connection,
                                boolean transactionActive)
        Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle.
        connection - the JDBC Connection to hold
        transactionActive - whether the given Connection is involved in an ongoing transaction
        See Also:
    • Method Detail

      • getConnectionHandle

        public ConnectionHandle getConnectionHandle()
        Return the ConnectionHandle held by this ConnectionHolder.
      • hasConnection

        protected boolean hasConnection()
        Return whether this holder currently has a Connection.
      • setTransactionActive

        protected void setTransactionActive(boolean transactionActive)
        Set whether this holder represents an active, JDBC-managed transaction.
        See Also:
      • isTransactionActive

        protected boolean isTransactionActive()
        Return whether this holder represents an active, JDBC-managed transaction.
      • setConnection

        protected void setConnection(@Nullable
                                     java.sql.Connection connection)
        Override the existing Connection handle with the given Connection. Reset the handle if given null.

        Used for releasing the Connection on suspend (with a null argument) and setting a fresh Connection on resume.

      • getConnection

        public java.sql.Connection getConnection()
        Return the current Connection held by this ConnectionHolder.

        This will be the same Connection until released gets called on the ConnectionHolder, which will reset the held Connection, fetching a new Connection on demand.

        See Also:
        ConnectionHandle.getConnection(), released()
      • supportsSavepoints

        public boolean supportsSavepoints()
                                   throws java.sql.SQLException
        Return whether JDBC 3.0 Savepoints are supported. Caches the flag for the lifetime of this ConnectionHolder.
        java.sql.SQLException - if thrown by the JDBC driver
      • createSavepoint

        public java.sql.Savepoint createSavepoint()
                                           throws java.sql.SQLException
        Create a new JDBC 3.0 Savepoint for the current Connection, using generated savepoint names that are unique for the Connection.
        the new Savepoint
        java.sql.SQLException - if thrown by the JDBC driver
      • released

        public void released()
        Releases the current Connection held by this ConnectionHolder.

        This is necessary for ConnectionHandles that expect "Connection borrowing", where each returned Connection is only temporarily leased and needs to be returned once the data operation is done, to make the Connection available for other operations within the same transaction.

        released in class ResourceHolderSupport