@@ -51,7 +51,9 @@ public InMemoryTable(DbMemory<T> memory) {
5151 }
5252
5353 public InMemoryTable (InMemoryRepositoryTransaction transaction , Class <T > type ) {
54- this (transaction , TableDescriptor .from (EntitySchema .of (type )));
54+ this .schema = EntitySchema .of (type );
55+ this .tableDescriptor = TableDescriptor .from (schema );
56+ this .transaction = transaction ;
5557 }
5658
5759 public InMemoryTable (InMemoryRepositoryTransaction transaction , TableDescriptor <T > tableDescriptor ) {
@@ -62,7 +64,7 @@ public InMemoryTable(InMemoryRepositoryTransaction transaction, TableDescriptor<
6264
6365 @ Override
6466 public List <T > findAll () {
65- transaction .getWatcher ().markTableRead (tableDescriptor );
67+ transaction .getWatcher ().markTableRead (tableDescriptor , schema );
6668 return findAll0 ();
6769 }
6870
@@ -92,9 +94,7 @@ public void update(Entity.Id<T> id, Changeset changeset) {
9294 }
9395 Map <String , Object > cells = new HashMap <>(schema .flatten (found ));
9496
95- changeset .toMap ().forEach ((k , v ) -> {
96- cells .putAll (schema .flattenOneField (k , v ));
97- });
97+ changeset .toMap ().forEach ((k , v ) -> cells .putAll (schema .flattenOneField (k , v )));
9898
9999 T newInstance = schema .newInstance (cells );
100100
@@ -285,7 +285,7 @@ public <ID extends Entity.Id<T>> List<T> findUncached(
285285 Set <Map <String , Object >> idsSet = ids .stream ().map (idSchema ::flatten ).collect (toUnmodifiableSet ());
286286 Set <Set <String >> idFieldsSet = idsSet .stream ().map (Map ::keySet ).collect (toUnmodifiableSet ());
287287
288- Preconditions .checkArgument (idFieldsSet .size () > 0 , "ids must have at least one non-null field" );
288+ Preconditions .checkArgument (! idFieldsSet .isEmpty () , "ids must have at least one non-null field" );
289289 Preconditions .checkArgument (idFieldsSet .size () == 1 , "ids must have nulls in the same fields" );
290290
291291 Set <String > idFields = Iterables .getOnlyElement (idFieldsSet );
@@ -349,7 +349,7 @@ public <KEY> List<T> find(
349349 Set <Map <String , Object >> keysSet = keys .stream ().map (keySchema ::flatten ).collect (toUnmodifiableSet ());
350350 Set <Set <String >> keyFieldsSet = keysSet .stream ().map (Map ::keySet ).collect (toUnmodifiableSet ());
351351
352- Preconditions .checkArgument (keyFieldsSet .size () != 0 , "keys should have at least one non-null field" );
352+ Preconditions .checkArgument (! keyFieldsSet .isEmpty () , "keys should have at least one non-null field" );
353353 Preconditions .checkArgument (keyFieldsSet .size () == 1 , "keys should have nulls in the same fields" );
354354
355355 Set <String > keyFields = Iterables .getOnlyElement (keyFieldsSet );
@@ -377,7 +377,7 @@ public <KEY> List<T> find(
377377 );
378378
379379 for (Map <String , Object > id : keysSet ) {
380- transaction .getWatcher ().markRangeRead (tableDescriptor , id );
380+ transaction .getWatcher ().markRangeRead (tableDescriptor , schema , id );
381381 }
382382
383383 Stream <T > result = getAllEntries ().stream ()
@@ -413,7 +413,7 @@ private <ID extends Entity.Id<T>> void markKeyRead(ID id) {
413413 EntityIdSchema <Entity .Id <T >> idSchema = schema .getIdSchema ();
414414 if (idSchema .flattenFieldNames ().size () != idSchema .flatten (id ).size ()) {
415415 // Partial key, will throw error when not searching by PK prefix
416- transaction .getWatcher ().markRangeRead (tableDescriptor , Range .create (id , id ));
416+ transaction .getWatcher ().markRangeRead (tableDescriptor , Range .create (idSchema , id ));
417417 } else {
418418 transaction .getWatcher ().markRowRead (tableDescriptor , id );
419419 }
@@ -482,7 +482,8 @@ public <ID extends Entity.Id<T>> Stream<T> streamPartial(ID partial, int batchSi
482482 Preconditions .checkArgument (1 <= batchSize && batchSize <= 5000 ,
483483 "batchSize must be in range [1, 5000], got %s" , batchSize );
484484
485- Range <ID > range = partial == null ? null : Range .create (partial );
485+ EntityIdSchema <ID > idSchema = schema .getIdSchema ();
486+ Range <ID > range = partial == null ? null : Range .create (idSchema , partial );
486487 markRangeRead (range );
487488
488489 return streamPartial0 (range );
@@ -515,15 +516,16 @@ public <ID extends Entity.Id<T>> Stream<ID> streamPartialIds(ID partial, int bat
515516 Preconditions .checkArgument (1 <= batchSize && batchSize <= 10000 ,
516517 "batchSize must be in range [1, 10000], got %s" , batchSize );
517518
518- Range <ID > range = partial == null ? null : Range .create (partial );
519+ EntityIdSchema <ID > idSchema = schema .getIdSchema ();
520+ Range <ID > range = partial == null ? null : Range .create (idSchema , partial );
519521 markRangeRead (range );
520522
521523 return streamPartial0 (range ).map (e -> (ID ) e .getId ());
522524 }
523525
524526 private <ID extends Entity .Id <T >> void markRangeRead (Range <ID > range ) {
525527 if (range == null ) {
526- transaction .getWatcher ().markTableRead (tableDescriptor );
528+ transaction .getWatcher ().markTableRead (tableDescriptor , schema );
527529 } else {
528530 transaction .getWatcher ().markRangeRead (tableDescriptor , range );
529531 }
@@ -552,15 +554,16 @@ private <ID extends Entity.Id<T>> boolean readTableFilter(T e, ReadTableParams<I
552554 @ SuppressWarnings ("unchecked" )
553555 ID id = (ID ) e .getId ();
554556 ID from = params .getFromKey ();
557+ EntityIdSchema <ID > idSchema = schema .getIdSchema ();
555558 if (from != null ) {
556- int compare = EntityIdSchema . ofEntity ( id . getType ()) .compare (id , from );
559+ int compare = idSchema .compare (id , from );
557560 if (params .isFromInclusive () ? compare < 0 : compare <= 0 ) {
558561 return false ;
559562 }
560563 }
561564 ID to = params .getToKey ();
562565 if (to != null ) {
563- int compare = EntityIdSchema . ofEntity ( id . getType ()) .compare (id , to );
566+ int compare = idSchema .compare (id , to );
564567 return params .isToInclusive () ? compare <= 0 : compare < 0 ;
565568 }
566569 return true ;
@@ -589,7 +592,7 @@ private static <V extends Table.View, T extends Entity<T>> V toView(
589592 return null ;
590593 }
591594
592- ViewSchema <V > viewSchema = ViewSchema . of (viewType );
595+ ViewSchema <V > viewSchema = schema . getViewSchema (viewType );
593596 return Columns .fromEntity (schema , entity ).toSchema (viewSchema );
594597 }
595598
0 commit comments