use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class RecordBasedRepository method store.
/**
* {@inheritDoc}
*/
@Override
public void store(E entity) {
final EntityRecordWithColumns record = toRecord(entity);
final RecordStorage<I> storage = recordStorage();
storage.write(entity.getId(), record);
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class ColumnRecordsShould method feed_entity_columns_to_database_record.
@Test
public void feed_entity_columns_to_database_record() {
// Set up mocks and arguments
final List<Object> destination = new ArrayList<>(MOCK_COLUMNS_COUNT);
final Map<String, Column.MemoizedValue<?>> columns = setupMockColumnsAllowingNulls();
final CollectAnyColumnType type = spy(CollectAnyColumnType.class);
final ColumnTypeRegistry<CollectAnyColumnType> registry = ColumnTypeRegistry.<CollectAnyColumnType>newBuilder().put(Object.class, type).build();
final EntityRecordWithColumns recordWithColumns = EntityRecordWithColumns.of(EntityRecord.getDefaultInstance(), columns);
final Function<String, Object> colIdMapper = spy(new NoOpColumnIdentifierMapper());
// Invoke the prepersistence action
ColumnRecords.feedColumnsTo(destination, recordWithColumns, registry, colIdMapper);
// Verify calls
verify(colIdMapper, times(MOCK_COLUMNS_COUNT)).apply(anyString());
verify(type, times(MOCK_NON_NULL_COLUMNS_COUNT)).setColumnValue(eq(destination), any(Object.class), anyString());
verify(type, times(MOCK_NULL_COLUMNS_COUNT)).setNull(eq(destination), anyString());
final int indexOfNull = destination.indexOf(null);
assertTrue("Null value was not saved to the destination", indexOfNull >= 0);
assertContainsAll(destination, getNonNullColumnValues().toArray());
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class TenantRecords method findAndApplyFieldMask.
EntityRecord findAndApplyFieldMask(I givenId, FieldMask fieldMask) {
EntityRecord matchingResult = null;
for (I recordId : filtered.keySet()) {
if (recordId.equals(givenId)) {
final Optional<EntityRecordWithColumns> record = get(recordId);
if (!record.isPresent()) {
continue;
}
EntityRecord.Builder matchingRecord = record.get().getRecord().toBuilder();
final Any state = matchingRecord.getState();
final TypeUrl typeUrl = TypeUrl.parse(state.getTypeUrl());
final Message wholeState = unpack(state);
final Message maskedState = applyMask(fieldMask, wholeState, typeUrl);
final Any processed = pack(maskedState);
matchingRecord.setState(processed);
matchingResult = matchingRecord.build();
}
}
return matchingResult;
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class TenantRecords method readAllRecords.
Map<I, EntityRecord> readAllRecords(FieldMask fieldMask) {
if (fieldMask.getPathsList().isEmpty()) {
return readAllRecords();
}
if (isEmpty()) {
return ImmutableMap.of();
}
final ImmutableMap.Builder<I, EntityRecord> result = ImmutableMap.builder();
for (Map.Entry<I, EntityRecordWithColumns> storageEntry : filtered.entrySet()) {
final I id = storageEntry.getKey();
final EntityRecord rawRecord = storageEntry.getValue().getRecord();
final TypeUrl type = TypeUrl.parse(rawRecord.getState().getTypeUrl());
final Any recordState = rawRecord.getState();
final Message stateAsMessage = unpack(recordState);
final Message processedState = applyMask(fieldMask, stateAsMessage, type);
final Any packedState = pack(processedState);
final EntityRecord resultingRecord = EntityRecord.newBuilder().setState(packedState).build();
result.put(id, resultingRecord);
}
return result.build();
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class RecordBasedRepository method toRecord.
/**
* Converts the passed entity into the record.
*/
protected EntityRecordWithColumns toRecord(E entity) {
final EntityRecord entityRecord = entityConverter().convert(entity);
checkNotNull(entityRecord);
final EntityRecordWithColumns recordWithColumns = EntityRecordWithColumns.create(entityRecord, entity, recordStorage());
return recordWithColumns;
}
Aggregations