org.axonframework.unitofwork
Class DefaultUnitOfWork

java.lang.Object
  extended by org.axonframework.unitofwork.AbstractUnitOfWork
      extended by org.axonframework.unitofwork.DefaultUnitOfWork
All Implemented Interfaces:
UnitOfWork

public class DefaultUnitOfWork
extends AbstractUnitOfWork

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.

Since:
0.6
Author:
Allard Buijze

Constructor Summary
DefaultUnitOfWork()
           
 
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 notifyListenersAfterCommit()
          Send a UnitOfWorkListener.afterCommit() notification to all registered listeners.
protected  void notifyListenersCleanup()
          Send a UnitOfWorkListener.onCleanup() notification to all registered listeners.
protected  void notifyListenersPrepareCommit()
          Send a UnitOfWorkListener.onPrepareCommit(java.util.Set, java.util.List) notification to all registered listeners.
protected  void notifyListenersRollback(Throwable cause)
          Send a UnitOfWorkListener.onRollback(Throwable) notification to all registered listeners.
 void publishEvent(Event 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.
<T extends AggregateRoot>
void
registerAggregate(T aggregate, SaveAggregateCallback<T> callback)
          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.
 
Methods inherited from class org.axonframework.unitofwork.AbstractUnitOfWork
commit, commitInnerUnitOfWork, doStart, isStarted, rollback, rollback, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultUnitOfWork

public DefaultUnitOfWork()
Method Detail

startAndGet

public static UnitOfWork startAndGet()
Starts a new DefaultUnitOfWork instance, registering it a CurrentUnitOfWork. This methods returns the started UnitOfWork instance.

Returns:
the started UnitOfWork instance

doRollback

protected void doRollback(Throwable cause)
Description copied from class: AbstractUnitOfWork
Executes the logic required to commit this unit of work.

Specified by:
doRollback in class AbstractUnitOfWork
Parameters:
cause - the cause of the rollback

doCommit

protected void doCommit()
Description copied from class: AbstractUnitOfWork
Executes the logic required to commit this unit of work.

Specified by:
doCommit in class AbstractUnitOfWork

registerAggregate

public <T extends AggregateRoot> void registerAggregate(T aggregate,
                                                        SaveAggregateCallback<T> callback)
Description copied from interface: UnitOfWork
Register an aggregate with this UnitOfWork. These aggregates will be saved (at the latest) when the UnitOfWork is committed.

Type Parameters:
T - the type of aggregate to register
Parameters:
aggregate - The aggregate root to register in the UnitOfWork
callback - The callback that is invoked when the UnitOfWork wants to store the registered aggregate

registerListener

public void registerListener(UnitOfWorkListener listener)
Description copied from interface: UnitOfWork
Register a listener that listens to state changes in this UnitOfWork. This typically allows components to clean up resources, such as locks, when a UnitOfWork is committed or rolled back. If a UnitOfWork is partially committed, only the listeners bound to one of the committed aggregates is notified.

Parameters:
listener - The listener to notify when the UnitOfWork's state changes.

publishEvent

public void publishEvent(Event event,
                         EventBus eventBus)
Description copied from interface: UnitOfWork
Request to publish the given event on the given eventBus. The UnitOfWork may either publish immediately, or buffer the events until the UnitOfWork is committed.

Parameters:
event - The event to be published on the event bus
eventBus - The event bus on which to publish the event

notifyListenersRollback

protected void notifyListenersRollback(Throwable cause)
Send a UnitOfWorkListener.onRollback(Throwable) notification to all registered listeners.

Specified by:
notifyListenersRollback in class AbstractUnitOfWork
Parameters:
cause - The cause of the rollback

notifyListenersAfterCommit

protected void notifyListenersAfterCommit()
Send a UnitOfWorkListener.afterCommit() notification to all registered listeners.


publishEvents

protected void publishEvents()
Publishes all registered events to their respective event bus.


saveAggregates

protected void saveAggregates()
Description copied from class: AbstractUnitOfWork
Saves all registered aggregates by calling their respective callbacks.

Specified by:
saveAggregates in class AbstractUnitOfWork

notifyListenersPrepareCommit

protected void notifyListenersPrepareCommit()
Description copied from class: AbstractUnitOfWork
Send a UnitOfWorkListener.onPrepareCommit(java.util.Set, java.util.List) notification to all registered listeners.

Specified by:
notifyListenersPrepareCommit in class AbstractUnitOfWork

notifyListenersCleanup

protected void notifyListenersCleanup()
Send a UnitOfWorkListener.onCleanup() notification to all registered listeners.

Specified by:
notifyListenersCleanup in class AbstractUnitOfWork


Copyright © 2011. All Rights Reserved.