public class DefaultUnitOfWork extends NestableUnitOfWork
| Constructor and Description |
|---|
DefaultUnitOfWork()
Initializes a Unit of Work (without starting it) that is not bound to any transaction.
|
DefaultUnitOfWork(TransactionManager<?> transactionManager)
Initializes a Unit of Work (without starting it) that is binds to the transaction created by the given
transactionManager when the Unit of Work starts. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doCommit()
Executes the logic required to commit this unit of work.
|
protected void |
doRollback(Throwable cause)
Executes the logic required to commit this unit of work.
|
protected void |
doStart()
Performs logic required when starting this UnitOfWork instance.
|
boolean |
isTransactional()
Indicates whether this UnitOfWork is bound to a transaction.
|
protected void |
notifyListenersAfterCommit()
Send a
UnitOfWorkListener.afterCommit(UnitOfWork) notification to all registered listeners. |
protected void |
notifyListenersCleanup()
Send a
UnitOfWorkListener.onCleanup(UnitOfWork) notification to all
registered listeners. |
protected void |
notifyListenersPrepareCommit()
Send a
UnitOfWorkListener.onPrepareCommit(UnitOfWork, java.util.Set,
java.util.List) notification to all registered listeners. |
protected void |
notifyListenersPrepareTransactionCommit(Object transaction)
Send a
UnitOfWorkListener.afterCommit(UnitOfWork) notification to all registered listeners. |
protected void |
notifyListenersRollback(Throwable cause)
Send a
UnitOfWorkListener.onRollback(UnitOfWork, Throwable) notification to all registered listeners. |
protected void |
publishEvents()
Publishes all registered events to their respective event bus.
|
<T extends AggregateRoot> |
registerAggregate(T aggregate,
EventBus eventBus,
SaveAggregateCallback<T> saveAggregateCallback)
Register an aggregate with this UnitOfWork.
|
void |
registerForPublication(EventMessage<?> event,
EventBus eventBus,
boolean notifyRegistrationHandlers)
Register the given
event for publication on the given eventBus when the unit of work
is committed. |
void |
registerListener(UnitOfWorkListener listener)
Register a listener that listens to state changes in this UnitOfWork.
|
protected void |
registerScheduledEvents(UnitOfWork unitOfWork)
Invokes when a child Unit of Work should register its scheduled events with the given
unitOfWork. |
protected void |
saveAggregates()
Saves all registered aggregates by calling their respective callbacks.
|
static UnitOfWork |
startAndGet()
Starts a new DefaultUnitOfWork instance, registering it a CurrentUnitOfWork.
|
static UnitOfWork |
startAndGet(TransactionManager<?> transactionManager)
Starts a new DefaultUnitOfWork instance using the given
transactionManager to provide a backing
transaction, registering it a CurrentUnitOfWork. |
attachInheritedResources, attachResource, attachResource, commit, commitInnerUnitOfWork, getResource, isStarted, publishEvent, rollback, rollback, startpublic DefaultUnitOfWork()
public DefaultUnitOfWork(TransactionManager<?> transactionManager)
transactionManager when the Unit of Work starts.transactionManager - The transaction manager to manage the transaction around this Unit of Workpublic static UnitOfWork startAndGet()
public static UnitOfWork startAndGet(TransactionManager<?> transactionManager)
transactionManager to provide a backing
transaction, registering it a CurrentUnitOfWork. This methods returns the started UnitOfWork instance.
Note that this Unit Of Work type is not meant to be shared among different Threads. A single DefaultUnitOfWork
instance should be used exclusively by the Thread that created it.transactionManager - The transaction manager to provide the backing transaction. May be null
when not using transactions.protected void doStart()
NestableUnitOfWorkdoStart in class NestableUnitOfWorkpublic boolean isTransactional()
UnitOfWorktrue if this unit of work is bound to a transaction, otherwise falseprotected void doRollback(Throwable cause)
NestableUnitOfWorkdoRollback in class NestableUnitOfWorkcause - the cause of the rollbackprotected void doCommit()
NestableUnitOfWorkdoCommit in class NestableUnitOfWorkprotected void registerScheduledEvents(UnitOfWork unitOfWork)
NestableUnitOfWorkunitOfWork.
Typically, the given unitOfWork is the parent of the current.registerScheduledEvents in class NestableUnitOfWorkunitOfWork - The Unit of Work to register scheduled events withUnitOfWork.publishEvent(org.axonframework.domain.EventMessage,
org.axonframework.eventhandling.EventBus)public <T extends AggregateRoot> T registerAggregate(T aggregate, EventBus eventBus, SaveAggregateCallback<T> saveAggregateCallback)
UnitOfWorksaveAggregateCallback is ignored.T - the type of aggregate to registeraggregate - The aggregate root to register in the UnitOfWorkeventBus - The event bus on which Events generated by this aggregate must be publishedsaveAggregateCallback - The callback that is invoked when the UnitOfWork wants to store the registered
aggregatepublic void registerListener(UnitOfWorkListener listener)
UnitOfWorklistener - The listener to notify when the UnitOfWork's state changes.public void registerForPublication(EventMessage<?> event, EventBus eventBus, boolean notifyRegistrationHandlers)
NestableUnitOfWorkevent for publication on the given eventBus when the unit of work
is committed. This method will only be invoked on the outer unit of work, as that one is responsible for
maintaining the order of publication of events.
The notifyRegistrationHandlers parameter indicates whether the registration handlers should be
notified of the registration of this event.registerForPublication in class NestableUnitOfWorkevent - The Event to publisheventBus - The Event Bus to publish the Event onnotifyRegistrationHandlers - Indicates whether event registration handlers should be notified of this eventprotected void notifyListenersRollback(Throwable cause)
NestableUnitOfWorkUnitOfWorkListener.onRollback(UnitOfWork, Throwable) notification to all registered listeners.notifyListenersRollback in class NestableUnitOfWorkcause - The cause of the rollbackprotected void notifyListenersPrepareTransactionCommit(Object transaction)
UnitOfWorkListener.afterCommit(UnitOfWork) notification to all registered listeners.transaction - The object representing the transaction to about to be committedprotected void notifyListenersAfterCommit()
UnitOfWorkListener.afterCommit(UnitOfWork) notification to all registered listeners.protected void publishEvents()
protected void saveAggregates()
NestableUnitOfWorksaveAggregates in class NestableUnitOfWorkprotected void notifyListenersPrepareCommit()
NestableUnitOfWorkUnitOfWorkListener.onPrepareCommit(UnitOfWork, java.util.Set,
java.util.List) notification to all registered listeners.notifyListenersPrepareCommit in class NestableUnitOfWorkprotected void notifyListenersCleanup()
NestableUnitOfWorkUnitOfWorkListener.onCleanup(UnitOfWork) notification to all
registered listeners. The implementation must ensure that all listeners are notified, even if one throws an
exception.notifyListenersCleanup in class NestableUnitOfWorkCopyright © 2010-2014. All Rights Reserved.