Class SpringTransactionAwareUnitOfWork<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager,UOW extends SpringTransactionAwareUnitOfWork<TRX_MGR,UOW>>
- java.lang.Object
-
- dk.cloudcreate.essentials.components.foundation.transaction.spring.SpringTransactionAwareUnitOfWork<TRX_MGR,UOW>
-
- Type Parameters:
TRX_MGR- thePlatformTransactionManagerspecialization that thisSpringTransactionAwareUnitOfWorkis compatible withUOW- theSpringTransactionAwareUnitOfWorkspecialization
- All Implemented Interfaces:
UnitOfWork
- Direct Known Subclasses:
SpringMongoTransactionAwareUnitOfWorkFactory.SpringMongoTransactionAwareUnitOfWork,SpringTransactionAwareJdbiUnitOfWorkFactory.SpringTransactionAwareHandleAwareUnitOfWork
public class SpringTransactionAwareUnitOfWork<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager,UOW extends SpringTransactionAwareUnitOfWork<TRX_MGR,UOW>> extends Object implements UnitOfWork
Spring transaction-awareUnitOfWork
Specializations can choose to overrideonStart()to initialize any datastore specific resources (e.g. a JDBI handle) andonCleanup()to release/cleanup the resources.
-
-
Field Summary
Fields Modifier and Type Field Description protected SpringTransactionAwareUnitOfWorkFactory<TRX_MGR,UOW>unitOfWorkFactoryprotected Map<UnitOfWorkLifecycleCallback<Object>,List<Object>>unitOfWorkLifecycleCallbackResources
-
Constructor Summary
Constructors Constructor Description SpringTransactionAwareUnitOfWork(SpringTransactionAwareUnitOfWorkFactory<TRX_MGR,UOW> unitOfWorkFactory)SpringTransactionAwareUnitOfWork(SpringTransactionAwareUnitOfWorkFactory<TRX_MGR,UOW> unitOfWorkFactory, org.springframework.transaction.TransactionStatus manuallyManagedSpringTransaction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()Commit theUnitOfWorkand any underlying transaction - seeUnitOfWorkStatus.CommittedExceptiongetCauseOfRollback()The cause of a Rollback or aUnitOfWork.markAsRollbackOnly(Exception)voidmarkAsRollbackOnly(Exception cause)protected voidonCleanup()Called on clean up (e.g.protected voidonStart()Called when theUnitOfWorkis started.
Here any unit of work related resources (e.g.<T> TregisterLifecycleCallbackForResource(T resource, UnitOfWorkLifecycleCallback<T> associatedUnitOfWorkCallback)TODO: Adjust example to the new API Register a resource (e.g.voidrollback(Exception cause)Roll back theUnitOfWorkand any underlying transaction - seeUnitOfWorkStatus.RolledBackvoidstart()Start theUnitOfWorkand any underlying transactionUnitOfWorkStatusstatus()Get the status of theUnitOfWork-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface dk.cloudcreate.essentials.components.foundation.transaction.UnitOfWork
markAsRollbackOnly, rollback
-
-
-
-
Field Detail
-
unitOfWorkFactory
protected SpringTransactionAwareUnitOfWorkFactory<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager,UOW extends SpringTransactionAwareUnitOfWork<TRX_MGR,UOW>> unitOfWorkFactory
-
unitOfWorkLifecycleCallbackResources
protected Map<UnitOfWorkLifecycleCallback<Object>,List<Object>> unitOfWorkLifecycleCallbackResources
-
-
Constructor Detail
-
SpringTransactionAwareUnitOfWork
public SpringTransactionAwareUnitOfWork(SpringTransactionAwareUnitOfWorkFactory<TRX_MGR,UOW> unitOfWorkFactory)
-
SpringTransactionAwareUnitOfWork
public SpringTransactionAwareUnitOfWork(SpringTransactionAwareUnitOfWorkFactory<TRX_MGR,UOW> unitOfWorkFactory, org.springframework.transaction.TransactionStatus manuallyManagedSpringTransaction)
-
-
Method Detail
-
start
public void start()
Description copied from interface:UnitOfWorkStart theUnitOfWorkand any underlying transaction- Specified by:
startin interfaceUnitOfWork
-
onStart
protected void onStart()
Called when theUnitOfWorkis started.
Here any unit of work related resources (e.g. JDBI handle) can be created
-
onCleanup
protected void onCleanup()
Called on clean up (e.g. after commit/rollback) of theUnitOfWork.
Here any unit of work related resources (e.g. JDBI handle) created inonStart()can be closed/cleaned-up
-
commit
public void commit()
Description copied from interface:UnitOfWorkCommit theUnitOfWorkand any underlying transaction - seeUnitOfWorkStatus.Committed- Specified by:
commitin interfaceUnitOfWork
-
rollback
public void rollback(Exception cause)
Description copied from interface:UnitOfWorkRoll back theUnitOfWorkand any underlying transaction - seeUnitOfWorkStatus.RolledBack- Specified by:
rollbackin interfaceUnitOfWork- Parameters:
cause- the cause of the rollback
-
status
public UnitOfWorkStatus status()
Description copied from interface:UnitOfWorkGet the status of theUnitOfWork- Specified by:
statusin interfaceUnitOfWork
-
getCauseOfRollback
public Exception getCauseOfRollback()
Description copied from interface:UnitOfWorkThe cause of a Rollback or aUnitOfWork.markAsRollbackOnly(Exception)- Specified by:
getCauseOfRollbackin interfaceUnitOfWork
-
markAsRollbackOnly
public void markAsRollbackOnly(Exception cause)
- Specified by:
markAsRollbackOnlyin interfaceUnitOfWork
-
registerLifecycleCallbackForResource
public <T> T registerLifecycleCallbackForResource(T resource, UnitOfWorkLifecycleCallback<T> associatedUnitOfWorkCallback)Description copied from interface:UnitOfWorkTODO: Adjust example to the new API Register a resource (e.g. an Aggregate) that should have itsUnitOfWorkLifecycleCallbackcalled duringUnitOfWorkoperation.
Example:
Where the AggregAggregate aggregate = unitOfWork.registerLifecycleCallbackForResource(aggregate.loadFromEvents(event), new AggregateRootRepositoryUnitOfWorkLifecycleCallback()));{@code class AggregateRootRepositoryUnitOfWorkLifecycleCallback implements UnitOfWorkLifecycleCallback{ - Specified by:
registerLifecycleCallbackForResourcein interfaceUnitOfWork- Type Parameters:
T- the type of resource- Parameters:
resource- the resource that should be trackedassociatedUnitOfWorkCallback- the callback instance for the given resource- Returns:
- the
resourceor a proxy to it
-
-