Search in sources :

Example 6 with EntityRecordWithColumns

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;
}
Also used : MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) LifecycleFlags(io.spine.server.entity.LifecycleFlags)

Example 7 with EntityRecordWithColumns

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));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) ProjectId(io.spine.test.entity.ProjectId) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) Test(org.junit.Test)

Example 8 with EntityRecordWithColumns

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));
}
Also used : Serializable(java.io.Serializable) TaskId(io.spine.test.entity.TaskId) EntityColumn(io.spine.server.entity.storage.EntityColumn) ColumnFilter(io.spine.client.ColumnFilter) QueryParameters(io.spine.server.entity.storage.QueryParameters) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) CompositeQueryParameter(io.spine.server.entity.storage.CompositeQueryParameter) EntityRecord(io.spine.server.entity.EntityRecord) Test(org.junit.Test)

Example 9 with EntityRecordWithColumns

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));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EntityColumn(io.spine.server.entity.storage.EntityColumn) ColumnFilter(io.spine.client.ColumnFilter) QueryParameters(io.spine.server.entity.storage.QueryParameters) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) CompositeQueryParameter(io.spine.server.entity.storage.CompositeQueryParameter) Test(org.junit.Test)

Example 10 with EntityRecordWithColumns

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);
}
Also used : EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns)

Aggregations

EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)22 EntityRecord (io.spine.server.entity.EntityRecord)14 Test (org.junit.Test)12 Any (com.google.protobuf.Any)7 ColumnFilter (io.spine.client.ColumnFilter)5 Message (com.google.protobuf.Message)3 EntityFilters (io.spine.client.EntityFilters)3 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 Project (io.spine.test.storage.Project)3 Int32Value (com.google.protobuf.Int32Value)2 CompositeColumnFilter (io.spine.client.CompositeColumnFilter)2 TypeUrl (io.spine.type.TypeUrl)2 HashMap (java.util.HashMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newConcurrentMap (com.google.common.collect.Maps.newConcurrentMap)1 FieldMask (com.google.protobuf.FieldMask)1