Class PersistentObjectTransactionManager<T>

java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.dellroad.stuff.pobj.PersistentObjectTransactionManager<T>
Type Parameters:
T - type of the root object
All Implemented Interfaces:
Serializable, Aware, BeanNameAware, InitializingBean, ConfigurableTransactionManager, PlatformTransactionManager, ResourceTransactionManager, TransactionManager

public class PersistentObjectTransactionManager<T> extends AbstractPlatformTransactionManager implements BeanNameAware, ResourceTransactionManager, InitializingBean
PersistentObject implementation of Spring's PlatformTransactionManager interface, allowing methods annotated with Spring's @Transactional annotation to perform transactions on PersistentObjects.

During a transaction, the transaction's root object is available via the method getRoot(), and may be replaced entirely via setRoot(). When the transaction completes, the transaction's root object will be automatically written back to the PersistentObject via PersistentObject.setRoot() (unless the transaction was read-only). During commit, the PersistentObject version number is verified, and if another update has occurred since the transaction was opened, a PersistentObjectVersionException is thrown (consider using @RetryTransaction for automatic retry in this case).

Transactions are associated with threads; the PersistentObjectTransactionManager associated with the current thread's transaction is available via getCurrent() (or getCurrent(String) if there is more than one).

The persistentObject property is required. The readOnlySharedRoot property is optional and configures whether, during read-only transactions only, getRoot() returns the shared root object. In this mode, root object graph copies are avoided entirely for read-only transactions, but the application code must be careful to not modify the object graph returned by getRoot() at any time, either during or after the transaction.

This class also provides an XAResource for use with JTA/XA tranasactions. Once elisted in a JTA transaction, the usage described above using getRoot() and setRoot() is identical.

See Also: