Class PersistentObjectTransactionManager<T>
- Type Parameters:
- T- type of the root object
- All Implemented Interfaces:
- Serializable,- Aware,- BeanNameAware,- InitializingBean,- ConfigurableTransactionManager,- PlatformTransactionManager,- ResourceTransactionManager,- TransactionManager
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.
- 
Nested Class SummaryNested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManagerAbstractPlatformTransactionManager.SuspendedResourcesHolder
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected PersistentObject<T>The configuredPersistentObjectfrom which transactions are created.Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManagerlogger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidprotected voiddoBegin(Object txObj, TransactionDefinition txDef) protected voiddoCleanupAfterCompletion(Object txObj) protected voiddoCommit(DefaultTransactionStatus status) protected Objectprotected voidResume a previously suspended transaction.protected voiddoRollback(DefaultTransactionStatus status) protected voidprotected ObjectSuspend the current transaction.Get this instance's assigned bean name.static <T> PersistentObjectTransactionManager<T>Get the (unique) instance associated with an open transaction in the current thread.static <T> PersistentObjectTransactionManager<T>getCurrent(String beanName) Get the instance associated with an open transaction in the current thread and having the given bean name.Get thePersistentObjectthat this instance will operate on.getRoot()Get the root object graph for use in the transaction associated with the current thread.longGet the snapshot version of the transaction associated with the current thread.Get theXAResourcecorresponding to this instance.protected booleanisExistingTransaction(Object txObj) booleanDetermine whether the transaction associated with the current thread is a read-only transaction.booleanGet whether, during read-only transactions,getRoot()returns a new copy of thePersistentObjectobject graph or the shared root.protected voidvoidsetBeanName(String beanName) voidsetPersistentObject(PersistentObject<T> persistentObject) Configure thePersistentObjectthat this instance will operate on.voidsetReadOnlySharedRoot(boolean readOnlySharedRoot) Configure whether, during read-only transactions,getRoot()returns a new copy of thePersistentObjectobject graph or the shared root.voidChange the root object graph to be committed in the transaction associated with the current thread.Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManagercommit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionExecutionListeners, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, prepareSynchronization, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionExecutionListeners, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransactionMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.transaction.ConfigurableTransactionManageraddListenerMethods inherited from interface org.springframework.transaction.PlatformTransactionManagercommit, getTransaction, rollback
- 
Field Details- 
persistentObjectThe configuredPersistentObjectfrom which transactions are created.
 
- 
- 
Constructor Details- 
PersistentObjectTransactionManagerpublic PersistentObjectTransactionManager()
 
- 
- 
Method Details- 
getBeanNameGet this instance's assigned bean name.- Returns:
- bean name
 
- 
setBeanName- Specified by:
- setBeanNamein interface- BeanNameAware
 
- 
afterPropertiesSet- Specified by:
- afterPropertiesSetin interface- InitializingBean
- Throws:
- Exception
 
- 
getPersistentObjectGet thePersistentObjectthat this instance will operate on.- Returns:
- the associated persistent object database
 
- 
setPersistentObjectConfigure thePersistentObjectthat this instance will operate on.Required property. - Parameters:
- persistentObject- associated persistent object database
 
- 
getXAResourceGet theXAResourcecorresponding to this instance.- Returns:
- associated XAResource
 
- 
getCurrentGet the instance associated with an open transaction in the current thread and having the given bean name.- Type Parameters:
- T- root object type
- Parameters:
- beanName- bean name assigned to the desired instance
- Returns:
- current thread's transaction manager with the given name
- Throws:
- IllegalArgumentException- if- nameis null
- IllegalStateException- if the current thread is not running within a transaction managed by a- PersistentObjectTransactionManagerassigned the given name
 
- 
getCurrentGet the (unique) instance associated with an open transaction in the current thread.This is a convenience method for the common case where there is only one instance associated with the current thread. - Type Parameters:
- T- root object type
- Returns:
- current thread's transaction manager
- Throws:
- IllegalStateException- if the current thread is not running within a- PersistentObjectTransactionManagertransaction
- IllegalStateException- there is more than one- PersistentObjectTransactionManagertransaction open in the current thread
 
- 
isReadOnlypublic boolean isReadOnly()Determine whether the transaction associated with the current thread is a read-only transaction.- Returns:
- true if the transaction associated with the current thread is a read-only transaction
- Throws:
- IllegalStateException- if there is no transaction associated with the current thread
 
- 
getSnapshotVersionpublic long getSnapshotVersion()Get the snapshot version of the transaction associated with the current thread.- Returns:
- snapshot version of the transaction associated with the current thread.
- Throws:
- IllegalStateException- if there is no transaction associated with the current thread
 
- 
getRootGet the root object graph for use in the transaction associated with the current thread.- Returns:
- root object
- Throws:
- IllegalStateException- if there is no open transaction
 
- 
setRootChange the root object graph to be committed in the transaction associated with the current thread. Subsequent calls togetRootwill return the new object.This method may be invoked during read-only transactions (as before, the root will not actually be committed). - Parameters:
- root- new root object
- Throws:
- IllegalStateException- if there is no transaction associated with the current thread
- IllegalArgumentException- if- rootis null
 
- 
getResourceFactory- Specified by:
- getResourceFactoryin interface- ResourceTransactionManager
 
- 
doGetTransaction- Specified by:
- doGetTransactionin class- AbstractPlatformTransactionManager
 
- 
isExistingTransaction- Overrides:
- isExistingTransactionin class- AbstractPlatformTransactionManager
 
- 
doBegin- Specified by:
- doBeginin class- AbstractPlatformTransactionManager
 
- 
doSuspendSuspend the current transaction.- Overrides:
- doSuspendin class- AbstractPlatformTransactionManager
 
- 
doResumeResume a previously suspended transaction.- Overrides:
- doResumein class- AbstractPlatformTransactionManager
 
- 
prepareForCommit- Overrides:
- prepareForCommitin class- AbstractPlatformTransactionManager
 
- 
doCommit- Specified by:
- doCommitin class- AbstractPlatformTransactionManager
 
- 
doRollback- Specified by:
- doRollbackin class- AbstractPlatformTransactionManager
 
- 
doSetRollbackOnly- Overrides:
- doSetRollbackOnlyin class- AbstractPlatformTransactionManager
 
- 
doCleanupAfterCompletion- Overrides:
- doCleanupAfterCompletionin class- AbstractPlatformTransactionManager
 
 
-