|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.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. |
|
void |
publishEvent(EventMessage<?> event,
EventBus eventBus)
Request to publish the given event on the given eventBus. |
|
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 |
registerListener(UnitOfWorkListener listener)
Register a listener that listens to state changes in this 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 |
|---|
commit, commitInnerUnitOfWork, isStarted, 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 Work| Method 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 NestableUnitOfWorkpublic boolean isTransactional()
UnitOfWork
true if this unit of work is bound to a transaction, otherwise falseprotected void doRollback(Throwable cause)
NestableUnitOfWork
doRollback in class NestableUnitOfWorkcause - the cause of the rollbackprotected void doCommit()
NestableUnitOfWork
doCommit in class NestableUnitOfWork
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
aggregate
public void registerListener(UnitOfWorkListener listener)
UnitOfWork
listener - The listener to notify when the UnitOfWork's state changes.
public void publishEvent(EventMessage<?> event,
EventBus eventBus)
UnitOfWorkevent on the given eventBus. The UnitOfWork may either
publish immediately, or buffer the events until the UnitOfWork is committed.
event - The event to be published on the event buseventBus - The event bus on which to publish the 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()
NestableUnitOfWork
saveAggregates 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 NestableUnitOfWork
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||