@@ -108,6 +108,9 @@ public interface ReadQueryUpdateTransactionOption
108
108
/** Marker interface to mark options applicable to Update and Write operations */
109
109
public interface UpdateTransactionOption extends UpdateOption , TransactionOption {}
110
110
111
+ /** Marker interface for options that can be used with both executeQuery and executeUpdate. */
112
+ public interface QueryUpdateOption extends QueryOption , UpdateOption {}
113
+
111
114
/**
112
115
* Marker interface to mark options applicable to Create, Update and Delete operations in admin
113
116
* API.
@@ -236,6 +239,20 @@ public static DataBoostQueryOption dataBoostEnabled(Boolean dataBoostEnabled) {
236
239
return new DataBoostQueryOption (dataBoostEnabled );
237
240
}
238
241
242
+ /**
243
+ * If set to true, this option marks the end of the transaction. The transaction should be
244
+ * committed or aborted after this statement executes, and attempts to execute any other requests
245
+ * against this transaction (including reads and queries) will be rejected. Mixing mutations with
246
+ * statements that are marked as the last statement is not allowed.
247
+ *
248
+ * <p>For DML statements, setting this option may cause some error reporting to be deferred until
249
+ * commit time (e.g. validation of unique constraints). Given this, successful execution of a DML
250
+ * statement should not be assumed until the transaction commits.
251
+ */
252
+ public static QueryUpdateOption lastStatement () {
253
+ return new LastStatementUpdateOption ();
254
+ }
255
+
239
256
/**
240
257
* Specifying this will cause the list operation to start fetching the record from this onwards.
241
258
*/
@@ -494,6 +511,7 @@ void appendToOptions(Options options) {
494
511
private DecodeMode decodeMode ;
495
512
private RpcOrderBy orderBy ;
496
513
private RpcLockHint lockHint ;
514
+ private Boolean lastStatement ;
497
515
498
516
// Construction is via factory methods below.
499
517
private Options () {}
@@ -630,6 +648,14 @@ OrderBy orderBy() {
630
648
return orderBy == null ? null : orderBy .proto ;
631
649
}
632
650
651
+ boolean hasLastStatement () {
652
+ return lastStatement != null ;
653
+ }
654
+
655
+ Boolean isLastStatement () {
656
+ return lastStatement ;
657
+ }
658
+
633
659
boolean hasLockHint () {
634
660
return lockHint != null ;
635
661
}
@@ -694,6 +720,9 @@ public String toString() {
694
720
if (orderBy != null ) {
695
721
b .append ("orderBy: " ).append (orderBy ).append (' ' );
696
722
}
723
+ if (lastStatement != null ) {
724
+ b .append ("lastStatement: " ).append (lastStatement ).append (' ' );
725
+ }
697
726
if (lockHint != null ) {
698
727
b .append ("lockHint: " ).append (lockHint ).append (' ' );
699
728
}
@@ -737,6 +766,7 @@ public boolean equals(Object o) {
737
766
&& Objects .equals (dataBoostEnabled (), that .dataBoostEnabled ())
738
767
&& Objects .equals (directedReadOptions (), that .directedReadOptions ())
739
768
&& Objects .equals (orderBy (), that .orderBy ())
769
+ && Objects .equals (isLastStatement (), that .isLastStatement ())
740
770
&& Objects .equals (lockHint (), that .lockHint ());
741
771
}
742
772
@@ -797,6 +827,9 @@ public int hashCode() {
797
827
if (orderBy != null ) {
798
828
result = 31 * result + orderBy .hashCode ();
799
829
}
830
+ if (lastStatement != null ) {
831
+ result = 31 * result + lastStatement .hashCode ();
832
+ }
800
833
if (lockHint != null ) {
801
834
result = 31 * result + lockHint .hashCode ();
802
835
}
@@ -965,4 +998,24 @@ public boolean equals(Object o) {
965
998
return Objects .equals (filter , ((FilterOption ) o ).filter );
966
999
}
967
1000
}
1001
+
1002
+ static final class LastStatementUpdateOption extends InternalOption implements QueryUpdateOption {
1003
+
1004
+ LastStatementUpdateOption () {}
1005
+
1006
+ @ Override
1007
+ void appendToOptions (Options options ) {
1008
+ options .lastStatement = true ;
1009
+ }
1010
+
1011
+ @ Override
1012
+ public int hashCode () {
1013
+ return LastStatementUpdateOption .class .hashCode ();
1014
+ }
1015
+
1016
+ @ Override
1017
+ public boolean equals (Object o ) {
1018
+ return o instanceof LastStatementUpdateOption ;
1019
+ }
1020
+ }
968
1021
}
0 commit comments