|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.transaction.support.ResourceHolderSupport org.springframework.jdbc.datasource.ConnectionHolder
public class ConnectionHolder
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.
DataSourceTransactionManager
,
DataSourceUtils
Field Summary | |
---|---|
private ConnectionHandle |
connectionHandle
|
private java.sql.Connection |
currentConnection
|
static java.lang.String |
SAVEPOINT_NAME_PREFIX
|
private int |
savepointCounter
|
private java.lang.Boolean |
savepointsSupported
|
private boolean |
transactionActive
|
Constructor Summary | |
---|---|
ConnectionHolder(java.sql.Connection connection)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle ,
assuming that there is no ongoing transaction. |
|
ConnectionHolder(java.sql.Connection connection,
boolean transactionActive)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle . |
|
ConnectionHolder(ConnectionHandle connectionHandle)
Create a new ConnectionHolder for the given ConnectionHandle. |
Method Summary | |
---|---|
void |
clear()
Clear the transactional state of this resource holder. |
java.sql.Savepoint |
createSavepoint()
Create a new JDBC 3.0 Savepoint for the current Connection, using generated savepoint names that are unique for the Connection. |
java.sql.Connection |
getConnection()
Return the current Connection held by this ConnectionHolder. |
ConnectionHandle |
getConnectionHandle()
Return the ConnectionHandle held by this ConnectionHolder. |
protected boolean |
hasConnection()
Return whether this holder currently has a Connection. |
protected boolean |
isTransactionActive()
Return whether this holder represents an active, JDBC-managed transaction. |
void |
released()
Releases the current Connection held by this ConnectionHolder. |
protected void |
setConnection(java.sql.Connection connection)
Override the existing Connection handle with the given Connection. |
protected void |
setTransactionActive(boolean transactionActive)
Set whether this holder represents an active, JDBC-managed transaction. |
boolean |
supportsSavepoints()
Return whether JDBC 3.0 Savepoints are supported. |
Methods inherited from class org.springframework.transaction.support.ResourceHolderSupport |
---|
getDeadline, getTimeToLiveInMillis, getTimeToLiveInSeconds, hasTimeout, isOpen, isRollbackOnly, isSynchronizedWithTransaction, isVoid, requested, reset, setRollbackOnly, setSynchronizedWithTransaction, setTimeoutInMillis, setTimeoutInSeconds, unbound |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String SAVEPOINT_NAME_PREFIX
private ConnectionHandle connectionHandle
private java.sql.Connection currentConnection
private boolean transactionActive
private java.lang.Boolean savepointsSupported
private int savepointCounter
Constructor Detail |
---|
public ConnectionHolder(ConnectionHandle connectionHandle)
connectionHandle
- the ConnectionHandle to holdpublic ConnectionHolder(java.sql.Connection connection)
SimpleConnectionHandle
,
assuming that there is no ongoing transaction.
connection
- the JDBC Connection to holdSimpleConnectionHandle
,
ConnectionHolder(java.sql.Connection, boolean)
public ConnectionHolder(java.sql.Connection connection, boolean transactionActive)
SimpleConnectionHandle
.
connection
- the JDBC Connection to holdtransactionActive
- whether the given Connection is involved
in an ongoing transactionSimpleConnectionHandle
Method Detail |
---|
public ConnectionHandle getConnectionHandle()
protected boolean hasConnection()
protected void setTransactionActive(boolean transactionActive)
DataSourceTransactionManager
protected boolean isTransactionActive()
protected void setConnection(java.sql.Connection connection)
null
.
Used for releasing the Connection on suspend (with a null
argument) and setting a fresh Connection on resume.
public java.sql.Connection getConnection()
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.
ConnectionHandle.getConnection()
,
released()
public boolean supportsSavepoints() throws java.sql.SQLException
java.sql.SQLException
- if thrown by the JDBC driverpublic java.sql.Savepoint createSavepoint() throws java.sql.SQLException
java.sql.SQLException
- if thrown by the JDBC driverpublic void released()
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.
released
in class ResourceHolderSupport
DefaultJdoDialect.getJdbcConnection(PersistenceManager, boolean)
public void clear()
ResourceHolderSupport
clear
in class ResourceHolderSupport
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |