Class AbstractRepository<K,T,R extends AbstractRepository<K,T,R>>

java.lang.Object
arez.component.internal.AbstractRepository<K,T,R>

public abstract class AbstractRepository<K,T,R extends AbstractRepository<K,T,R>> extends Object
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 Details

  • Method Details

    • shouldDisposeEntryOnDispose

      protected final boolean shouldDisposeEntryOnDispose()
    • contains

      public boolean contains(@Nonnull T entity)
    • findAll

      @Nonnull public final List<T> findAll()
      Return all the entities.
      Returns:
      all the entities.
    • findAll

      @Nonnull public final List<T> findAll(@Nonnull Comparator<T> sorter)
      Return all entities sorted by supplied comparator.
      Parameters:
      sorter - the comparator used to sort entities.
      Returns:
      the entity list result.
    • findAllByQuery

      @Nonnull public final List<T> findAllByQuery(@Nonnull Predicate<T> query)
      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

      @Nullable public final T findByQuery(@Nonnull Predicate<T> query)
      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

      @Nonnull public final T getByQuery(@Nonnull Predicate<T> query) throws NoResultException
      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

      @Nullable public final T findByArezId(@Nonnull K arezId)
    • getByArezId

      @Nonnull public final T getByArezId(@Nonnull K arezId) throws NoSuchEntityException
      Throws:
      NoSuchEntityException
    • self

      @Nonnull public final R self()
      Return the repository instance cast to typed subtype.
      Returns:
      the repository instance.
    • attach

      protected void attach(@Nonnull T entity)
      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

      @PreDispose protected void preDispose()
      Dispose or detach all the entities associated with the container.
    • destroy

      protected void destroy(@Nonnull T entity)
      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

      protected void detach(@Nonnull T entity)
      Detach entity from container without disposing entity. The entity must be attached to the container.
      Parameters:
      entity - the entity to detach.
    • reportRead

      protected boolean 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

      @Nonnull public Stream<T> entities()
      Return a stream of all entities in the container.
      Returns:
      the underlying entities.
    • entitiesValue

      @Observable(name="entities", expectSetter=false) @Nonnull protected Stream<T> entitiesValue()
      Return a stream of all entities in the container.
      Returns:
      the underlying entities.