4343import java .util .Iterator ;
4444import java .util .List ;
4545import java .util .Map ;
46+ import java .util .Objects ;
4647import net .jcip .annotations .Immutable ;
4748import org .slf4j .Logger ;
4849import org .slf4j .LoggerFactory ;
@@ -70,7 +71,7 @@ public class DefaultBatchStatement implements BatchStatement {
7071 private final Duration timeout ;
7172 private final Node node ;
7273 private final int nowInSeconds ;
73- @ NonNull private final RequestRoutingType routingType ;
74+ private final Boolean isExplicitLWTSet ;
7475
7576 public DefaultBatchStatement (
7677 BatchType batchType ,
@@ -92,7 +93,7 @@ public DefaultBatchStatement(
9293 Duration timeout ,
9394 Node node ,
9495 int nowInSeconds ,
95- @ NonNull RequestRoutingType routingType ) {
96+ Boolean isExplicitLWTSet ) {
9697 for (BatchableStatement <?> statement : statements ) {
9798 if (statement != null
9899 && (statement .getConsistencyLevel () != null
@@ -124,7 +125,7 @@ public DefaultBatchStatement(
124125 this .timeout = timeout ;
125126 this .node = node ;
126127 this .nowInSeconds = nowInSeconds ;
127- this .routingType = routingType ;
128+ this .isExplicitLWTSet = isExplicitLWTSet ;
128129 }
129130
130131 @ NonNull
@@ -156,7 +157,7 @@ public BatchStatement setBatchType(@NonNull BatchType newBatchType) {
156157 timeout ,
157158 node ,
158159 nowInSeconds ,
159- routingType );
160+ isExplicitLWTSet );
160161 }
161162
162163 @ NonNull
@@ -182,7 +183,7 @@ public BatchStatement setKeyspace(@Nullable CqlIdentifier newKeyspace) {
182183 timeout ,
183184 node ,
184185 nowInSeconds ,
185- routingType );
186+ isExplicitLWTSet );
186187 }
187188
188189 @ NonNull
@@ -212,7 +213,7 @@ public BatchStatement add(@NonNull BatchableStatement<?> statement) {
212213 timeout ,
213214 node ,
214215 nowInSeconds ,
215- routingType );
216+ isExplicitLWTSet );
216217 }
217218 }
218219
@@ -246,7 +247,7 @@ public BatchStatement addAll(@NonNull Iterable<? extends BatchableStatement<?>>
246247 timeout ,
247248 node ,
248249 nowInSeconds ,
249- routingType );
250+ isExplicitLWTSet );
250251 }
251252 }
252253
@@ -278,7 +279,7 @@ public BatchStatement clear() {
278279 timeout ,
279280 node ,
280281 nowInSeconds ,
281- routingType );
282+ isExplicitLWTSet );
282283 }
283284
284285 @ NonNull
@@ -315,7 +316,7 @@ public BatchStatement setPagingState(ByteBuffer newPagingState) {
315316 timeout ,
316317 node ,
317318 nowInSeconds ,
318- routingType );
319+ isExplicitLWTSet );
319320 }
320321
321322 @ Override
@@ -346,7 +347,7 @@ public BatchStatement setPageSize(int newPageSize) {
346347 timeout ,
347348 node ,
348349 nowInSeconds ,
349- routingType );
350+ isExplicitLWTSet );
350351 }
351352
352353 @ Nullable
@@ -378,7 +379,7 @@ public BatchStatement setConsistencyLevel(@Nullable ConsistencyLevel newConsiste
378379 timeout ,
379380 node ,
380381 nowInSeconds ,
381- routingType );
382+ isExplicitLWTSet );
382383 }
383384
384385 @ Nullable
@@ -411,7 +412,7 @@ public BatchStatement setSerialConsistencyLevel(
411412 timeout ,
412413 node ,
413414 nowInSeconds ,
414- routingType );
415+ isExplicitLWTSet );
415416 }
416417
417418 @ Override
@@ -442,7 +443,7 @@ public BatchStatement setExecutionProfileName(@Nullable String newConfigProfileN
442443 timeout ,
443444 node ,
444445 nowInSeconds ,
445- routingType );
446+ isExplicitLWTSet );
446447 }
447448
448449 @ Override
@@ -473,7 +474,7 @@ public DefaultBatchStatement setExecutionProfile(@Nullable DriverExecutionProfil
473474 timeout ,
474475 node ,
475476 nowInSeconds ,
476- routingType );
477+ isExplicitLWTSet );
477478 }
478479
479480 @ Override
@@ -539,7 +540,7 @@ public BatchStatement setRoutingKeyspace(CqlIdentifier newRoutingKeyspace) {
539540 timeout ,
540541 node ,
541542 nowInSeconds ,
542- routingType );
543+ isExplicitLWTSet );
543544 }
544545
545546 @ NonNull
@@ -565,7 +566,7 @@ public BatchStatement setNode(@Nullable Node newNode) {
565566 timeout ,
566567 newNode ,
567568 nowInSeconds ,
568- routingType );
569+ isExplicitLWTSet );
569570 }
570571
571572 @ Nullable
@@ -612,7 +613,7 @@ public BatchStatement setRoutingKey(ByteBuffer newRoutingKey) {
612613 timeout ,
613614 node ,
614615 nowInSeconds ,
615- routingType );
616+ isExplicitLWTSet );
616617 }
617618
618619 @ Override
@@ -653,7 +654,7 @@ public BatchStatement setRoutingToken(Token newRoutingToken) {
653654 timeout ,
654655 node ,
655656 nowInSeconds ,
656- routingType );
657+ isExplicitLWTSet );
657658 }
658659
659660 @ NonNull
@@ -685,7 +686,7 @@ public DefaultBatchStatement setCustomPayload(@NonNull Map<String, ByteBuffer> n
685686 timeout ,
686687 node ,
687688 nowInSeconds ,
688- routingType );
689+ isExplicitLWTSet );
689690 }
690691
691692 @ Override
@@ -722,7 +723,7 @@ public DefaultBatchStatement setIdempotent(Boolean newIdempotence) {
722723 timeout ,
723724 node ,
724725 nowInSeconds ,
725- routingType );
726+ isExplicitLWTSet );
726727 }
727728
728729 @ Override
@@ -753,7 +754,7 @@ public BatchStatement setTracing(boolean newTracing) {
753754 timeout ,
754755 node ,
755756 nowInSeconds ,
756- routingType );
757+ isExplicitLWTSet );
757758 }
758759
759760 @ Override
@@ -784,7 +785,7 @@ public BatchStatement setQueryTimestamp(long newTimestamp) {
784785 timeout ,
785786 node ,
786787 nowInSeconds ,
787- routingType );
788+ isExplicitLWTSet );
788789 }
789790
790791 @ NonNull
@@ -810,7 +811,7 @@ public BatchStatement setTimeout(@Nullable Duration newTimeout) {
810811 newTimeout ,
811812 node ,
812813 nowInSeconds ,
813- routingType );
814+ isExplicitLWTSet );
814815 }
815816
816817 @ Override
@@ -841,18 +842,17 @@ public BatchStatement setNowInSeconds(int newNowInSeconds) {
841842 timeout ,
842843 node ,
843844 newNowInSeconds ,
844- routingType );
845+ isExplicitLWTSet );
845846 }
846847
847848 @ NonNull
848- @ Override
849- public RequestRoutingType getRequestRoutingType () {
850- return routingType ;
849+ public Boolean getIsExplicitLWTSet () {
850+ return isExplicitLWTSet ;
851851 }
852852
853853 @ NonNull
854854 @ Override
855- public BatchStatement setRequestRoutingType ( RequestRoutingType requestRoutingType ) {
855+ public BatchStatement setIsLWT ( Boolean newIsLWT ) {
856856 return new DefaultBatchStatement (
857857 batchType ,
858858 statements ,
@@ -873,40 +873,18 @@ public BatchStatement setRequestRoutingType(RequestRoutingType requestRoutingTyp
873873 timeout ,
874874 node ,
875875 nowInSeconds ,
876- requestRoutingType );
876+ newIsLWT );
877877 }
878878
879879 @ NonNull
880880 @ Override
881- public BatchStatement setIsLWT (Boolean newIsLWT ) {
882- RequestRoutingType routingType =
883- newIsLWT != null ? (newIsLWT ? RequestRoutingType .LWT : RequestRoutingType .REGULAR ) : null ;
884- return new DefaultBatchStatement (
885- batchType ,
886- statements ,
887- executionProfileName ,
888- executionProfile ,
889- keyspace ,
890- routingKeyspace ,
891- routingKey ,
892- routingToken ,
893- customPayload ,
894- idempotent ,
895- tracing ,
896- timestamp ,
897- pagingState ,
898- pageSize ,
899- consistencyLevel ,
900- serialConsistencyLevel ,
901- timeout ,
902- node ,
903- nowInSeconds ,
904- routingType );
881+ public RequestRoutingType getRequestRoutingType () {
882+ return isLWT () ? RequestRoutingType .LWT : RequestRoutingType .REGULAR ;
905883 }
906884
907885 @ Override
908886 public boolean isLWT () {
909- if (routingType != null ) return routingType == RequestRoutingType . LWT ;
887+ if (Objects . nonNull ( isExplicitLWTSet )) return isExplicitLWTSet ;
910888 return statements .stream ().anyMatch (Statement ::isLWT );
911889 }
912890}
0 commit comments