org.axonframework.repository
Interface Repository<T>

Type Parameters:
T - The type of aggregate this repository stores.
All Known Implementing Classes:
AbstractRepository, CachingEventSourcingRepository, EventSourcingRepository, GenericJpaRepository, HybridJpaRepository, LockingRepository

public interface Repository<T>

The repository provides an abstraction of the storage of aggregates.

Since:
0.1
Author:
Allard Buijze

Method Summary
 void add(T aggregate)
          Adds the given aggregate to the 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.
 

Method Detail

load

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. 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.

Parameters:
aggregateIdentifier - The identifier of the aggregate to load
expectedVersion - The expected version of the aggregate to load, or null to indicate the version should not be checked
Returns:
The aggregate root with the given identifier.
Throws:
AggregateNotFoundException - if aggregate with given id cannot be found
ConflictingModificationException - if the expectedVersion did not match the aggregate's actual version
See Also:
UnitOfWork

load

T load(Object aggregateIdentifier)
Load the aggregate with the given unique identifier. No version checks are done when loading an aggregate, meaning that concurrent access will not be checked for.

Parameters:
aggregateIdentifier - The identifier of the aggregate to load
Returns:
The aggregate root with the given identifier.
Throws:
AggregateNotFoundException - if aggregate with given id cannot be found

add

void add(T aggregate)
Adds the given 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())

Parameters:
aggregate - The aggregate to add to the repository.
Throws:
IllegalArgumentException - if the given aggregate is not newly created. This means AggregateRoot.getVersion() must return null.


Copyright © 2010-2016. All Rights Reserved.