@@ -150,9 +150,12 @@ private ReactiveStatelessSessionImpl(
150
150
PersistenceContext persistenceContext ) {
151
151
super ( factory , options );
152
152
this .persistenceContext = persistenceContext ;
153
+ // StatelessSessionImpl constructor sets the Jdbc Batch Size to 0,
154
+ // setting it to null allows getConfiguredJdbcBatchSize() to return correct configured size
155
+ setJdbcBatchSize ( null );
153
156
Integer batchSize = getConfiguredJdbcBatchSize ();
154
157
reactiveConnection = batchSize == null || batchSize < 2
155
- ? connection
158
+ ? new BatchingConnection ( connection , 1 )
156
159
: new BatchingConnection ( connection , batchSize );
157
160
batchingHelperSession = this ;
158
161
influencers = new LoadQueryInfluencers ( factory );
@@ -551,9 +554,16 @@ public CompletionStage<Void> reactiveInsertAll(Object... entities) {
551
554
552
555
@ Override
553
556
public CompletionStage <Void > reactiveInsertAll (int batchSize , Object ... entities ) {
554
- final ReactiveConnection connection = batchingConnection ( batchSize );
555
- return loop ( entities , batchingHelperSession ::reactiveInsert )
556
- .thenCompose ( v -> connection .executeBatch () );
557
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
558
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
559
+ try {
560
+ final ReactiveConnection connection = batchingConnection ( batchSize );
561
+ return loop ( entities , batchingHelperSession ::reactiveInsert )
562
+ .thenCompose ( v -> connection .executeBatch () );
563
+ }
564
+ finally {
565
+ batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize );
566
+ }
557
567
}
558
568
559
569
@ Override
@@ -564,9 +574,16 @@ public CompletionStage<Void> reactiveUpdateAll(Object... entities) {
564
574
565
575
@ Override
566
576
public CompletionStage <Void > reactiveUpdateAll (int batchSize , Object ... entities ) {
567
- final ReactiveConnection connection = batchingConnection ( batchSize );
568
- return loop ( entities , batchingHelperSession ::reactiveUpdate )
569
- .thenCompose ( v -> connection .executeBatch () );
577
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
578
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
579
+ try {
580
+ final ReactiveConnection connection = batchingConnection ( batchSize );
581
+ return loop ( entities , batchingHelperSession ::reactiveUpdate )
582
+ .thenCompose ( v -> connection .executeBatch () );
583
+ }
584
+ finally {
585
+ batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize );
586
+ }
570
587
}
571
588
572
589
@ Override
@@ -577,9 +594,16 @@ public CompletionStage<Void> reactiveDeleteAll(Object... entities) {
577
594
578
595
@ Override
579
596
public CompletionStage <Void > reactiveDeleteAll (int batchSize , Object ... entities ) {
580
- final ReactiveConnection connection = batchingConnection ( batchSize );
581
- return loop ( entities , batchingHelperSession ::reactiveDelete )
582
- .thenCompose ( v -> connection .executeBatch () );
597
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
598
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
599
+ try {
600
+ final ReactiveConnection connection = batchingConnection ( batchSize );
601
+ return loop ( entities , batchingHelperSession ::reactiveDelete )
602
+ .thenCompose ( v -> connection .executeBatch () );
603
+ }
604
+ finally {
605
+ batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize );
606
+ }
583
607
}
584
608
585
609
@@ -591,9 +615,16 @@ public CompletionStage<Void> reactiveRefreshAll(Object... entities) {
591
615
592
616
@ Override
593
617
public CompletionStage <Void > reactiveRefreshAll (int batchSize , Object ... entities ) {
594
- final ReactiveConnection connection = batchingConnection ( batchSize );
595
- return loop ( entities , batchingHelperSession ::reactiveRefresh )
596
- .thenCompose ( v -> connection .executeBatch () );
618
+ final Integer jdbcBatchSize = batchingHelperSession .getJdbcBatchSize ();
619
+ batchingHelperSession .setJdbcBatchSize ( batchSize );
620
+ try {
621
+ final ReactiveConnection connection = batchingConnection ( batchSize );
622
+ return loop ( entities , batchingHelperSession ::reactiveRefresh )
623
+ .thenCompose ( v -> connection .executeBatch () );
624
+ }
625
+ finally {
626
+ batchingHelperSession .setJdbcBatchSize ( jdbcBatchSize );
627
+ }
597
628
}
598
629
599
630
private ReactiveConnection batchingConnection (int batchSize ) {
0 commit comments