站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 1.2.9 API 文档英文版

ConnectionHolder (Spring Framework) - Spring Framework 1.2.9 API 文档英文版


org.springframework.jdbc.datasource
Class ConnectionHolder

java.lang.Object
  extended by org.springframework.transaction.support.ResourceHolderSupport
      extended by org.springframework.jdbc.datasource.ConnectionHolder

public class ConnectionHolder
extends ResourceHolderSupport

Connection holder, wrapping a JDBC Connection. DataSourceTransactionManager binds instances of this class to the thread, for a given 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:
DataSourceTransactionManager, DataSourceUtils

Constructor Summary
ConnectionHolder(Connection connection)
          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.
 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.
 
Methods inherited from class org.springframework.transaction.support.ResourceHolderSupport
getDeadline, getTimeToLiveInMillis, getTimeToLiveInSeconds, hasTimeout, isOpen, isRollbackOnly, isSynchronizedWithTransaction, requested, reset, setRollbackOnly, setSynchronizedWithTransaction, setTimeoutInMillis, setTimeoutInSeconds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionHolder

public ConnectionHolder(ConnectionHandle connectionHandle)
Create a new ConnectionHolder for the given ConnectionHandle.

Parameters:
connectionHandle - the ConnectionHandle to hold

ConnectionHolder

public ConnectionHolder(Connection connection)
Create a new ConnectionHolder for the given JDBC Connection, wrapping it with a SimpleConnectionHandle.

Parameters:
connection - the JDBC Connection to hold
See Also:
SimpleConnectionHandle
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:
DataSourceTransactionManager

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 given null.

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.

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

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.

Overrides:
released in class ResourceHolderSupport
See Also:
DefaultJdoDialect.getJdbcConnection(javax.jdo.PersistenceManager, boolean)

clear

public void clear()
Description copied from class: ResourceHolderSupport
Clear the transactional state of this resource holder.

Overrides:
clear in class ResourceHolderSupport


Copyright (c) 2002-2007 The Spring Framework Project.