|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.unitofwork.NestableUnitOfWork
public abstract class NestableUnitOfWork
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.
CurrentUnitOfWork
Constructor Summary | |
---|---|
NestableUnitOfWork()
|
Method Summary | ||
---|---|---|
void |
attachInheritedResources(UnitOfWork inheritingUnitOfWork)
Attach all inherited resources to the given unitOfWork . |
|
void |
attachResource(String name,
Object resource)
Attaches the given resource to this Unit of Work under the given name . |
|
void |
attachResource(String name,
Object resource,
boolean inherited)
Attaches the given resource to this Unit of Work under the given name . |
|
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 abstract void |
doStart()
Performs logic required when starting this UnitOfWork instance. |
|
|
getResource(String name)
Returns the resource previously attached under given name , or null if no such resource
is available. |
|
boolean |
isStarted()
Indicates whether this UnitOfWork is started. |
|
protected abstract void |
notifyListenersCleanup()
Send a UnitOfWorkListener.onCleanup(UnitOfWork) notification to all
registered listeners. |
|
protected abstract void |
notifyListenersPrepareCommit()
Send a UnitOfWorkListener.onPrepareCommit(UnitOfWork, java.util.Set,
java.util.List) notification to all registered listeners. |
|
protected abstract 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 abstract 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. |
|
protected abstract void |
registerScheduledEvents(UnitOfWork unitOfWork)
Invokes when a child Unit of Work should register its scheduled events with the given unitOfWork . |
|
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 |
---|
isTransactional, registerAggregate, registerListener |
Constructor Detail |
---|
public NestableUnitOfWork()
Method Detail |
---|
public void commit()
UnitOfWork
commit
in interface UnitOfWork
protected abstract void registerScheduledEvents(UnitOfWork unitOfWork)
unitOfWork
.
Typically, the given unitOfWork
is the parent of the current.
unitOfWork
- The Unit of Work to register scheduled events withUnitOfWork.publishEvent(org.axonframework.domain.EventMessage,
org.axonframework.eventhandling.EventBus)
protected abstract void notifyListenersCleanup()
UnitOfWorkListener.onCleanup(UnitOfWork)
notification to all
registered listeners. The implementation must ensure that all listeners are notified, even if one throws an
exception.
protected abstract void notifyListenersRollback(Throwable cause)
UnitOfWorkListener.onRollback(UnitOfWork, Throwable)
notification to all registered listeners.
cause
- The cause of the rollbackpublic void rollback()
UnitOfWork
UnitOfWorkListener
s are notified.
If the rollback is a result of an exception, consider using UnitOfWork.rollback(Throwable)
instead.
rollback
in interface UnitOfWork
public void rollback(Throwable cause)
UnitOfWork
UnitOfWorkListener
s are notified.
rollback
in interface UnitOfWork
cause
- The cause of the rollback. May be null
.public void start()
UnitOfWork
start
in interface UnitOfWork
public void publishEvent(EventMessage<?> event, EventBus eventBus)
UnitOfWork
event
on the given eventBus
. The UnitOfWork may either
publish immediately, or buffer the events until the UnitOfWork is committed.
publishEvent
in interface UnitOfWork
event
- The event to be published on the event buseventBus
- The event bus on which to publish the eventprotected abstract void registerForPublication(EventMessage<?> event, EventBus eventBus, boolean notifyRegistrationHandlers)
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.
event
- The Event to publisheventBus
- The Event Bus to publish the Event onnotifyRegistrationHandlers
- Indicates whether event registration handlers should be notified of this eventpublic boolean isStarted()
UnitOfWork
UnitOfWork.start()
method has been called,
and
if the UnitOfWork has not been committed or rolled back.
isStarted
in interface UnitOfWork
true
if this UnitOfWork is started, false
otherwise.protected abstract void doStart()
protected abstract void doCommit()
protected abstract void doRollback(Throwable cause)
cause
- the cause of the rollbackprotected void commitInnerUnitOfWork()
protected abstract void saveAggregates()
protected abstract void notifyListenersPrepareCommit()
UnitOfWorkListener.onPrepareCommit(UnitOfWork, java.util.Set,
java.util.List)
notification to all registered listeners.
public void attachResource(String name, Object resource)
UnitOfWork
resource
to this Unit of Work under the given name
. The attached
resource is not inherited by any nested Unit of Work (see UnitOfWork.attachResource(String, Object, boolean)
.
If a resource was already attached under this name, it is overwritten.
By convention, resources should be attached using the fully Qualified name of their type (or main interface).
For example, a JDBC Connection should be attached using the name "java.sql.Connection". When there is a
requirement to distinguish between different resources of the same type, their name may differ from this
convention.
attachResource
in interface UnitOfWork
name
- The name under which to attach the resourceresource
- The resource to attachpublic void attachResource(String name, Object resource, boolean inherited)
UnitOfWork
resource
to this Unit of Work under the given name
. The attached
resource is inherited
as indicated. Inherited resources are automatically attached to a nested
Unit of Work.
If a resource was already attached under this name, it is overwritten.
By convention, resources should be attached using the fully Qualified name of their type (or main interface).
For example, a JDBC Connection should be attached using the name "java.sql.Connection". When there is a
requirement to distinguish between different resources of the same type, their name may differ from this
convention.
attachResource
in interface UnitOfWork
name
- The name under which to attach the resourceresource
- The resource to attachinherited
- Whether or not the resource may be inherited by a nested Unit of Workpublic <T> T getResource(String name)
UnitOfWork
name
, or null
if no such resource
is available.
getResource
in interface UnitOfWork
T
- The type of resourcename
- The name under which the resource was attached
name
, or null
if no such resource is
available.public void attachInheritedResources(UnitOfWork inheritingUnitOfWork)
UnitOfWork
unitOfWork
.
attachInheritedResources
in interface UnitOfWork
inheritingUnitOfWork
- the Unit of Work inheriting the resources from this instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |