13
13
import tech .ydb .yoj .repository .db .EntitySchema ;
14
14
import tech .ydb .yoj .repository .db .Range ;
15
15
import tech .ydb .yoj .repository .db .Table ;
16
- import tech .ydb .yoj .repository .db .Tx ;
17
16
import tech .ydb .yoj .repository .db .ViewSchema ;
18
17
import tech .ydb .yoj .repository .db .bulk .BulkParams ;
19
18
import tech .ydb .yoj .repository .db .cache .FirstLevelCache ;
20
19
import tech .ydb .yoj .repository .db .cache .TransactionLocal ;
21
20
import tech .ydb .yoj .repository .db .readtable .ReadTableParams ;
22
21
import tech .ydb .yoj .repository .db .statement .Changeset ;
22
+ import tech .ydb .yoj .repository .ydb .YdbRepositoryTransaction ;
23
23
import tech .ydb .yoj .repository .ydb .bulk .BulkMapper ;
24
24
import tech .ydb .yoj .repository .ydb .bulk .BulkMapperImpl ;
25
25
import tech .ydb .yoj .repository .ydb .readtable .EntityIdKeyMapper ;
54
54
import static tech .ydb .yoj .repository .db .EntityExpressions .defaultOrder ;
55
55
56
56
public class YdbTable <T extends Entity <T >> implements Table <T > {
57
- private final QueryExecutor executor ;
57
+ private final YdbRepositoryTransaction <?> executor ;
58
58
@ Getter
59
59
private final Class <T > type ;
60
60
61
- public YdbTable (Class <T > type , QueryExecutor executor ) {
61
+ public YdbTable (Class <T > type , YdbRepositoryTransaction <?> executor ) {
62
62
this .type = type ;
63
- this .executor = new CheckingQueryExecutor ( executor ) ;
63
+ this .executor = executor ;
64
64
}
65
65
66
66
protected YdbTable (QueryExecutor executor ) {
67
- this .executor = new CheckingQueryExecutor ( executor ) ;
67
+ this .executor = ( YdbRepositoryTransaction <?>) executor ;
68
68
this .type = resolveEntityType ();
69
69
}
70
70
@@ -421,7 +421,7 @@ public T insert(T t) {
421
421
T entityToSave = t .preSave ();
422
422
executor .pendingExecute (YqlStatement .insert (type ), entityToSave );
423
423
executor .getTransactionLocal ().firstLevelCache ().put (entityToSave );
424
- executor .getTransactionLocal ().projectionCache ().save (entityToSave );
424
+ executor .getTransactionLocal ().projectionCache ().save (executor , entityToSave );
425
425
return t ;
426
426
}
427
427
@@ -430,15 +430,15 @@ public T save(T t) {
430
430
T entityToSave = t .preSave ();
431
431
executor .pendingExecute (YqlStatement .save (type ), entityToSave );
432
432
executor .getTransactionLocal ().firstLevelCache ().put (entityToSave );
433
- executor .getTransactionLocal ().projectionCache ().save (entityToSave );
433
+ executor .getTransactionLocal ().projectionCache ().save (executor , entityToSave );
434
434
return t ;
435
435
}
436
436
437
437
@ Override
438
438
public void delete (Entity .Id <T > id ) {
439
439
executor .pendingExecute (YqlStatement .delete (type ), id );
440
440
executor .getTransactionLocal ().firstLevelCache ().putEmpty (id );
441
- executor .getTransactionLocal ().projectionCache ().delete (id );
441
+ executor .getTransactionLocal ().projectionCache ().delete (executor , id );
442
442
}
443
443
444
444
/**
@@ -458,7 +458,7 @@ public <ID extends Id<T>> void migrate(ID id) {
458
458
T rawEntity = foundRaw .get (0 );
459
459
T entityToSave = rawEntity .postLoad ().preSave ();
460
460
executor .pendingExecute (YqlStatement .save (type ), entityToSave );
461
- executor .getTransactionLocal ().projectionCache ().save (entityToSave );
461
+ executor .getTransactionLocal ().projectionCache ().save (executor , entityToSave );
462
462
}
463
463
464
464
@ Override
@@ -494,55 +494,6 @@ default <IN> void bulkUpsert(BulkMapper<IN> mapper, List<IN> input, BulkParams p
494
494
TransactionLocal getTransactionLocal ();
495
495
}
496
496
497
- public static class CheckingQueryExecutor implements QueryExecutor {
498
- private final QueryExecutor delegate ;
499
- private final Tx originTx ;
500
-
501
- public CheckingQueryExecutor (QueryExecutor delegate ) {
502
- this .delegate = delegate ;
503
- this .originTx = Tx .Current .exists () ? Tx .Current .get () : null ;
504
- }
505
-
506
- private void check () {
507
- Tx .checkSameTx (originTx );
508
- }
509
-
510
- @ Override
511
- public <PARAMS , RESULT > List <RESULT > execute (Statement <PARAMS , RESULT > statement , PARAMS params ) {
512
- check ();
513
- return delegate .execute (statement , params );
514
- }
515
-
516
- @ Override
517
- public <PARAMS , RESULT > Stream <RESULT > executeScanQuery (Statement <PARAMS , RESULT > statement , PARAMS params ) {
518
- return delegate .executeScanQuery (statement , params );
519
- }
520
-
521
- @ Override
522
- public <PARAMS > void pendingExecute (Statement <PARAMS , ?> statement , PARAMS value ) {
523
- check ();
524
- delegate .pendingExecute (statement , value );
525
- }
526
-
527
- @ Override
528
- public <IN > void bulkUpsert (BulkMapper <IN > mapper , List <IN > input , BulkParams params ) {
529
- check ();
530
- delegate .bulkUpsert (mapper , input , params );
531
- }
532
-
533
- @ Override
534
- public <IN , OUT > Stream <OUT > readTable (ReadTableMapper <IN , OUT > mapper , ReadTableParams <IN > params ) {
535
- check ();
536
- return delegate .readTable (mapper , params );
537
- }
538
-
539
- @ Override
540
- public TransactionLocal getTransactionLocal () {
541
- check ();
542
- return delegate .getTransactionLocal ();
543
- }
544
- }
545
-
546
497
public <ID extends Id <T >> void updateIn (Collection <ID > ids , Changeset changeset ) {
547
498
var params = new UpdateInStatement .UpdateInStatementInput <>(ids , changeset .toMap ());
548
499
0 commit comments