Class SpringTransactionAwareUnitOfWorkFactory<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager,UOW extends SpringTransactionAwareUnitOfWork<TRX_MGR,UOW>>
- java.lang.Object
-
- dk.cloudcreate.essentials.components.foundation.transaction.spring.SpringTransactionAwareUnitOfWorkFactory<TRX_MGR,UOW>
-
- Type Parameters:
TRX_MGR- the platform transaction manager that thisUnitOfWorkFactoryis compatible withUOW- the Unit of work implementation that thisSpringTransactionAwareUnitOfWorkFactoryspecialization is compatible with
- All Implemented Interfaces:
UnitOfWorkFactory<UOW>
- Direct Known Subclasses:
SpringMongoTransactionAwareUnitOfWorkFactory,SpringTransactionAwareJdbiUnitOfWorkFactory
public abstract class SpringTransactionAwareUnitOfWorkFactory<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager,UOW extends SpringTransactionAwareUnitOfWork<TRX_MGR,UOW>> extends Object implements UnitOfWorkFactory<UOW>
Variant of theUnitOfWorkFactorywhich can delegate the creation of the underlying transaction to the providedPlatformTransactionManagerinstance.
TheUnitOfWorktype specialization needs to extendSpringTransactionAwareUnitOfWork
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.transaction.support.DefaultTransactionDefinitiondefaultTransactionDefinitionprotected static org.slf4j.Loggerlogprotected TRX_MGRtransactionManagerprotected Class<?>unitOfWorkTypeThe class representation of theUOWgeneric type parameter.
TheUnitOfWorkis bound a resource with theTransactionSynchronizationManagerusing theunitOfWorkTypeclass as key.-
Fields inherited from interface dk.cloudcreate.essentials.components.foundation.transaction.UnitOfWorkFactory
unitOfWorkLog
-
-
Constructor Summary
Constructors Constructor Description SpringTransactionAwareUnitOfWorkFactory(TRX_MGR transactionManager)
-
Method Summary
-
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.UnitOfWorkFactory
usingUnitOfWork, usingUnitOfWork, withUnitOfWork, withUnitOfWork
-
-
-
-
Field Detail
-
log
protected static final org.slf4j.Logger log
-
transactionManager
protected final TRX_MGR extends org.springframework.transaction.PlatformTransactionManager transactionManager
-
defaultTransactionDefinition
protected final org.springframework.transaction.support.DefaultTransactionDefinition defaultTransactionDefinition
-
unitOfWorkType
protected final Class<?> unitOfWorkType
The class representation of theUOWgeneric type parameter.
TheUnitOfWorkis bound a resource with theTransactionSynchronizationManagerusing theunitOfWorkTypeclass as key.
-
-
Constructor Detail
-
SpringTransactionAwareUnitOfWorkFactory
public SpringTransactionAwareUnitOfWorkFactory(TRX_MGR transactionManager)
-
-
Method Detail
-
resolveUnitOfWorkType
protected Class<?> resolveUnitOfWorkType()
-
createDefaultTransactionDefinition
protected org.springframework.transaction.support.DefaultTransactionDefinition createDefaultTransactionDefinition()
Override to create a customDefaultTransactionDefinition.- Returns:
- per default, it generates a
DefaultTransactionDefinitionwith propagationTransactionDefinition.PROPAGATION_REQUIREDand Isolation-levelTransactionDefinition.ISOLATION_READ_COMMITTED
-
getTransactionManager
public TRX_MGR getTransactionManager()
-
getRequiredUnitOfWork
public UOW getRequiredUnitOfWork()
Description copied from interface:UnitOfWorkFactoryGet a required activeUnitOfWork- Specified by:
getRequiredUnitOfWorkin interfaceUnitOfWorkFactory<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager>- Returns:
- the active
UnitOfWork
-
getCurrentUnitOfWork
public Optional<UOW> getCurrentUnitOfWork()
Description copied from interface:UnitOfWorkFactoryGet the currently activeUnitOfWork- Specified by:
getCurrentUnitOfWorkin interfaceUnitOfWorkFactory<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager>- Returns:
- the currently active
UnitOfWorkwrapped in anOptionalorOptional.empty()in case there isn't a currently activeUnitOfWork
-
getOrCreateNewUnitOfWork
public UOW getOrCreateNewUnitOfWork()
Description copied from interface:UnitOfWorkFactoryGet the currently activeUnitOfWorkor create a newUnitOfWorkif one is missing- Specified by:
getOrCreateNewUnitOfWorkin interfaceUnitOfWorkFactory<TRX_MGR extends org.springframework.transaction.PlatformTransactionManager>- Returns:
- a
UnitOfWork
-
createUnitOfWorkForFactoryManagedTransaction
protected abstract UOW createUnitOfWorkForFactoryManagedTransaction(org.springframework.transaction.TransactionStatus transaction)
Create aUnitOfWorkwrapping a Spring Transaction managed by thisUnitOfWorkFactory- Parameters:
transaction- the Spring Transaction managed by thisUnitOfWorkFactory- Returns:
- a
UnitOfWorkwrapping the existing active Spring managed transaction
-
createUnitOfWorkForSpringManagedTransaction
protected abstract UOW createUnitOfWorkForSpringManagedTransaction()
Create aUnitOfWorkparticipating in an existing Spring Managed Transaction that isn't managed by thisUnitOfWorkFactory- Returns:
- a
UnitOfWorkthat is participating in an existing Spring Managed Transaction that isn't managed by thisUnitOfWorkFactory
-
afterCommitAfterCallingLifecycleCallbackResources
protected void afterCommitAfterCallingLifecycleCallbackResources(UOW unitOfWork)
Called duringTransactionSynchronization.afterCommit()AFTER all registeredSpringTransactionAwareUnitOfWork.unitOfWorkLifecycleCallbackResourceshave had theirUnitOfWorkLifecycleCallback.afterCommit(UnitOfWork, List)method called- Parameters:
unitOfWork- the unit of work
-
afterCommitBeforeCallingLifecycleCallbackResources
protected void afterCommitBeforeCallingLifecycleCallbackResources(UOW unitOfWork)
Called duringTransactionSynchronization.afterCommit()BEFORE any registeredSpringTransactionAwareUnitOfWork.unitOfWorkLifecycleCallbackResourceshave had theirUnitOfWorkLifecycleCallback.afterCommit(UnitOfWork, List)method called- Parameters:
unitOfWork- the unit of work
-
beforeCommitAfterCallingLifecycleCallbackResources
protected void beforeCommitAfterCallingLifecycleCallbackResources(UOW unitOfWork)
Called duringTransactionSynchronization.beforeCommit(boolean)AFTER all registeredSpringTransactionAwareUnitOfWork.unitOfWorkLifecycleCallbackResourceshave had theirUnitOfWorkLifecycleCallback.beforeCommit(UnitOfWork, List)method called- Parameters:
unitOfWork- the unit of work
-
beforeCommitBeforeCallingLifecycleCallbackResources
protected void beforeCommitBeforeCallingLifecycleCallbackResources(UOW unitOfWork)
Called duringTransactionSynchronization.beforeCommit(boolean)BEFORE any registeredSpringTransactionAwareUnitOfWork.unitOfWorkLifecycleCallbackResourceshave had theirUnitOfWorkLifecycleCallback.beforeCommit(UnitOfWork, List)method called- Parameters:
unitOfWork- the unit of work
-
afterRollbackBeforeCallingLifecycleCallbackResources
protected void afterRollbackBeforeCallingLifecycleCallbackResources(UOW unitOfWork)
Called duringTransactionSynchronization.afterCompletion(int)BEFORE any registeredSpringTransactionAwareUnitOfWork.unitOfWorkLifecycleCallbackResourceshave had theirUnitOfWorkLifecycleCallback.afterRollback(UnitOfWork, List, Exception)method called- Parameters:
unitOfWork- the unit of work
-
afterRollbackAfterCallingLifecycleCallbackResources
protected void afterRollbackAfterCallingLifecycleCallbackResources(UOW unitOfWork)
Called duringTransactionSynchronization.afterCompletion(int)AFTER all registeredSpringTransactionAwareUnitOfWork.unitOfWorkLifecycleCallbackResourceshave had theirUnitOfWorkLifecycleCallback.afterRollback(UnitOfWork, List, Exception)method called- Parameters:
unitOfWork- the unit of work
-
-