I
- the type of IDs of aggregates managed by this storage@SPI public abstract class AggregateStorage<I> extends AbstractStorage<I,io.spine.server.aggregate.AggregateHistory,AggregateReadRequest<I>> implements StorageWithLifecycleFlags<I,io.spine.server.aggregate.AggregateHistory,AggregateReadRequest<I>>
Modifier | Constructor and Description |
---|---|
protected |
AggregateStorage(boolean multitenant) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkNotClosed()
Ensures the storage is not closed.
|
protected abstract java.util.Iterator<I> |
distinctAggregateIds()
Obtains distinct aggregate IDs from the stored event records.
|
protected abstract java.util.Iterator<io.spine.server.aggregate.AggregateEventRecord> |
historyBackward(AggregateReadRequest<I> request)
Creates iterator of aggregate event history with the reverse traversal.
|
java.util.Iterator<I> |
index()
Returns an iterator over identifiers of records in the storage.
|
java.util.Optional<io.spine.server.aggregate.AggregateHistory> |
read(AggregateReadRequest<I> request)
Forms and returns an
AggregateHistory based on the
aggregate history. |
protected abstract void |
truncate(int snapshotIndex)
Drops all records which occur before the Nth snapshot for each entity.
|
protected abstract void |
truncate(int snapshotIndex,
com.google.protobuf.Timestamp date)
Drops all records older than
date but not newer than the Nth snapshot for each
entity. |
void |
write(I id,
io.spine.server.aggregate.AggregateHistory events)
Writes events into the storage.
|
protected abstract void |
writeRecord(I id,
io.spine.server.aggregate.AggregateEventRecord record)
Writes the passed record into the storage.
|
checkNotClosed, close, isClosed, isMultitenant, isOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
readLifecycleFlags, writeLifecycleFlags
close, isMultitenant, isOpen
protected void checkNotClosed() throws java.lang.IllegalStateException
If the storage is closed, throws IllegalStateException
.
Opens the method for the package.
checkNotClosed
in class AbstractStorage<I,io.spine.server.aggregate.AggregateHistory,AggregateReadRequest<I>>
java.lang.IllegalStateException
- if the storage is closedpublic java.util.Iterator<I> index()
Attempts to read aggregate IDs from the MirrorRepository
, as they are already
stored there in a convenient form.
If an aggregate MirrorRepository
is not configured to use for reads with this
repository, falls back to the default method of getting distinct aggregate IDs
from the event records.
index
in interface Storage<I,io.spine.server.aggregate.AggregateHistory,AggregateReadRequest<I>>
public java.util.Optional<io.spine.server.aggregate.AggregateHistory> read(AggregateReadRequest<I> request)
AggregateHistory
based on the
aggregate history.read
in interface Storage<I,io.spine.server.aggregate.AggregateHistory,AggregateReadRequest<I>>
request
- the aggregate read request based on which to form a recordOptional.empty()
if the
aggregate history is emptyjava.lang.IllegalStateException
- if the storage was closed beforepublic void write(I id, io.spine.server.aggregate.AggregateHistory events)
NOTE: does not rewrite any events. Several events can be associated with one aggregate ID.
write
in interface Storage<I,io.spine.server.aggregate.AggregateHistory,AggregateReadRequest<I>>
id
- the ID for the recordevents
- non empty aggregate state record to storeprotected abstract void writeRecord(I id, io.spine.server.aggregate.AggregateEventRecord record)
id
- the aggregate IDrecord
- the record to writeprotected abstract java.util.Iterator<io.spine.server.aggregate.AggregateEventRecord> historyBackward(AggregateReadRequest<I> request)
Records are sorted by timestamp descending (from newer to older). The iterator is empty if there's no history for the aggregate with passed ID.
request
- the read requestprotected abstract void truncate(int snapshotIndex)
protected abstract void truncate(int snapshotIndex, com.google.protobuf.Timestamp date)
date
but not newer than the Nth snapshot for each
entity.protected abstract java.util.Iterator<I> distinctAggregateIds()