A
- the type of the aggregate root class.I
- the type of identifier of the aggregate root class.@DomainRepository public interface Repository<A extends AggregateRoot<I>,I>
A repository is responsible for storing and retrieve a whole aggregate. It manipulates the aggregate through its root entity. It cannot directly store or retrieve parts of the aggregate.
A repository provides the illusion of an in-memory collection of all objects that are of the corresponding aggregate root type.
A repository implements a well-known interface that provides methods for adding, removing and querying objects.
A repository optionally implements methods that select objects based on criteria meaningful to domain experts. Those methods return fully instantiated objects or collections of objects whose attribute values meet the criteria.
Example:
public interface SomeRepository extends Repository<SomeAggregate, SomeId> { // Optional business-meaningful methods List<SomeAggregate> objectsByCategory(String category); } public class SomeJpaRepository implements SomeRepository { @Override public List<SomeAggregate> objectsByCategory(String category) { // implement specific query } }
Modifier and Type | Interface and Description |
---|---|
static interface |
Repository.Option
Marker interface for options that can be used to alter the results of some repository methods.
|
Modifier and Type | Method and Description |
---|---|
void |
add(A aggregate)
Adds an aggregate to the repository.
|
default A |
addOrUpdate(A aggregate)
Adds an aggregate to the repository or updates it if it already exists.
|
default void |
clear()
Removes all aggregates from the repository.
|
default boolean |
contains(A aggregate)
Checks that the specified aggregate is present in the repository.
|
default boolean |
contains(I id)
Checks that the aggregate identified by the specified identifier is present in the repository.
|
default boolean |
contains(Specification<A> specification)
Check if at least one aggregate satisfying the specified specification is present in the
repository.
|
default long |
count(Specification<A> specification)
Count the number of aggregates in the repository satisfying the given specification.
|
default Optional<A> |
get(I id)
Gets an aggregate identified by its identifier.
|
Stream<A> |
get(Specification<A> specification,
Repository.Option... options)
Finds all aggregates in the repository satisfying the given specification.
|
Class<A> |
getAggregateRootClass()
Returns the aggregate root class managed by the repository.
|
Class<I> |
getIdentifierClass()
Returns the aggregate root identifier class managed by the repository.
|
SpecificationBuilder |
getSpecificationBuilder()
Access to the specification builder.
|
default boolean |
isEmpty()
Return true if the repository is empty (i.e.
|
default void |
remove(A aggregate)
Removes the specified aggregate from the repository.
|
default void |
remove(I id)
Removes the existing aggregate identified with the specified identifier.
|
long |
remove(Specification<A> specification)
Removes all aggregates in the repository satisfying the given specification.
|
default long |
size()
Returns the number of aggregates in the repository.
|
default A |
update(A aggregate)
Updates an existing aggregate with the specified instance.
|
void add(A aggregate) throws AggregateExistsException
aggregate
- the aggregate to add.AggregateExistsException
- if the repository already contains the aggregate.Stream<A> get(Specification<A> specification, Repository.Option... options)
specification
- the specification aggregates must satisfy.options
- result options.Repository.Option
default Optional<A> get(I id)
id
- the aggregate identifier.default boolean contains(Specification<A> specification)
specification
- the specification.default boolean contains(I id)
id
- the aggregate identifier.default boolean contains(A aggregate)
contains(aggregate.getId()
)
.aggregate
- the aggregate identifier.default long count(Specification<A> specification)
specification
- the specification aggregates must satisfy.default long size()
default boolean isEmpty()
long remove(Specification<A> specification) throws AggregateNotFoundException
specification
- the specification aggregates must satisfy.AggregateNotFoundException
- if the repository doesn't contain the aggregate.default void remove(I id) throws AggregateNotFoundException
id
- the identifier of the aggregate to remove.AggregateNotFoundException
- if the repository doesn't contain the aggregate.default void remove(A aggregate) throws AggregateNotFoundException
aggregate
- the aggregate to remove.AggregateNotFoundException
- if the repository doesn't contain the aggregate.default A update(A aggregate) throws AggregateNotFoundException
aggregate
- the aggregate to update.AggregateNotFoundException
- if the repository doesn't contain the aggregate.default A addOrUpdate(A aggregate)
add(A)
and update(AggregateRoot)
should
be preferred.aggregate
- the aggregate to update.AggregateNotFoundException
- if the repository doesn't contain the aggregate.default void clear()
Class<A> getAggregateRootClass()
Class<I> getIdentifierClass()
SpecificationBuilder getSpecificationBuilder()
Copyright © 2013-2018–2019 SeedStack. All rights reserved.