use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class RecordStorageShould method withLifecycleColumns.
protected static EntityRecordWithColumns withLifecycleColumns(EntityRecord record) {
final LifecycleFlags flags = record.getLifecycleFlags();
final Map<String, MemoizedValue> columns = ImmutableMap.of(LifecycleColumns.ARCHIVED.columnName(), booleanColumn(LifecycleColumns.ARCHIVED.column(), flags.getArchived()), LifecycleColumns.DELETED.columnName(), booleanColumn(LifecycleColumns.DELETED.column(), flags.getDeleted()));
final EntityRecordWithColumns result = createRecord(record, columns);
return result;
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method match_ids.
@Test
public void match_ids() {
final Message genericId = Sample.messageOfType(ProjectId.class);
final Collection<Object> idFilter = Collections.<Object>singleton(genericId);
final Any entityId = AnyPacker.pack(genericId);
final EntityQuery<?> query = createQuery(idFilter, defaultQueryParameters());
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord matching = EntityRecord.newBuilder().setEntityId(entityId).build();
final Any otherEntityId = AnyPacker.pack(Sample.messageOfType(ProjectId.class));
final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(otherEntityId).build();
final EntityRecordWithColumns matchingRecord = of(matching);
final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
assertTrue(matcher.apply(matchingRecord));
assertFalse(matcher.apply(nonMatchingRecord));
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method match_columns.
@SuppressWarnings({ // Mocks <-> reflection issues
"unchecked", // Test data is constant
"ConstantConditions" })
@Test
public void match_columns() {
final String targetName = "feature";
final EntityColumn target = mock(EntityColumn.class);
when(target.isNullable()).thenReturn(true);
when(target.getStoredName()).thenReturn(targetName);
when(target.getType()).thenReturn(Boolean.class);
final Serializable acceptedValue = true;
final Collection<Object> ids = Collections.emptyList();
final Multimap<EntityColumn, ColumnFilter> filters = of(target, eq(targetName, acceptedValue));
final CompositeQueryParameter parameter = createParams(filters, ALL);
final QueryParameters params = QueryParameters.newBuilder().add(parameter).build();
final EntityQuery<?> query = createQuery(ids, params);
final Any matchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final Any nonMatchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord matching = EntityRecord.newBuilder().setEntityId(matchingId).build();
final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(nonMatchingId).build();
final EntityColumn.MemoizedValue storedValue = mock(EntityColumn.MemoizedValue.class);
when(storedValue.getSourceColumn()).thenReturn(target);
when(storedValue.getValue()).thenReturn(acceptedValue);
final Map<String, EntityColumn.MemoizedValue> matchingColumns = ImmutableMap.of(targetName, storedValue);
final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
final EntityRecordWithColumns matchingRecord = createRecord(matching, matchingColumns);
assertTrue(matcher.apply(matchingRecord));
assertFalse(matcher.apply(nonMatchingRecord));
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method not_match_by_wrong_field_name.
@Test
public void not_match_by_wrong_field_name() {
final String wrongName = "wrong";
final EntityColumn target = mock(EntityColumn.class);
final Multimap<EntityColumn, ColumnFilter> filters = of(target, eq(wrongName, "any"));
final CompositeQueryParameter parameter = createParams(filters, EITHER);
final QueryParameters params = QueryParameters.newBuilder().add(parameter).build();
final EntityQuery<?> query = createQuery(Collections.emptyList(), params);
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord record = EntityRecord.newBuilder().setEntityId(Any.getDefaultInstance()).build();
final EntityRecordWithColumns recordWithColumns = of(record);
assertFalse(matcher.apply(recordWithColumns));
}
use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.
the class RecordBasedRepository method store.
/**
* Stores {@linkplain Entity Entities} in bulk.
*
* <p>NOTE: The storage must be assigned before calling this method.
*
* @param entities the {@linkplain Entity Entities} to store
*/
public void store(Collection<E> entities) {
final Map<I, EntityRecordWithColumns> records = newHashMapWithExpectedSize(entities.size());
for (E entity : entities) {
final EntityRecordWithColumns recordWithColumns = toRecord(entity);
records.put(entity.getId(), recordWithColumns);
}
recordStorage().write(records);
}
Aggregations