30
30
import com .datastax .oss .driver .api .core .cql .BatchType ;
31
31
import com .datastax .oss .driver .api .core .cql .BatchableStatement ;
32
32
import com .datastax .oss .driver .api .core .cql .SimpleStatement ;
33
+ import com .datastax .oss .driver .api .core .cql .Statement ;
33
34
import com .datastax .oss .driver .api .core .metadata .Node ;
34
35
import com .datastax .oss .driver .api .core .metadata .token .Token ;
35
36
import com .datastax .oss .driver .shaded .guava .common .collect .ImmutableList ;
@@ -68,6 +69,7 @@ public class DefaultBatchStatement implements BatchStatement {
68
69
private final Duration timeout ;
69
70
private final Node node ;
70
71
private final int nowInSeconds ;
72
+ private final Boolean isLWT ;
71
73
72
74
public DefaultBatchStatement (
73
75
BatchType batchType ,
@@ -88,7 +90,8 @@ public DefaultBatchStatement(
88
90
ConsistencyLevel serialConsistencyLevel ,
89
91
Duration timeout ,
90
92
Node node ,
91
- int nowInSeconds ) {
93
+ int nowInSeconds ,
94
+ Boolean isLWT ) {
92
95
for (BatchableStatement <?> statement : statements ) {
93
96
if (statement != null
94
97
&& (statement .getConsistencyLevel () != null
@@ -120,6 +123,7 @@ public DefaultBatchStatement(
120
123
this .timeout = timeout ;
121
124
this .node = node ;
122
125
this .nowInSeconds = nowInSeconds ;
126
+ this .isLWT = isLWT ;
123
127
}
124
128
125
129
@ NonNull
@@ -150,7 +154,8 @@ public BatchStatement setBatchType(@NonNull BatchType newBatchType) {
150
154
serialConsistencyLevel ,
151
155
timeout ,
152
156
node ,
153
- nowInSeconds );
157
+ nowInSeconds ,
158
+ isLWT );
154
159
}
155
160
156
161
@ NonNull
@@ -175,7 +180,8 @@ public BatchStatement setKeyspace(@Nullable CqlIdentifier newKeyspace) {
175
180
serialConsistencyLevel ,
176
181
timeout ,
177
182
node ,
178
- nowInSeconds );
183
+ nowInSeconds ,
184
+ isLWT );
179
185
}
180
186
181
187
@ NonNull
@@ -204,7 +210,8 @@ public BatchStatement add(@NonNull BatchableStatement<?> statement) {
204
210
serialConsistencyLevel ,
205
211
timeout ,
206
212
node ,
207
- nowInSeconds );
213
+ nowInSeconds ,
214
+ isLWT );
208
215
}
209
216
}
210
217
@@ -237,7 +244,8 @@ public BatchStatement addAll(@NonNull Iterable<? extends BatchableStatement<?>>
237
244
serialConsistencyLevel ,
238
245
timeout ,
239
246
node ,
240
- nowInSeconds );
247
+ nowInSeconds ,
248
+ isLWT );
241
249
}
242
250
}
243
251
@@ -268,7 +276,8 @@ public BatchStatement clear() {
268
276
serialConsistencyLevel ,
269
277
timeout ,
270
278
node ,
271
- nowInSeconds );
279
+ nowInSeconds ,
280
+ isLWT );
272
281
}
273
282
274
283
@ NonNull
@@ -304,7 +313,8 @@ public BatchStatement setPagingState(ByteBuffer newPagingState) {
304
313
serialConsistencyLevel ,
305
314
timeout ,
306
315
node ,
307
- nowInSeconds );
316
+ nowInSeconds ,
317
+ isLWT );
308
318
}
309
319
310
320
@ Override
@@ -334,7 +344,8 @@ public BatchStatement setPageSize(int newPageSize) {
334
344
serialConsistencyLevel ,
335
345
timeout ,
336
346
node ,
337
- nowInSeconds );
347
+ nowInSeconds ,
348
+ isLWT );
338
349
}
339
350
340
351
@ Nullable
@@ -365,7 +376,8 @@ public BatchStatement setConsistencyLevel(@Nullable ConsistencyLevel newConsiste
365
376
serialConsistencyLevel ,
366
377
timeout ,
367
378
node ,
368
- nowInSeconds );
379
+ nowInSeconds ,
380
+ isLWT );
369
381
}
370
382
371
383
@ Nullable
@@ -397,7 +409,8 @@ public BatchStatement setSerialConsistencyLevel(
397
409
newSerialConsistencyLevel ,
398
410
timeout ,
399
411
node ,
400
- nowInSeconds );
412
+ nowInSeconds ,
413
+ isLWT );
401
414
}
402
415
403
416
@ Override
@@ -427,7 +440,8 @@ public BatchStatement setExecutionProfileName(@Nullable String newConfigProfileN
427
440
serialConsistencyLevel ,
428
441
timeout ,
429
442
node ,
430
- nowInSeconds );
443
+ nowInSeconds ,
444
+ isLWT );
431
445
}
432
446
433
447
@ Override
@@ -457,7 +471,8 @@ public DefaultBatchStatement setExecutionProfile(@Nullable DriverExecutionProfil
457
471
serialConsistencyLevel ,
458
472
timeout ,
459
473
node ,
460
- nowInSeconds );
474
+ nowInSeconds ,
475
+ isLWT );
461
476
}
462
477
463
478
@ Override
@@ -522,7 +537,8 @@ public BatchStatement setRoutingKeyspace(CqlIdentifier newRoutingKeyspace) {
522
537
serialConsistencyLevel ,
523
538
timeout ,
524
539
node ,
525
- nowInSeconds );
540
+ nowInSeconds ,
541
+ isLWT );
526
542
}
527
543
528
544
@ NonNull
@@ -547,7 +563,8 @@ public BatchStatement setNode(@Nullable Node newNode) {
547
563
serialConsistencyLevel ,
548
564
timeout ,
549
565
newNode ,
550
- nowInSeconds );
566
+ nowInSeconds ,
567
+ isLWT );
551
568
}
552
569
553
570
@ Nullable
@@ -593,7 +610,8 @@ public BatchStatement setRoutingKey(ByteBuffer newRoutingKey) {
593
610
serialConsistencyLevel ,
594
611
timeout ,
595
612
node ,
596
- nowInSeconds );
613
+ nowInSeconds ,
614
+ isLWT );
597
615
}
598
616
599
617
@ Override
@@ -633,7 +651,8 @@ public BatchStatement setRoutingToken(Token newRoutingToken) {
633
651
serialConsistencyLevel ,
634
652
timeout ,
635
653
node ,
636
- nowInSeconds );
654
+ nowInSeconds ,
655
+ isLWT );
637
656
}
638
657
639
658
@ NonNull
@@ -664,7 +683,8 @@ public DefaultBatchStatement setCustomPayload(@NonNull Map<String, ByteBuffer> n
664
683
serialConsistencyLevel ,
665
684
timeout ,
666
685
node ,
667
- nowInSeconds );
686
+ nowInSeconds ,
687
+ isLWT );
668
688
}
669
689
670
690
@ Override
@@ -700,7 +720,8 @@ public DefaultBatchStatement setIdempotent(Boolean newIdempotence) {
700
720
serialConsistencyLevel ,
701
721
timeout ,
702
722
node ,
703
- nowInSeconds );
723
+ nowInSeconds ,
724
+ isLWT );
704
725
}
705
726
706
727
@ Override
@@ -730,7 +751,8 @@ public BatchStatement setTracing(boolean newTracing) {
730
751
serialConsistencyLevel ,
731
752
timeout ,
732
753
node ,
733
- nowInSeconds );
754
+ nowInSeconds ,
755
+ isLWT );
734
756
}
735
757
736
758
@ Override
@@ -760,7 +782,8 @@ public BatchStatement setQueryTimestamp(long newTimestamp) {
760
782
serialConsistencyLevel ,
761
783
timeout ,
762
784
node ,
763
- nowInSeconds );
785
+ nowInSeconds ,
786
+ isLWT );
764
787
}
765
788
766
789
@ NonNull
@@ -785,7 +808,8 @@ public BatchStatement setTimeout(@Nullable Duration newTimeout) {
785
808
serialConsistencyLevel ,
786
809
newTimeout ,
787
810
node ,
788
- nowInSeconds );
811
+ nowInSeconds ,
812
+ isLWT );
789
813
}
790
814
791
815
@ Override
@@ -815,11 +839,39 @@ public BatchStatement setNowInSeconds(int newNowInSeconds) {
815
839
serialConsistencyLevel ,
816
840
timeout ,
817
841
node ,
818
- newNowInSeconds );
842
+ newNowInSeconds ,
843
+ isLWT );
844
+ }
845
+
846
+ @ NonNull
847
+ @ Override
848
+ public BatchStatement setIsLWT (Boolean newIsLWT ) {
849
+ return new DefaultBatchStatement (
850
+ batchType ,
851
+ statements ,
852
+ executionProfileName ,
853
+ executionProfile ,
854
+ keyspace ,
855
+ routingKeyspace ,
856
+ routingKey ,
857
+ routingToken ,
858
+ customPayload ,
859
+ idempotent ,
860
+ tracing ,
861
+ timestamp ,
862
+ pagingState ,
863
+ pageSize ,
864
+ consistencyLevel ,
865
+ serialConsistencyLevel ,
866
+ timeout ,
867
+ node ,
868
+ nowInSeconds ,
869
+ newIsLWT );
819
870
}
820
871
821
872
@ Override
822
873
public boolean isLWT () {
823
- return false ;
874
+ if (isLWT != null ) return isLWT ;
875
+ return statements .stream ().anyMatch (Statement ::isLWT );
824
876
}
825
877
}
0 commit comments