类 ConnectionHolder
- java.lang.Object
- org.springframework.transaction.support.ResourceHolderSupport
- org.springframework.jdbc.datasource.ConnectionHolder
- 所有已实现的接口:
ResourceHolder
public class ConnectionHolder extends ResourceHolderSupport
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.
- 从以下版本开始:
- 06.05.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
DataSourceTransactionManager
,DataSourceUtils
字段概要
字段 修饰符和类型 字段 说明 static String
SAVEPOINT_NAME_PREFIX
构造器概要
构造器 构造器 说明 ConnectionHolder(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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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.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(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.从类继承的方法 org.springframework.transaction.support.ResourceHolderSupport
getDeadline, getTimeToLiveInMillis, getTimeToLiveInSeconds, hasTimeout, isOpen, isRollbackOnly, isSynchronizedWithTransaction, isVoid, requested, reset, setRollbackOnly, setSynchronizedWithTransaction, setTimeoutInMillis, setTimeoutInSeconds, unbound
字段详细资料
SAVEPOINT_NAME_PREFIX
public static final String SAVEPOINT_NAME_PREFIX
- 另请参阅:
- 常量字段值
构造器详细资料
ConnectionHolder
public ConnectionHolder(ConnectionHandle connectionHandle)
Create a new ConnectionHolder for the given ConnectionHandle.- 参数:
connectionHandle
- the ConnectionHandle to hold
ConnectionHolder
public ConnectionHolder(Connection connection)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with aSimpleConnectionHandle
, assuming that there is no ongoing transaction.- 参数:
connection
- the JDBC Connection to hold- 另请参阅:
SimpleConnectionHandle
,ConnectionHolder(java.sql.Connection, boolean)
ConnectionHolder
public ConnectionHolder(Connection connection, boolean transactionActive)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with aSimpleConnectionHandle
.- 参数:
connection
- the JDBC Connection to holdtransactionActive
- whether the given Connection is involved in an ongoing transaction- 另请参阅:
SimpleConnectionHandle
方法详细资料
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.
isTransactionActive
protected boolean isTransactionActive()
Return whether this holder represents an active, JDBC-managed transaction.
setConnection
protected void setConnection(Connection connection)
Override the existing Connection handle with the given Connection. Reset the handle if givennull
.Used for releasing the Connection on suspend (with a
null
argument) and setting a fresh Connection on resume.
getConnection
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.
supportsSavepoints
public boolean supportsSavepoints() throws SQLException
Return whether JDBC 3.0 Savepoints are supported. Caches the flag for the lifetime of this ConnectionHolder.- 抛出:
SQLException
- if thrown by the JDBC driver
createSavepoint
public Savepoint createSavepoint() throws 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
- 抛出:
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. This is the case with JDO 2.0 DataStoreConnections, for example.
clear
public void clear()
从类复制的说明:ResourceHolderSupport
Clear the transactional state of this resource holder.- 覆盖:
clear
在类中ResourceHolderSupport