|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.repository.AbstractRepository<T>
T
- The type of aggregate this repository storespublic abstract class AbstractRepository<T extends AggregateRoot>
Abstract implementation of the Repository
that takes care of the dispatching of events when an aggregate is
persisted. All uncommitted events on an aggregate are dispatched when the aggregate is saved.
LockingRepository
.
setEventBus(org.axonframework.eventhandling.EventBus)
,
LockingRepository
Constructor Summary | |
---|---|
protected |
AbstractRepository(Class<T> aggregateType)
Initializes a repository that stores aggregate of the given aggregateType . |
Method Summary | |
---|---|
void |
add(T aggregate)
Adds the given aggregate to the repository. |
protected abstract void |
doDelete(T aggregate)
Removes the aggregate from the repository. |
protected abstract T |
doLoad(Object aggregateIdentifier,
Long expectedVersion)
Loads and initialized the aggregate with the given aggregateIdentifier. |
protected abstract void |
doSave(T aggregate)
Performs the actual saving of the aggregate. |
protected Class<T> |
getAggregateType()
Returns the aggregate type stored by this repository. |
T |
load(Object aggregateIdentifier)
Load the aggregate with the given unique identifier. |
T |
load(Object aggregateIdentifier,
Long expectedVersion)
Load the aggregate with the given unique aggregateIdentifier , expecting the version of the aggregate
to be equal to the given expectedVersion . |
protected void |
postDelete(T aggregate)
Perform action that needs to be done directly after deleting an aggregate and committing the aggregate's uncommitted events. |
protected void |
postSave(T aggregate)
Perform action that needs to be done directly after updating an aggregate and committing the aggregate's uncommitted events. |
void |
setEventBus(EventBus eventBus)
Sets the event bus to which newly stored events should be published. |
protected void |
validateOnLoad(T aggregate,
Long expectedVersion)
Checks the aggregate for concurrent changes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractRepository(Class<T> aggregateType)
aggregateType
. All aggregates in this
repository must be instanceOf
this aggregate type.
aggregateType
- The type of aggregate stored in this repositoryMethod Detail |
---|
public void add(T aggregate)
aggregate
to the repository. The version of this aggregate must be null
,
indicating that it has not been previously persisted.
This method will not force the repository to save the aggregate immediately. Instead, it is registered with the
current UnitOfWork. To force storage of an aggregate, commit the current unit of work
(CurrentUnitOfWork.commit()
)
add
in interface Repository<T extends AggregateRoot>
aggregate
- The aggregate to add to the repository.public T load(Object aggregateIdentifier, Long expectedVersion)
aggregateIdentifier
, expecting the version of the aggregate
to be equal to the given expectedVersion
. If the expectedVersion
is null
,
no version validation is done.
When versions do not match, implementations may either raise an exception immediately when loading an aggregate,
or at any other time while the aggregate is registered in the current Unit Of Work.
load
in interface Repository<T extends AggregateRoot>
aggregateIdentifier
- The identifier of the aggregate to loadexpectedVersion
- The expected version of the aggregate to load, or null
to indicate the
version should not be checked
AggregateNotFoundException
- if aggregate with given id cannot be found
RuntimeException
- any exception thrown by implementing classesUnitOfWork
public T load(Object aggregateIdentifier)
load
in interface Repository<T extends AggregateRoot>
aggregateIdentifier
- The identifier of the aggregate to load
protected void validateOnLoad(T aggregate, Long expectedVersion)
ConflictingModificationException
when conflicting changes have been
detected.
This implementation throws a ConflictingAggregateVersionException
if the expected version is not null
and the version number of the aggregate does not match the expected version
aggregate
- The loaded aggregateexpectedVersion
- The expected version of the aggregate
ConflictingModificationException
ConflictingAggregateVersionException
protected Class<T> getAggregateType()
protected abstract void doSave(T aggregate)
aggregate
- the aggregate to storeprotected abstract T doLoad(Object aggregateIdentifier, Long expectedVersion)
aggregateIdentifier
- the identifier of the aggregate to loadexpectedVersion
- The expected version of the aggregate to load
AggregateNotFoundException
- if the aggregate with given identifier does not existprotected abstract void doDelete(T aggregate)
doLoad(Object, Long)
throw a AggregateNotFoundException
when
loading a deleted aggregate.
aggregate
- the aggregate to deletepublic void setEventBus(EventBus eventBus)
eventBus
- the event bus to publish events toprotected void postSave(T aggregate)
aggregate
- The aggregate instance being savedprotected void postDelete(T aggregate)
aggregate
- The aggregate instance being saved
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |