org.axonframework.unitofwork
Class AbstractUnitOfWork

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

public abstract class AbstractUnitOfWork
extends Object
implements UnitOfWork

Abstract implementation of the UnitOfWork interface. Provides the necessary implementations to support most actions required by any Unit of Work, such as managing registration with the CurrentUnitOfWork and support for nesting a Unit of Work.

Since:
0.7
Author:
Allard Buijze
See Also:
CurrentUnitOfWork

Constructor Summary
AbstractUnitOfWork()
           
 
Method Summary
 void commit()
          Commits the UnitOfWork.
protected  void commitInnerUnitOfWork()
          Commit all registered inner units of work.
protected abstract  void doCommit()
          Executes the logic required to commit this unit of work.
protected abstract  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 isStarted()
          Indicates whether this UnitOfWork is started.
protected abstract  void notifyListenersCleanup()
           
protected abstract  void notifyListenersPrepareCommit()
          Send a UnitOfWorkListener.onPrepareCommit(java.util.Set, java.util.List) notification to all registered listeners.
protected abstract  void notifyListenersRollback(Throwable cause)
           
 void rollback()
          Clear the UnitOfWork of any buffered changes.
 void rollback(Throwable cause)
          Clear the UnitOfWork of any buffered changes.
protected abstract  void saveAggregates()
          Saves all registered aggregates by calling their respective callbacks.
 void start()
          Starts the current unit of work, preparing it for aggregate registration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axonframework.unitofwork.UnitOfWork
publishEvent, registerAggregate, registerListener
 

Constructor Detail

AbstractUnitOfWork

public AbstractUnitOfWork()
Method Detail

commit

public void commit()
Description copied from interface: UnitOfWork
Commits the UnitOfWork. All registered aggregates that have not been registered as stored are saved in their respective repositories, buffered events are sent to their respective event bus, and all registered UnitOfWorkListeners are notified.

After the commit (successful or not), the UnitOfWork is unregistered from the CurrentUnitOfWork.

Specified by:
commit in interface UnitOfWork

notifyListenersCleanup

protected abstract void notifyListenersCleanup()

notifyListenersRollback

protected abstract void notifyListenersRollback(Throwable cause)

rollback

public void rollback()
Description copied from interface: UnitOfWork
Clear the UnitOfWork of any buffered changes. All buffered events and registered aggregates are discarded and registered UnitOfWorkListeners are notified.

If the rollback is a result of an exception, consider using UnitOfWork.rollback(Throwable) instead.

Specified by:
rollback in interface UnitOfWork

rollback

public void rollback(Throwable cause)
Description copied from interface: UnitOfWork
Clear the UnitOfWork of any buffered changes. All buffered events and registered aggregates are discarded and registered UnitOfWorkListeners are notified.

Specified by:
rollback in interface UnitOfWork
Parameters:
cause - The cause of the rollback. May be null.

start

public void start()
Description copied from interface: UnitOfWork
Starts the current unit of work, preparing it for aggregate registration. The UnitOfWork instance is registered with the CurrentUnitOfWork.

Specified by:
start in interface UnitOfWork

isStarted

public boolean isStarted()
Description copied from interface: UnitOfWork
Indicates whether this UnitOfWork is started. It is started when the UnitOfWork.start() method has been called, and if the UnitOfWork has not been committed or rolled back.

Specified by:
isStarted in interface UnitOfWork
Returns:
true if this UnitOfWork is started, false otherwise.

doStart

protected void doStart()
Performs logic required when starting this UnitOfWork instance.

This implementation does nothing and may be freely overridden.


doCommit

protected abstract void doCommit()
Executes the logic required to commit this unit of work.


doRollback

protected abstract void doRollback(Throwable cause)
Executes the logic required to commit this unit of work.

Parameters:
cause - the cause of the rollback

commitInnerUnitOfWork

protected void commitInnerUnitOfWork()
Commit all registered inner units of work. This should be invoked after events have been dispatched and before any listeners are notified of the commit.


saveAggregates

protected abstract void saveAggregates()
Saves all registered aggregates by calling their respective callbacks.


notifyListenersPrepareCommit

protected abstract void notifyListenersPrepareCommit()
Send a UnitOfWorkListener.onPrepareCommit(java.util.Set, java.util.List) notification to all registered listeners.



Copyright © 2011. All Rights Reserved.