Class ConnectionHolder
java.lang.Object
org.springframework.transaction.support.ResourceHolderSupport
org.springframework.jdbc.datasource.ConnectionHolder
- All Implemented Interfaces:
- ResourceHolder
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.
- Since:
- 06.05.2003
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConnectionHolder(Connection connection) Create a new ConnectionHolder for the given JDBC Connection, wrapping it with aSimpleConnectionHandle, assuming that there is no ongoing transaction.ConnectionHolder(Connection connection, boolean transactionActive) Create a new ConnectionHolder for the given JDBC Connection, wrapping it with aSimpleConnectionHandle.ConnectionHolder(ConnectionHandle connectionHandle) Create a new ConnectionHolder for the given ConnectionHandle.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()Clear the transactional state of this resource holder.Create a new JDBC 3.0 Savepoint for the current Connection, using generated savepoint names that are unique for the Connection.Return the current Connection held by this ConnectionHolder.Return the ConnectionHandle held by this ConnectionHolder.protected booleanReturn whether this holder currently has a Connection.protected booleanReturn whether this holder represents an active, JDBC-managed transaction.voidreleased()Releases the current Connection held by this ConnectionHolder.protected voidsetConnection(Connection connection) Override the existing Connection handle with the given Connection.protected voidsetTransactionActive(boolean transactionActive) Set whether this holder represents an active, JDBC-managed transaction.booleanReturn whether JDBC 3.0 Savepoints are supported.Methods inherited from class org.springframework.transaction.support.ResourceHolderSupportgetDeadline, getTimeToLiveInMillis, getTimeToLiveInSeconds, hasTimeout, isOpen, isRollbackOnly, isSynchronizedWithTransaction, isVoid, requested, reset, resetRollbackOnly, setRollbackOnly, setSynchronizedWithTransaction, setTimeoutInMillis, setTimeoutInSeconds, unbound
- 
Field Details- 
SAVEPOINT_NAME_PREFIXPrefix for savepoint names.- See Also:
 
 
- 
- 
Constructor Details- 
ConnectionHolderCreate a new ConnectionHolder for the given ConnectionHandle.- Parameters:
- connectionHandle- the ConnectionHandle to hold
 
- 
ConnectionHolderCreate a new ConnectionHolder for the given JDBC Connection, wrapping it with aSimpleConnectionHandle, assuming that there is no ongoing transaction.- Parameters:
- connection- the JDBC Connection to hold
- See Also:
 
- 
ConnectionHolderCreate a new ConnectionHolder for the given JDBC Connection, wrapping it with aSimpleConnectionHandle.- Parameters:
- connection- the JDBC Connection to hold
- transactionActive- whether the given Connection is involved in an ongoing transaction
- See Also:
 
 
- 
- 
Method Details- 
getConnectionHandleReturn the ConnectionHandle held by this ConnectionHolder.
- 
hasConnectionprotected boolean hasConnection()Return whether this holder currently has a Connection.
- 
setTransactionActiveprotected void setTransactionActive(boolean transactionActive) Set whether this holder represents an active, JDBC-managed transaction.- See Also:
 
- 
isTransactionActiveprotected boolean isTransactionActive()Return whether this holder represents an active, JDBC-managed transaction.
- 
setConnectionOverride the existing Connection handle with the given Connection. Reset the handle if givennull.Used for releasing the Connection on suspend (with a nullargument) and setting a fresh Connection on resume.
- 
getConnectionReturn the current Connection held by this ConnectionHolder.This will be the same Connection until releasedgets called on the ConnectionHolder, which will reset the held Connection, fetching a new Connection on demand.- See Also:
 
- 
supportsSavepointsReturn whether JDBC 3.0 Savepoints are supported. Caches the flag for the lifetime of this ConnectionHolder.- Throws:
- SQLException- if thrown by the JDBC driver
 
- 
createSavepointCreate 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
 
- 
releasedpublic 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. - Overrides:
- releasedin class- ResourceHolderSupport
 
- 
clearpublic void clear()Description copied from class:ResourceHolderSupportClear the transactional state of this resource holder.- Overrides:
- clearin class- ResourceHolderSupport
 
 
-