|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.repository.AbstractRepository<T> org.axonframework.repository.LockingRepository<T>
T
- The type that this aggregate storespublic abstract class LockingRepository<T extends AggregateRoot>
Implementation of the Repository interface that takes provides a locking mechanism to prevent concurrent modifications of persisted aggregates. Unless there is a locking mechanism present in the underlying persistence environment, it is recommended to use a LockingRepository (or one of its subclasses).
The LockingRepository can be initialized with two strategies:
Constructor Summary | |
---|---|
protected |
LockingRepository(Class<T> aggregateType)
Initialize a repository with a pessimistic locking strategy. |
protected |
LockingRepository(Class<T> aggregateType,
LockManager lockManager)
Initialize the repository with the given lockManager . |
Method Summary | |
---|---|
void |
add(T aggregate)
Adds the given aggregate to the repository. |
protected void |
doDelete(T aggregate)
Verifies whether all locks are valid and delegates to doDeleteWithLock(org.axonframework.domain.AggregateRoot) to perform actual deleting. |
protected abstract void |
doDeleteWithLock(T aggregate)
Perform the actual deleting of the aggregate. |
protected abstract T |
doLoad(Object aggregateIdentifier,
Long expectedVersion)
Perform the actual loading of an aggregate. |
protected void |
doSave(T aggregate)
Verifies whether all locks are valid and delegates to doSaveWithLock(org.axonframework.domain.AggregateRoot) to perform actual storage. |
protected abstract void |
doSaveWithLock(T aggregate)
Perform the actual saving of the aggregate. |
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 . |
Methods inherited from class org.axonframework.repository.AbstractRepository |
---|
getAggregateType, load, postDelete, postSave, setEventBus, validateOnLoad |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected LockingRepository(Class<T> aggregateType)
aggregateType
- The type of aggregate stored in this repositoryprotected LockingRepository(Class<T> aggregateType, LockManager lockManager)
lockManager
.
aggregateType
- The type of aggregate stored in this repositorylockManager
- the lock manager to useMethod Detail |
---|
public void add(T aggregate)
AbstractRepository
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>
add
in class AbstractRepository<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>
load
in class AbstractRepository<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
protected final void doSave(T aggregate)
doSaveWithLock(org.axonframework.domain.AggregateRoot)
to perform actual storage.
doSave
in class AbstractRepository<T extends AggregateRoot>
aggregate
- the aggregate to storeprotected final void doDelete(T aggregate)
doDeleteWithLock(org.axonframework.domain.AggregateRoot)
to perform actual deleting.
doDelete
in class AbstractRepository<T extends AggregateRoot>
aggregate
- the aggregate to deleteprotected abstract void doSaveWithLock(T aggregate)
aggregate
- the aggregate to storeprotected abstract void doDeleteWithLock(T aggregate)
aggregate
- the aggregate to deleteprotected abstract T doLoad(Object aggregateIdentifier, Long expectedVersion)
doLoad
in class AbstractRepository<T extends AggregateRoot>
aggregateIdentifier
- the identifier of the aggregate to loadexpectedVersion
- The expected version of the aggregate
AggregateNotFoundException
- if aggregate with given id cannot be found
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |