public class

ConnectionHolder

extends ResourceHolderSupport
java.lang.Object
   ↳ org.springframework.transaction.support.ResourceHolderSupport
     ↳ org.springframework.jdbc.datasource.ConnectionHolder

Class Overview

Connection 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.

Summary

Constants
String SAVEPOINT_NAME_PREFIX
Public Constructors
ConnectionHolder(ConnectionHandle connectionHandle)
Create a new ConnectionHolder for the given ConnectionHandle.
ConnectionHolder(Connection connection)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle, assuming that there is no ongoing transaction.
ConnectionHolder(Connection connection, boolean transactionActive)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle.
Public Methods
void clear()
Clear the transactional state of this resource holder.
Savepoint createSavepoint()
Create a new JDBC 3.0 Savepoint for the current Connection, using generated savepoint names that are unique for the Connection.
Connection getConnection()
Return the current Connection held by this ConnectionHolder.
ConnectionHandle getConnectionHandle()
Return the ConnectionHandle held by this ConnectionHolder.
void released()
Releases the current Connection held by this ConnectionHolder.
boolean supportsSavepoints()
Return whether JDBC 3.0 Savepoints are supported.
Protected Methods
boolean hasConnection()
Return whether this holder currently has a Connection.
boolean isTransactionActive()
Return whether this holder represents an active, JDBC-managed transaction.
void setConnection(Connection connection)
Override the existing Connection handle with the given Connection.
void setTransactionActive(boolean transactionActive)
Set whether this holder represents an active, JDBC-managed transaction.
[Expand]
Inherited Methods
From class org.springframework.transaction.support.ResourceHolderSupport
From class java.lang.Object
From interface org.springframework.transaction.support.ResourceHolder

Constants

public static final String SAVEPOINT_NAME_PREFIX

Constant Value: "SAVEPOINT_"

Public Constructors

public ConnectionHolder (ConnectionHandle connectionHandle)

Create a new ConnectionHolder for the given ConnectionHandle.

Parameters
connectionHandle the ConnectionHandle to hold

public ConnectionHolder (Connection connection)

Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle, assuming that there is no ongoing transaction.

Parameters
connection the JDBC Connection to hold

public ConnectionHolder (Connection connection, boolean transactionActive)

Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle.

Parameters
connection the JDBC Connection to hold
transactionActive whether the given Connection is involved in an ongoing transaction

Public Methods

public void clear ()

Clear the transactional state of this resource holder.

public Savepoint createSavepoint ()

Create a new JDBC 3.0 Savepoint for the current Connection, using generated savepoint names that are unique for the Connection.

Returns
  • the new Savepoint
Throws
SQLException if thrown by the JDBC driver

public 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.

public ConnectionHandle getConnectionHandle ()

Return the ConnectionHandle held by this ConnectionHolder.

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. This is the case with JDO 2.0 DataStoreConnections, for example.

public boolean supportsSavepoints ()

Return whether JDBC 3.0 Savepoints are supported. Caches the flag for the lifetime of this ConnectionHolder.

Throws
SQLException if thrown by the JDBC driver

Protected Methods

protected boolean hasConnection ()

Return whether this holder currently has a Connection.

protected boolean isTransactionActive ()

Return whether this holder represents an active, JDBC-managed transaction.

protected void setConnection (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.

protected void setTransactionActive (boolean transactionActive)

Set whether this holder represents an active, JDBC-managed transaction.