Package arez.component.internal
Class AbstractRepository<K,T,R extends AbstractRepository<K,T,R>>
java.lang.Object
arez.component.internal.AbstractRepository<K,T,R>
Abstract base class for repositories that contain Arez components.
This class is used by the annotation processor as a base class from which to derive the actual
repositories for each type.
When multiple results are returned as a list, they are passed through CollectionsUtil.asList(Stream)
or
CollectionsUtil.wrap(List)
and this will convert the result set to an unmodifiable variant if
Arez.areCollectionsPropertiesUnmodifiable()
returns true. Typically this means that in
development mode these will be made immutable but that the lists will be passed through as-is
in production mode for maximum performance.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Attach specified entity to the set of entities managed by the container.boolean
protected void
Detach the entity from the container and dispose the entity.protected void
Detach entity from container without disposing entity.entities()
Return a stream of all entities in the container.Return a stream of all entities in the container.findAll()
Return all the entities.findAll
(Comparator<T> sorter) Return all entities sorted by supplied comparator.findAllByQuery
(Predicate<T> query) Return all entities that match query.findAllByQuery
(Predicate<T> query, Comparator<T> sorter) Return all entities that match query sorted by supplied comparator.final T
findByArezId
(K arezId) final T
findByQuery
(Predicate<T> query) Return the entity that matches query or null if unable to locate matching entity.final T
getByArezId
(K arezId) final T
getByQuery
(Predicate<T> query) Return the entity that matches query else throw an exception.protected abstract ObservableValue<?>
Return the observable associated with entities.protected void
Dispose or detach all the entities associated with the container.protected boolean
final R
self()
Return the repository instance cast to typed subtype.protected final boolean
-
Constructor Details
-
AbstractRepository
public AbstractRepository()
-
-
Method Details
-
shouldDisposeEntryOnDispose
-
contains
-
findAll
Return all the entities.- Returns:
- all the entities.
-
findAll
Return all entities sorted by supplied comparator.- Parameters:
sorter
- the comparator used to sort entities.- Returns:
- the entity list result.
-
findAllByQuery
Return all entities that match query.- Parameters:
query
- the predicate used to select entities.- Returns:
- the entity list result.
-
findAllByQuery
@Nonnull public final List<T> findAllByQuery(@Nonnull Predicate<T> query, @Nonnull Comparator<T> sorter) Return all entities that match query sorted by supplied comparator.- Parameters:
query
- the predicate used to select entities.sorter
- the comparator used to sort entities.- Returns:
- the entity list result.
-
findByQuery
Return the entity that matches query or null if unable to locate matching entity.- Parameters:
query
- the predicate used to select entity.- Returns:
- the entity or null if unable to locate matching entity.
-
getByQuery
Return the entity that matches query else throw an exception.- Parameters:
query
- the predicate used to select entity.- Returns:
- the entity.
- Throws:
NoResultException
- if unable to locate matching entity.
-
findByArezId
-
getByArezId
- Throws:
NoSuchEntityException
-
self
Return the repository instance cast to typed subtype.- Returns:
- the repository instance.
-
attach
Attach specified entity to the set of entities managed by the container. This should not be invoked if the entity is already attached to the repository.- Parameters:
entity
- the entity to register.
-
preDispose
Dispose or detach all the entities associated with the container. -
destroy
Detach the entity from the container and dispose the entity. The entity must be attached to the container.- Parameters:
entity
- the entity to destroy.
-
detach
Detach entity from container without disposing entity. The entity must be attached to the container.- Parameters:
entity
- the entity to detach.
-
reportRead
-
getEntitiesObservableValue
Return the observable associated with entities. This template method is implemented by the Arez annotation processor and is used internally to container. It should not be invoked by extensions.- Returns:
- the Arez observable associated with entities observable property.
-
entities
Return a stream of all entities in the container.- Returns:
- the underlying entities.
-
entitiesValue
Return a stream of all entities in the container.- Returns:
- the underlying entities.
-