Skip to content

Commit b4b933a

Browse files
committed
Migrate to the refactored column API
1 parent 60863c7 commit b4b933a

File tree

11 files changed

+101
-106
lines changed

11 files changed

+101
-106
lines changed

datastore/src/main/java/io/spine/server/storage/datastore/DatastoreStorageFactory.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import io.spine.server.aggregate.AggregateStorage;
3333
import io.spine.server.delivery.InboxStorage;
3434
import io.spine.server.entity.Entity;
35-
import io.spine.server.entity.storage.ColumnStorageRules;
35+
import io.spine.server.entity.storage.ColumnMapping;
3636
import io.spine.server.projection.Projection;
3737
import io.spine.server.projection.ProjectionStorage;
3838
import io.spine.server.storage.RecordStorage;
@@ -43,7 +43,7 @@
4343
import io.spine.server.storage.datastore.tenant.NamespaceSupplier;
4444
import io.spine.server.storage.datastore.tenant.NsConverterFactory;
4545
import io.spine.server.storage.datastore.tenant.PrefixedNsConverterFactory;
46-
import io.spine.server.storage.datastore.type.DsStorageRules;
46+
import io.spine.server.storage.datastore.type.DsColumnMapping;
4747
import io.spine.server.tenant.TenantIndex;
4848

4949
import java.util.Map;
@@ -86,12 +86,12 @@ public class DatastoreStorageFactory implements StorageFactory {
8686
*/
8787
private final Map<Class<? extends Storage>, DatastoreWrapper> sysWrappers = newConcurrentMap();
8888

89-
private final ColumnStorageRules<Value<?>> columnStorageRules;
89+
private final ColumnMapping<Value<?>> columnMapping;
9090

9191
private final NsConverterFactory converterFactory;
9292

9393
protected DatastoreStorageFactory(Builder builder) {
94-
this.columnStorageRules = builder.columnStorageRules;
94+
this.columnMapping = builder.columnMapping;
9595
this.datastore = builder.datastore;
9696
this.converterFactory = builder.converterFactory;
9797
}
@@ -156,8 +156,8 @@ public InboxStorage createInboxStorage(boolean multitenant) {
156156
return new DsInboxStorage(wrapper, multitenant);
157157
}
158158

159-
public ColumnStorageRules<Value<?>> columnStorageRules() {
160-
return columnStorageRules;
159+
public ColumnMapping<Value<?>> columnMapping() {
160+
return columnMapping;
161161
}
162162

163163
/**
@@ -168,7 +168,7 @@ S configure(B builder, Class<? extends Entity<I, ?>> cls, ContextSpec context) {
168168
builder.setModelClass(asEntityClass(cls))
169169
.setDatastore(wrapperFor(context))
170170
.setMultitenant(context.isMultitenant())
171-
.setColumnStorageRules(columnStorageRules);
171+
.setColumnMapping(columnMapping);
172172
S storage = builder.build();
173173
return storage;
174174
}
@@ -268,7 +268,7 @@ public static Builder newBuilder() {
268268
public static class Builder {
269269

270270
private Datastore datastore;
271-
private ColumnStorageRules<Value<?>> columnStorageRules;
271+
private ColumnMapping<Value<?>> columnMapping;
272272
private NamespaceConverter namespaceConverter;
273273
private NsConverterFactory converterFactory;
274274

@@ -296,17 +296,17 @@ public Datastore getDatastore() {
296296
}
297297

298298
/**
299-
* Sets the {@link ColumnStorageRules}.
299+
* Sets the {@link ColumnMapping}.
300300
*
301-
* <p>Default value is {@link DsStorageRules}.
301+
* <p>Default value is {@link DsColumnMapping}.
302302
*
303-
* @param columnStorageRules
303+
* @param columnMapping
304304
* the storage rules for entity columns
305305
* @return self for method chaining
306306
*/
307307
public Builder
308-
setColumnStorageRules(ColumnStorageRules<Value<?>> columnStorageRules) {
309-
this.columnStorageRules = checkNotNull(columnStorageRules);
308+
setColumnMapping(ColumnMapping<Value<?>> columnMapping) {
309+
this.columnMapping = checkNotNull(columnMapping);
310310
return this;
311311
}
312312

@@ -335,8 +335,8 @@ public Builder setNamespaceConverter(NamespaceConverter converter) {
335335
*/
336336
public DatastoreStorageFactory build() {
337337
checkNotNull(datastore);
338-
if (columnStorageRules == null) {
339-
columnStorageRules = new DsStorageRules();
338+
if (columnMapping == null) {
339+
columnMapping = new DsColumnMapping();
340340
}
341341
if (namespaceConverter == null) {
342342
converterFactory = NsConverterFactory.defaults();

datastore/src/main/java/io/spine/server/storage/datastore/DsRecordStorage.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import io.spine.client.OrderBy;
3232
import io.spine.client.ResponseFormat;
3333
import io.spine.server.entity.EntityRecord;
34-
import io.spine.server.entity.storage.ColumnStorageRules;
34+
import io.spine.server.entity.storage.ColumnMapping;
3535
import io.spine.server.entity.storage.EntityQuery;
3636
import io.spine.server.entity.storage.EntityRecordWithColumns;
3737
import io.spine.server.entity.storage.QueryParameters;
@@ -70,7 +70,7 @@ public class DsRecordStorage<I> extends RecordStorage<I> {
7070
private final DsLookupByIds<I> idLookup;
7171
private final DsLookupByQueries queryLookup;
7272

73-
private final ColumnStorageRules<Value<?>> columnStorageRules;
73+
private final ColumnMapping<Value<?>> columnMapping;
7474
private final FilterAdapter columnFilterAdapter;
7575

7676
/**
@@ -93,8 +93,8 @@ protected DsRecordStorage(
9393
this.typeUrl = TypeUrl.from(b.getDescriptor());
9494
this.idClass = checkNotNull(b.getIdClass());
9595
this.datastore = b.getDatastore();
96-
this.columnStorageRules = checkNotNull(b.getColumnStorageRules());
97-
this.columnFilterAdapter = FilterAdapter.of(this.columnStorageRules);
96+
this.columnMapping = checkNotNull(b.getColumnMapping());
97+
this.columnFilterAdapter = FilterAdapter.of(this.columnMapping);
9898
this.idLookup = new DsLookupByIds<>(this.datastore, this.typeUrl);
9999
this.queryLookup = new DsLookupByQueries(this.datastore, this.typeUrl,
100100
this.columnFilterAdapter);
@@ -269,7 +269,7 @@ protected Entity entityRecordToEntity(I id, EntityRecordWithColumns record) {
269269
private void populateFromStorageFields(BaseEntity.Builder<Key, Entity.Builder> entity,
270270
EntityRecordWithColumns record) {
271271
record.columnNames().forEach(columnName -> {
272-
Value<?> columnValue = record.columnValue(columnName, columnStorageRules);
272+
Value<?> columnValue = record.columnValue(columnName, columnMapping);
273273
entity.set(columnName.value(), columnValue);
274274
});
275275
}

datastore/src/main/java/io/spine/server/storage/datastore/FilterAdapter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@
2525
import io.spine.client.Filter;
2626
import io.spine.protobuf.TypeConverter;
2727
import io.spine.server.entity.storage.Column;
28-
import io.spine.server.entity.storage.ColumnStorageRule;
29-
import io.spine.server.entity.storage.ColumnStorageRules;
28+
import io.spine.server.entity.storage.ColumnMapping;
29+
import io.spine.server.entity.storage.ColumnTypeMapping;
3030

3131
import static com.google.common.base.Preconditions.checkArgument;
3232
import static com.google.common.base.Preconditions.checkNotNull;
3333

3434
/**
35-
* A {@link Filter} to {@link Value} adapter based on {@link ColumnStorageRules}.
35+
* A {@link Filter} to {@link Value} adapter based on {@link ColumnMapping}.
3636
*/
3737
final class FilterAdapter {
3838

39-
private final ColumnStorageRules<Value<?>> columnStorageRules;
39+
private final ColumnMapping<Value<?>> columnMapping;
4040

41-
static FilterAdapter of(ColumnStorageRules<Value<?>> columnStorageRules) {
42-
return new FilterAdapter(columnStorageRules);
41+
static FilterAdapter of(ColumnMapping<Value<?>> columnMapping) {
42+
return new FilterAdapter(columnMapping);
4343
}
4444

45-
private FilterAdapter(ColumnStorageRules<Value<?>> columnStorageRules) {
46-
this.columnStorageRules = columnStorageRules;
45+
private FilterAdapter(ColumnMapping<Value<?>> columnMapping) {
46+
this.columnMapping = columnMapping;
4747
}
4848

4949
/**
@@ -64,8 +64,8 @@ Value<?> toValue(Column column, Filter columnFilter) {
6464
Class<?> columnClass = column.type();
6565
Object filterValueUnpacked = TypeConverter.toObject(filterValue, columnClass);
6666

67-
ColumnStorageRule<?, ? extends Value<?>> storageRule =
68-
columnStorageRules.of(filterValueUnpacked.getClass());
67+
ColumnTypeMapping<?, ? extends Value<?>> storageRule =
68+
columnMapping.of(filterValueUnpacked.getClass());
6969
checkArgument(storageRule != null, "Column of unknown type: %s.", column);
7070

7171
Value<?> result = storageRule.applyTo(filterValueUnpacked);

datastore/src/main/java/io/spine/server/storage/datastore/RecordStorageBuilder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.google.protobuf.Descriptors.Descriptor;
2626
import io.spine.server.entity.Entity;
2727
import io.spine.server.entity.model.EntityClass;
28-
import io.spine.server.entity.storage.ColumnStorageRules;
28+
import io.spine.server.entity.storage.ColumnMapping;
2929
import io.spine.server.storage.RecordStorage;
3030
import io.spine.type.TypeUrl;
3131

@@ -47,7 +47,7 @@ abstract class RecordStorageBuilder<I,
4747
private Descriptor descriptor;
4848
private DatastoreWrapper datastore;
4949
private boolean multitenant;
50-
private ColumnStorageRules<Value<?>> columnStorageRules;
50+
private ColumnMapping<Value<?>> columnMapping;
5151
private Class<I> idClass;
5252
private EntityClass<?> entityClass;
5353

@@ -132,12 +132,12 @@ public B setMultitenant(boolean multitenant) {
132132
}
133133

134134
/**
135-
* Assigns the column storage rules of
135+
* Sets the mapping rules of
136136
* the {@linkplain io.spine.server.entity.storage.Column entity columns}.
137137
*/
138138
@CanIgnoreReturnValue
139-
public B setColumnStorageRules(ColumnStorageRules<Value<?>> columnStorageRules) {
140-
this.columnStorageRules = checkNotNull(columnStorageRules);
139+
public B setColumnMapping(ColumnMapping<Value<?>> columnMapping) {
140+
this.columnMapping = checkNotNull(columnMapping);
141141
return self();
142142
}
143143

@@ -164,10 +164,10 @@ public boolean isMultitenant() {
164164
}
165165

166166
/**
167-
* Obtains the column storage rules of the storage.
167+
* Obtains the column mapping used in the storage.
168168
*/
169-
public ColumnStorageRules<Value<?>> getColumnStorageRules() {
170-
return columnStorageRules;
169+
public ColumnMapping<Value<?>> getColumnMapping() {
170+
return columnMapping;
171171
}
172172

173173
/**
@@ -187,7 +187,7 @@ public EntityClass<?> getEntityClass() {
187187
final void checkRequiredFields() {
188188
checkNotNull(descriptor, "State descriptor is not set.");
189189
checkNotNull(datastore, "Datastore is not set.");
190-
checkNotNull(columnStorageRules, "Column storage rules are not set.");
190+
checkNotNull(columnMapping, "Column mapping is not set.");
191191
}
192192

193193
abstract B self();

datastore/src/main/java/io/spine/server/storage/datastore/type/DsStorageRules.java renamed to datastore/src/main/java/io/spine/server/storage/datastore/type/DsColumnMapping.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,89 +34,89 @@
3434
import com.google.protobuf.Message;
3535
import com.google.protobuf.Timestamp;
3636
import io.spine.core.Version;
37-
import io.spine.server.entity.storage.AbstractStorageRules;
38-
import io.spine.server.entity.storage.ColumnStorageRule;
37+
import io.spine.server.entity.storage.AbstractColumnMapping;
38+
import io.spine.server.entity.storage.ColumnTypeMapping;
3939
import io.spine.string.Stringifiers;
4040

4141
import static com.google.cloud.Timestamp.ofTimeSecondsAndNanos;
4242

4343
/**
4444
* Non-{@code final}, implement to ..., maybe {@link io.spine.annotation.SPI}.
4545
*/
46-
public class DsStorageRules extends AbstractStorageRules<Value<?>> {
46+
public class DsColumnMapping extends AbstractColumnMapping<Value<?>> {
4747

4848
@Override
4949
protected void
50-
setupCustomRules(
51-
ImmutableMap.Builder<Class<?>, ColumnStorageRule<?, ? extends Value<?>>> builder) {
50+
setupCustomMapping(
51+
ImmutableMap.Builder<Class<?>, ColumnTypeMapping<?, ? extends Value<?>>> builder) {
5252
builder.put(Timestamp.class, ofTimestamp());
5353
builder.put(Version.class, ofVersion());
5454
}
5555

5656
@Override
57-
protected ColumnStorageRule<String, StringValue> ofString() {
57+
protected ColumnTypeMapping<String, StringValue> ofString() {
5858
return StringValue::of;
5959
}
6060

6161
@Override
62-
protected ColumnStorageRule<Integer, LongValue> ofInteger() {
62+
protected ColumnTypeMapping<Integer, LongValue> ofInteger() {
6363
return LongValue::of;
6464
}
6565

6666
@Override
67-
protected ColumnStorageRule<Long, LongValue> ofLong() {
67+
protected ColumnTypeMapping<Long, LongValue> ofLong() {
6868
return LongValue::of;
6969
}
7070

7171
@Override
72-
protected ColumnStorageRule<Float, DoubleValue> ofFloat() {
72+
protected ColumnTypeMapping<Float, DoubleValue> ofFloat() {
7373
return DoubleValue::of;
7474
}
7575

7676
@Override
77-
protected ColumnStorageRule<Double, DoubleValue> ofDouble() {
77+
protected ColumnTypeMapping<Double, DoubleValue> ofDouble() {
7878
return DoubleValue::of;
7979
}
8080

8181
@Override
82-
protected ColumnStorageRule<Boolean, BooleanValue> ofBoolean() {
82+
protected ColumnTypeMapping<Boolean, BooleanValue> ofBoolean() {
8383
return BooleanValue::of;
8484
}
8585

8686
@Override
87-
protected ColumnStorageRule<ByteString, BlobValue> ofByteString() {
87+
protected ColumnTypeMapping<ByteString, BlobValue> ofByteString() {
8888
return bytes -> {
8989
Blob blob = Blob.copyFrom(bytes.asReadOnlyByteBuffer());
9090
return BlobValue.of(blob);
9191
};
9292
}
9393

9494
@Override
95-
protected ColumnStorageRule<Enum<?>, LongValue> ofEnum() {
95+
protected ColumnTypeMapping<Enum<?>, LongValue> ofEnum() {
9696
return anEnum -> LongValue.of(anEnum.ordinal());
9797
}
9898

9999
@Override
100-
protected ColumnStorageRule<Message, StringValue> ofMessage() {
100+
protected ColumnTypeMapping<Message, StringValue> ofMessage() {
101101
return msg -> {
102102
String str = Stringifiers.toString(msg);
103103
return StringValue.of(str);
104104
};
105105
}
106106

107107
@Override
108-
public ColumnStorageRule<?, ? extends Value<?>> ofNull() {
108+
public ColumnTypeMapping<?, ? extends Value<?>> ofNull() {
109109
return o -> NullValue.of();
110110
}
111111

112112
@SuppressWarnings("ProtoTimestampGetSecondsGetNano") // This behavior is intended.
113-
private static ColumnStorageRule<Timestamp, TimestampValue> ofTimestamp() {
113+
private static ColumnTypeMapping<Timestamp, TimestampValue> ofTimestamp() {
114114
return timestamp -> TimestampValue.of(
115115
ofTimeSecondsAndNanos(timestamp.getSeconds(), timestamp.getNanos())
116116
);
117117
}
118118

119-
private static ColumnStorageRule<Version, LongValue> ofVersion() {
119+
private static ColumnTypeMapping<Version, LongValue> ofVersion() {
120120
return version -> LongValue.of(version.getNumber());
121121
}
122122
}

0 commit comments

Comments
 (0)