Repository

public abstract class Repository<I, E extends Entity<I, ? extends Object>> implements ContextAware, Closeable

Abstract base class for repositories.

Inheritors

Constructors

Link copied to clipboard
protected void Repository()
Creates the repository.

Functions

Link copied to clipboard
protected static S checkStorage<S extends AutoCloseable>(S storage)
Ensures that the storage is not null.
Link copied to clipboard
public void close()
Closes the repository by closing the underlying storage.
Link copied to clipboard
protected final BoundedContext context()
Obtains the BoundedContext to which this repository belongs.
Link copied to clipboard
public abstract E create(I id)
Create a new entity instance with its default state.
Link copied to clipboard
protected abstract Storage<I, ? extends Object, ? extends Object> createStorage()
Creates the storage for this repository.
Link copied to clipboard
Obtains StorageFactory associated with the ServerEnvironment for creating standard storages.
Link copied to clipboard
public final Class<E> entityClass()
Returns the class of entities managed by this repository.
Link copied to clipboard
Obtains model class for the entities managed by this repository.
Link copied to clipboard
public final TypeUrl entityStateType()
Obtains the TypeUrl for the state objects wrapped by entities managed by this repository.
Link copied to clipboard
Creates an EventFilter for this repository.
Link copied to clipboard
public abstract Optional<E> find(I id)
Finds an entity with the passed ID.
Link copied to clipboard
protected final boolean hasContext()
Verifies whether the repository is registered with a BoundedContext.
Link copied to clipboard
public final Class<I> idClass()
Returns the class of IDs used by this repository.
Link copied to clipboard
public Iterator<I> index()
Returns an iterator over the identifiers of all the entities managed by this repository.
Link copied to clipboard
public final boolean isOpen()
Verifies if the repository is open.
Link copied to clipboard
public boolean isRegistered()
Tells if the repository is registered in a BoundedContext.
Link copied to clipboard
protected boolean isTypeSupplier()
Tells if this repository should be registered as a type supplier with a Stand of the BoundedContext to which this repository belongs.
Link copied to clipboard
public Iterator<E> iterator(Predicate<E> filter)
Returns an iterator over the entities managed by the repository that match the passed filter.
Link copied to clipboard
Obtains an instance of EntityLifecycle for the entity with the given ID.
Link copied to clipboard
public void onRegistered()
The callback is invoked by a BoundedContext when adding the repository.
Link copied to clipboard
protected void onRoutingFailed(SignalEnvelope<? extends Object, ? extends Object, ? extends Object> envelope, Throwable cause)
A callback invoked when an exception is thrown from message routing.
Link copied to clipboard
protected final void open()
Initializes the storage of the repository.
Link copied to clipboard
public void registerWith(BoundedContext context)
Assigns a BoundedContext to this repository.
Link copied to clipboard
protected final Optional<R> route<M extends Message, C extends MessageContext, R>(Route<M, C, R> routing, SignalEnvelope<? extends Object, ? extends Object, C> envelope)
Link copied to clipboard
protected final Storage<I, ? extends Object, ? extends Object> storage()
Returns the storage assigned to this repository.
Link copied to clipboard
public final boolean storageAssigned()
Returns true if the storage is assigned, false otherwise.
Link copied to clipboard
protected abstract void store(E obj)
Stores the passed object.
Link copied to clipboard
protected EntityClass<E> toModelClass(Class<E> cls)
Obtains a model class for the passed entity class value.

Inherited functions

Link copied to clipboard
public void checkNotRegistered()
Verifies that this instance is NOT registered yet.
Link copied to clipboard
public void checkOpen()
Ensures that the object is open.
Link copied to clipboard
public void checkRegistered()
Verifies that this instance is already registered.