|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.unitofwork.NestableUnitOfWork org.axonframework.unitofwork.DefaultUnitOfWork
public class DefaultUnitOfWork
Implementation of the UnitOfWork that buffers all published events until it is committed. Aggregates that have not been explicitly save in their aggregates will be saved when the UnitOfWork commits.
This implementation requires a mechanism that explicitly commits or rolls back.
Constructor Summary | |
---|---|
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. |
Method Summary | ||
---|---|---|
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. |
|
|
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. |
Methods inherited from class org.axonframework.unitofwork.NestableUnitOfWork |
---|
attachInheritedResources, attachResource, attachResource, commit, commitInnerUnitOfWork, getResource, isStarted, publishEvent, rollback, rollback, start |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultUnitOfWork()
public DefaultUnitOfWork(TransactionManager<?> transactionManager)
transactionManager
when the Unit of Work starts.
transactionManager
- The transaction manager to manage the transaction around this Unit of WorkMethod Detail |
---|
public 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()
NestableUnitOfWork
doStart
in class NestableUnitOfWork
public boolean isTransactional()
UnitOfWork
true
if this unit of work is bound to a transaction, otherwise false
protected void doRollback(Throwable cause)
NestableUnitOfWork
doRollback
in class NestableUnitOfWork
cause
- the cause of the rollbackprotected void doCommit()
NestableUnitOfWork
doCommit
in class NestableUnitOfWork
protected void registerScheduledEvents(UnitOfWork unitOfWork)
NestableUnitOfWork
unitOfWork
.
Typically, the given unitOfWork
is the parent of the current.
registerScheduledEvents
in class NestableUnitOfWork
unitOfWork
- 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)
UnitOfWork
saveAggregateCallback
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
aggregate
public void registerListener(UnitOfWorkListener listener)
UnitOfWork
listener
- The listener to notify when the UnitOfWork's state changes.public void registerForPublication(EventMessage<?> event, EventBus eventBus, boolean notifyRegistrationHandlers)
NestableUnitOfWork
event
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 NestableUnitOfWork
event
- 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)
NestableUnitOfWork
UnitOfWorkListener.onRollback(UnitOfWork, Throwable)
notification to all registered listeners.
notifyListenersRollback
in class NestableUnitOfWork
cause
- 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()
NestableUnitOfWork
saveAggregates
in class NestableUnitOfWork
protected void notifyListenersPrepareCommit()
NestableUnitOfWork
UnitOfWorkListener.onPrepareCommit(UnitOfWork, java.util.Set,
java.util.List)
notification to all registered listeners.
notifyListenersPrepareCommit
in class NestableUnitOfWork
protected void notifyListenersCleanup()
NestableUnitOfWork
UnitOfWorkListener.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 NestableUnitOfWork
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |