public abstract class ResourceHolderSupport extends java.lang.Object implements ResourceHolder
Features rollback-only support for participating transactions. Can expire after a certain number of seconds or milliseconds in order to determine a transactional timeout.
DataSourceTransactionManager.doBegin(java.lang.Object, org.springframework.transaction.TransactionDefinition)
,
DataSourceUtils.applyTransactionTimeout(java.sql.Statement, javax.sql.DataSource)
Modifier and Type | Field and Description |
---|---|
private java.util.Date |
deadline |
private boolean |
isVoid |
private int |
referenceCount |
private boolean |
rollbackOnly |
private boolean |
synchronizedWithTransaction |
Constructor and Description |
---|
ResourceHolderSupport() |
Modifier and Type | Method and Description |
---|---|
private void |
checkTransactionTimeout(boolean deadlineReached)
Set the transaction rollback-only if the deadline has been reached,
and throw a TransactionTimedOutException.
|
void |
clear()
Clear the transactional state of this resource holder.
|
java.util.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.
|
boolean |
isVoid()
Determine whether this holder is considered as 'void',
i.e.
|
void |
released()
Decrease the reference count by one because the holder has been released
(i.e.
|
void |
requested()
Increase the reference count by one because the holder has been requested
(i.e.
|
void |
reset()
Reset this resource holder - transactional state as well as reference count.
|
void |
resetRollbackOnly()
Reset the rollback-only status for this resource transaction.
|
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.
|
void |
unbound()
Notify this holder that it has been unbound from transaction synchronization.
|
private boolean synchronizedWithTransaction
private boolean rollbackOnly
private java.util.Date deadline
private int referenceCount
private boolean isVoid
public void setSynchronizedWithTransaction(boolean synchronizedWithTransaction)
public boolean isSynchronizedWithTransaction()
public void setRollbackOnly()
public void resetRollbackOnly()
Only really intended to be called after custom rollback steps which keep the original resource in action, e.g. in case of a savepoint.
SavepointManager.rollbackToSavepoint(java.lang.Object)
public boolean isRollbackOnly()
public void setTimeoutInSeconds(int seconds)
seconds
- number of seconds until expirationpublic void setTimeoutInMillis(long millis)
millis
- number of milliseconds until expirationpublic boolean hasTimeout()
public java.util.Date getDeadline()
public int getTimeToLiveInSeconds()
TransactionTimedOutException
- if the deadline has already been reachedpublic long getTimeToLiveInMillis() throws TransactionTimedOutException
TransactionTimedOutException
- if the deadline has already been reachedprivate void checkTransactionTimeout(boolean deadlineReached) throws TransactionTimedOutException
TransactionTimedOutException
public void requested()
public void released()
public boolean isOpen()
public void clear()
public void reset()
reset
in interface ResourceHolder
public void unbound()
ResourceHolder
unbound
in interface ResourceHolder
public boolean isVoid()
ResourceHolder
isVoid
in interface ResourceHolder