I
- the type of entity IDspublic abstract class RecordStorage<I> extends AbstractStorage<I,io.spine.server.entity.EntityRecord,RecordReadRequest<I>> implements StorageWithLifecycleFlags<I,io.spine.server.entity.EntityRecord,RecordReadRequest<I>>
Modifier | Constructor and Description |
---|---|
protected |
RecordStorage(java.lang.Class<? extends Entity<?,?>> entityClass,
boolean multitenant)
Creates an instance of
RecordStorage . |
Modifier and Type | Method and Description |
---|---|
protected com.google.common.collect.ImmutableList<Column> |
columnList()
Obtains a list of columns of the managed
Entity . |
abstract boolean |
delete(I id)
Deletes the record with the passed ID.
|
java.util.Optional<io.spine.server.entity.EntityRecord> |
read(RecordReadRequest<I> request)
Reads a record which matches the specified request.
|
java.util.Optional<io.spine.server.entity.EntityRecord> |
read(RecordReadRequest<I> request,
com.google.protobuf.FieldMask fieldMask)
Reads a record which matches the specified request
and applies a
FieldMask to it. |
java.util.Iterator<io.spine.server.entity.EntityRecord> |
readAll(EntityQuery<I> query)
Reads all the records matching the given
EntityQuery and applies the given
FieldMask to the resulting record states. |
java.util.Iterator<io.spine.server.entity.EntityRecord> |
readAll(EntityQuery<I> query,
io.spine.client.ResponseFormat format)
Reads all the records matching the given
EntityQuery and applies the given
FieldMask to the resulting record states. |
java.util.Iterator<io.spine.server.entity.EntityRecord> |
readAll(io.spine.client.ResponseFormat format)
Reads all active items from the storage and apply
FieldMask to each of the results. |
protected abstract java.util.Iterator<io.spine.server.entity.EntityRecord> |
readAllRecords(EntityQuery<I> query,
io.spine.client.ResponseFormat format)
Obtains an iterator for reading records matching the query,
and applying the passed field mask to the results.
|
protected abstract java.util.Iterator<io.spine.server.entity.EntityRecord> |
readAllRecords(io.spine.client.ResponseFormat format)
Obtains an iterator for reading all records.
|
java.util.Optional<io.spine.server.entity.LifecycleFlags> |
readLifecycleFlags(I id)
Reads the lifecycle status for the entity with the passed ID.
|
java.util.Iterator<io.spine.server.entity.EntityRecord> |
readMultiple(java.lang.Iterable<I> ids,
com.google.protobuf.FieldMask fieldMask)
Reads multiple active items from the storage and applies
FieldMask to the results. |
protected abstract java.util.Iterator<io.spine.server.entity.EntityRecord> |
readMultipleRecords(java.lang.Iterable<I> ids,
com.google.protobuf.FieldMask fieldMask)
Obtains an iterator for reading multiple records by IDs, and
applying the passed field mask to the results.
|
protected abstract java.util.Optional<io.spine.server.entity.EntityRecord> |
readRecord(I id)
Reads a record from the storage by the passed ID.
|
void |
write(I id,
io.spine.server.entity.EntityRecord record)
Writes a record into the storage.
|
void |
write(I id,
EntityRecordWithColumns record)
Writes a record and its columns into the
storage.
|
void |
write(java.util.Map<I,EntityRecordWithColumns> records)
Writes a bulk of records into the storage.
|
void |
writeLifecycleFlags(I id,
io.spine.server.entity.LifecycleFlags flags)
Writes the lifecycle status for the entity with the passed ID.
|
protected abstract void |
writeRecord(I id,
EntityRecordWithColumns record)
Writes a record and the associated column
values into the storage.
|
protected abstract void |
writeRecords(java.util.Map<I,EntityRecordWithColumns> records)
Writes a bulk of records into the storage.
|
checkNotClosed, checkNotClosed, close, isClosed, isMultitenant, isOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, index, isMultitenant, isOpen
protected RecordStorage(java.lang.Class<? extends Entity<?,?>> entityClass, boolean multitenant)
RecordStorage
.public java.util.Optional<io.spine.server.entity.EntityRecord> read(RecordReadRequest<I> request)
read
in interface Storage<I,io.spine.server.entity.EntityRecord,RecordReadRequest<I>>
request
- the request to read the recordOptional.empty()
if there is no record with this IDpublic java.util.Optional<io.spine.server.entity.EntityRecord> read(RecordReadRequest<I> request, com.google.protobuf.FieldMask fieldMask)
FieldMask
to it.request
- the request to read the recordfieldMask
- fields to read.FieldMask
applied
or Optional.empty()
if there is no record matching this requestRecordStorage.read(RecordReadRequest)
public void write(I id, EntityRecordWithColumns record)
Rewrites it if a record with this ID already exists in the storage.
id
- the ID for the recordrecord
- the record to storejava.lang.IllegalStateException
- if the storage is closedRecordStorage.write(Object, EntityRecord)
public void write(I id, io.spine.server.entity.EntityRecord record)
Storage
Rewrites it if a record with this ID already exists in the storage.
write
in interface Storage<I,io.spine.server.entity.EntityRecord,RecordReadRequest<I>>
id
- the ID for the recordrecord
- the record to storepublic void write(java.util.Map<I,EntityRecordWithColumns> records)
Rewrites it if a record with this ID already exists in the storage.
records
- the ID to record map with the entries to storejava.lang.IllegalStateException
- if the storage is closedpublic java.util.Optional<io.spine.server.entity.LifecycleFlags> readLifecycleFlags(I id)
StorageWithLifecycleFlags
This method returns Optional.empty()
if none of the
flags were set before.
readLifecycleFlags
in interface StorageWithLifecycleFlags<I,io.spine.server.entity.EntityRecord,RecordReadRequest<I>>
id
- the ID of the entityOptional.empty()
public void writeLifecycleFlags(I id, io.spine.server.entity.LifecycleFlags flags)
StorageWithLifecycleFlags
writeLifecycleFlags
in interface StorageWithLifecycleFlags<I,io.spine.server.entity.EntityRecord,RecordReadRequest<I>>
id
- the ID of the entity for which to update the statusflags
- the status to writepublic abstract boolean delete(I id)
id
- the record to deletetrue
if the operation succeeded, false
otherwisepublic java.util.Iterator<io.spine.server.entity.EntityRecord> readMultiple(java.lang.Iterable<I> ids, com.google.protobuf.FieldMask fieldMask)
FieldMask
to the results.
The size of the returned Iterator
matches the size of the given ids
,
with nulls in place of missing or inactive entities.
ids
- the IDs of the items to readfieldMask
- the mask to applyFieldMask
appliedpublic java.util.Iterator<io.spine.server.entity.EntityRecord> readAll(io.spine.client.ResponseFormat format)
FieldMask
to each of the results.format
- the expected format of the responseFieldMask
appliedpublic java.util.Iterator<io.spine.server.entity.EntityRecord> readAll(EntityQuery<I> query, io.spine.client.ResponseFormat format)
EntityQuery
and applies the given
FieldMask
to the resulting record states.
By default, the entities supporting lifecycle will be returned only if they are active. To get inactive entities, the lifecycle attribute must be set to the provided query.
query
- the query to executeformat
- the format of the query responsepublic java.util.Iterator<io.spine.server.entity.EntityRecord> readAll(EntityQuery<I> query)
EntityQuery
and applies the given
FieldMask
to the resulting record states.
By default, if the query does not specify the LifecycleFlags but the entity supports them, all the resulting records are active. Otherwise the records obey the constraints provided by the query.
query
- the query to executeprotected final com.google.common.collect.ImmutableList<Column> columnList()
Entity
.Column
,
ColumnOption
protected abstract java.util.Optional<io.spine.server.entity.EntityRecord> readRecord(I id)
id
- the ID of the record to loadnull
if there is no record with this IDprotected abstract java.util.Iterator<io.spine.server.entity.EntityRecord> readMultipleRecords(java.lang.Iterable<I> ids, com.google.protobuf.FieldMask fieldMask)
The size of the returned Iterator
matches the size of the given ids
,
with nulls in place of missing or inactive entities.
BulkStorageOperationsMixin.readMultiple(java.lang.Iterable<I>, com.google.protobuf.FieldMask)
protected abstract java.util.Iterator<io.spine.server.entity.EntityRecord> readAllRecords(io.spine.client.ResponseFormat format)
Only active entities are returned.
format
- the expected format of the query responseBulkStorageOperationsMixin.readAll(io.spine.client.ResponseFormat)
protected abstract java.util.Iterator<io.spine.server.entity.EntityRecord> readAllRecords(EntityQuery<I> query, io.spine.client.ResponseFormat format)
Returns only active entities if the query does not specify the lifecycle flags. In order to read inactive entities, the corresponding filters must be set
to the provided query
.
protected abstract void writeRecord(I id, EntityRecordWithColumns record)
Rewrites it if a record with this ID already exists in the storage.
id
- an ID of the recordrecord
- a record to storeprotected abstract void writeRecords(java.util.Map<I,EntityRecordWithColumns> records)
Rewrites it if a record with this ID already exists in the storage.
records
- an ID to record map with the entries to store