use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method delete_record.
// converter nullability issues
@SuppressWarnings("ConstantConditions")
@Test
public void delete_record() {
final RecordStorage<I> storage = getStorage();
final I id = newId();
final EntityRecord record = newStorageRecord(id);
// Write the record.
storage.write(id, record);
// Delete the record.
assertTrue(storage.delete(id));
// There's no record with such ID.
assertFalse(storage.read(id).isPresent());
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method write_and_read_record_by_Message_id.
@SuppressWarnings("ConstantConditions")
// Converter nullability issues and Optional getting
@Test
public void write_and_read_record_by_Message_id() {
final RecordStorage<I> storage = getStorage();
final I id = newId();
final EntityRecord expected = newStorageRecord(id);
storage.write(id, expected);
final EntityRecord actual = storage.read(id).get();
assertEquals(expected, actual);
close(storage);
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class EventStorage method iterator.
Iterator<Event> iterator(EventStreamQuery query) {
final EventRecordStorage storage = recordStorage();
final Map<EventId, EntityRecord> records = storage.readAll(query);
final Collection<EventEntity> entities = transform(records.entrySet(), storageRecordToEntity());
// TODO:2017-05-19:dmytro.dashenkov: Remove after the Entity Column approach is implemented.
final Collection<EventEntity> filtered = filter(entities, createEntityFilter(query));
final List<EventEntity> entityList = newArrayList(filtered);
Collections.sort(entityList, EventEntity.comparator());
final Iterator<Event> result = Iterators.transform(entityList.iterator(), getEventFunc());
return result;
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorage method writeLifecycleFlags.
@Override
public void writeLifecycleFlags(I id, LifecycleFlags flags) {
final Optional<EntityRecord> optional = read(id);
if (optional.isPresent()) {
final EntityRecord record = optional.get();
final EntityRecord updated = record.toBuilder().setLifecycleFlags(flags).build();
write(id, updated);
} else {
// The AggregateStateId is a special case, which is not handled by the Identifier class.
final String idStr = id instanceof AggregateStateId ? id.toString() : idToString(id);
throw newIllegalStateException("Unable to load record for entity with ID: %s", idStr);
}
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorage method read.
/**
* Reads a single item from the storage and applies a {@link FieldMask} to it.
*
* @param id ID of the item to read.
* @param fieldMask fields to read.
* @return the item with the given ID and with the {@code FieldMask} applied.
* @see #read(Object)
*/
public Optional<EntityRecord> read(I id, FieldMask fieldMask) {
final Optional<EntityRecord> rawResult = read(id);
if (!rawResult.isPresent()) {
return Optional.absent();
}
final EntityRecord.Builder builder = EntityRecord.newBuilder(rawResult.get());
final Any state = builder.getState();
final TypeUrl type = TypeUrl.parse(state.getTypeUrl());
final Message stateAsMessage = AnyPacker.unpack(state);
final Message maskedState = FieldMasks.applyMask(fieldMask, stateAsMessage, type);
final Any packedState = AnyPacker.pack(maskedState);
builder.setState(packedState);
return Optional.of(builder.build());
}
Aggregations