The Spring Framework

org.springframework.transaction.support
Class ResourceHolderSupport

java.lang.Object
  extended by org.springframework.transaction.support.ResourceHolderSupport
Direct Known Subclasses:
ConnectionHolder, ConnectionHolder, EntityManagerHolder, JmsResourceHolder, PersistenceManagerHolder, SessionHolder, SessionHolder

public abstract class ResourceHolderSupport
extends Object

Convenient base class for resource holders.

Features rollback-only support for nested transactions. Can expire after a certain number of seconds or milliseconds, to determine transactional timeouts.

Since:
02.02.2004
Author:
Juergen Hoeller
See Also:
DataSourceTransactionManager.doBegin(java.lang.Object, org.springframework.transaction.TransactionDefinition), DataSourceUtils.applyTransactionTimeout(java.sql.Statement, javax.sql.DataSource)

Constructor Summary
ResourceHolderSupport()
           
 
Method Summary
 void clear()
          Clear the transactional state of this resource holder.
 Date getDeadline()
          Return the expiration deadline of this object.
 long getTimeToLiveInMillis()
          Return the time to live for this object in milliseconds.
 int getTimeToLiveInSeconds()
          Return the time to live for this object in seconds.
 boolean hasTimeout()
          Return whether this object has an associated timeout.
 boolean isOpen()
          Return whether there are still open references to this holder.
 boolean isRollbackOnly()
          Return whether the resource transaction is marked as rollback-only.
 boolean isSynchronizedWithTransaction()
          Return whether the resource is synchronized with a transaction.
 void released()
          Decrease the reference count by one because the holder has been released (i.e. someone released the resource held by it).
 void requested()
          Increase the reference count by one because the holder has been requested (i.e. someone requested the resource held by it).
 void reset()
          Reset this resource holder - transactional state as well as reference count.
 void setRollbackOnly()
          Mark the resource transaction as rollback-only.
 void setSynchronizedWithTransaction(boolean synchronizedWithTransaction)
          Mark the resource as synchronized with a transaction.
 void setTimeoutInMillis(long millis)
          Set the timeout for this object in milliseconds.
 void setTimeoutInSeconds(int seconds)
          Set the timeout for this object in seconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceHolderSupport

public ResourceHolderSupport()
Method Detail

setSynchronizedWithTransaction

public void setSynchronizedWithTransaction(boolean synchronizedWithTransaction)
Mark the resource as synchronized with a transaction.


isSynchronizedWithTransaction

public boolean isSynchronizedWithTransaction()
Return whether the resource is synchronized with a transaction.


setRollbackOnly

public void setRollbackOnly()
Mark the resource transaction as rollback-only.


isRollbackOnly

public boolean isRollbackOnly()
Return whether the resource transaction is marked as rollback-only.


setTimeoutInSeconds

public void setTimeoutInSeconds(int seconds)
Set the timeout for this object in seconds.

Parameters:
seconds - number of seconds until expiration

setTimeoutInMillis

public void setTimeoutInMillis(long millis)
Set the timeout for this object in milliseconds.

Parameters:
millis - number of milliseconds until expiration

hasTimeout

public boolean hasTimeout()
Return whether this object has an associated timeout.


getDeadline

public Date getDeadline()
Return the expiration deadline of this object.

Returns:
the deadline as Date object

getTimeToLiveInSeconds

public int getTimeToLiveInSeconds()
Return the time to live for this object in seconds. Rounds up eagerly, e.g. 9.00001 still to 10.

Returns:
number of seconds until expiration
Throws:
TransactionTimedOutException - if the deadline has already been reached

getTimeToLiveInMillis

public long getTimeToLiveInMillis()
                           throws TransactionTimedOutException
Return the time to live for this object in milliseconds.

Returns:
number of millseconds until expiration
Throws:
TransactionTimedOutException - if the deadline has already been reached

requested

public void requested()
Increase the reference count by one because the holder has been requested (i.e. someone requested the resource held by it).


released

public void released()
Decrease the reference count by one because the holder has been released (i.e. someone released the resource held by it).


isOpen

public boolean isOpen()
Return whether there are still open references to this holder.


clear

public void clear()
Clear the transactional state of this resource holder.


reset

public void reset()
Reset this resource holder - transactional state as well as reference count.


The Spring Framework

Copyright © 2002-2007 The Spring Framework.