org.springframework.jdbc.datasource
Class DataSourceUtils.ConnectionSynchronization

java.lang.Object
  extended by org.springframework.transaction.support.TransactionSynchronizationAdapter
      extended by org.springframework.jdbc.datasource.DataSourceUtils.ConnectionSynchronization
All Implemented Interfaces:
Ordered, TransactionSynchronization
Enclosing class:
DataSourceUtils

private static class DataSourceUtils.ConnectionSynchronization
extends TransactionSynchronizationAdapter

Callback for resource cleanup at the end of a non-native JDBC transaction (e.g. when participating in a JtaTransactionManager transaction).

See Also:
JtaTransactionManager

Field Summary
private  ConnectionHolder connectionHolder
           
private  javax.sql.DataSource dataSource
           
private  boolean holderActive
           
private  int order
           
 
Fields inherited from interface org.springframework.transaction.support.TransactionSynchronization
STATUS_COMMITTED, STATUS_ROLLED_BACK, STATUS_UNKNOWN
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
DataSourceUtils.ConnectionSynchronization(ConnectionHolder connectionHolder, javax.sql.DataSource dataSource)
           
 
Method Summary
 void afterCompletion(int status)
          Invoked after transaction commit/rollback.
 void beforeCompletion()
          Invoked before transaction commit/rollback.
 int getOrder()
          Return the order value of this object, with a higher value meaning greater in terms of sorting.
 void resume()
          Resume this synchronization.
 void suspend()
          Suspend this synchronization.
 
Methods inherited from class org.springframework.transaction.support.TransactionSynchronizationAdapter
afterCommit, beforeCommit, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionHolder

private final ConnectionHolder connectionHolder

dataSource

private final javax.sql.DataSource dataSource

order

private int order

holderActive

private boolean holderActive
Constructor Detail

DataSourceUtils.ConnectionSynchronization

public DataSourceUtils.ConnectionSynchronization(ConnectionHolder connectionHolder,
                                                 javax.sql.DataSource dataSource)
Method Detail

getOrder

public int getOrder()
Description copied from interface: Ordered
Return the order value of this object, with a higher value meaning greater in terms of sorting.

Normally starting with 0, with Integer.MAX_VALUE indicating the greatest value. Same order values will result in arbitrary positions for the affected objects.

Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Specified by:
getOrder in interface Ordered
Overrides:
getOrder in class TransactionSynchronizationAdapter
Returns:
the order value

suspend

public void suspend()
Description copied from interface: TransactionSynchronization
Suspend this synchronization. Supposed to unbind resources from TransactionSynchronizationManager if managing any.

Specified by:
suspend in interface TransactionSynchronization
Overrides:
suspend in class TransactionSynchronizationAdapter
See Also:
TransactionSynchronizationManager.unbindResource(java.lang.Object)

resume

public void resume()
Description copied from interface: TransactionSynchronization
Resume this synchronization. Supposed to rebind resources to TransactionSynchronizationManager if managing any.

Specified by:
resume in interface TransactionSynchronization
Overrides:
resume in class TransactionSynchronizationAdapter
See Also:
TransactionSynchronizationManager.bindResource(java.lang.Object, java.lang.Object)

beforeCompletion

public void beforeCompletion()
Description copied from interface: TransactionSynchronization
Invoked before transaction commit/rollback. Can perform resource cleanup before transaction completion.

This method will be invoked after beforeCommit, even when beforeCommit threw an exception. This callback allows for closing resources before transaction completion, for any outcome.

Specified by:
beforeCompletion in interface TransactionSynchronization
Overrides:
beforeCompletion in class TransactionSynchronizationAdapter
See Also:
TransactionSynchronization.beforeCommit(boolean), TransactionSynchronization.afterCompletion(int)

afterCompletion

public void afterCompletion(int status)
Description copied from interface: TransactionSynchronization
Invoked after transaction commit/rollback. Can perform resource cleanup after transaction completion.

NOTE: The transaction will have been committed or rolled back already, but the transactional resources might still be active and accessible. As a consequence, any data access code triggered at this point will still "participate" in the original transaction, allowing to perform some cleanup (with no commit following anymore!), unless it explicitly declares that it needs to run in a separate transaction. Hence: Use PROPAGATION_REQUIRES_NEW for any transactional operation that is called from here.

Specified by:
afterCompletion in interface TransactionSynchronization
Overrides:
afterCompletion in class TransactionSynchronizationAdapter
Parameters:
status - completion status according to the STATUS_* constants
See Also:
TransactionSynchronization.STATUS_COMMITTED, TransactionSynchronization.STATUS_ROLLED_BACK, TransactionSynchronization.STATUS_UNKNOWN, TransactionSynchronization.beforeCompletion()