16
16
17
17
package com .example .spanner ;
18
18
19
+ import com .google .api .gax .rpc .ServerStream ;
19
20
import com .google .cloud .spanner .CommitResponse ;
20
21
import com .google .cloud .spanner .DatabaseClient ;
21
22
import com .google .cloud .spanner .DatabaseId ;
22
23
import com .google .cloud .spanner .Mutation ;
24
+ import com .google .cloud .spanner .MutationGroup ;
23
25
import com .google .cloud .spanner .Options ;
24
26
import com .google .cloud .spanner .Spanner ;
25
27
import com .google .cloud .spanner .SpannerOptions ;
26
28
import com .google .cloud .spanner .Statement ;
27
29
import com .google .cloud .spanner .TransactionContext ;
28
30
import com .google .cloud .spanner .TransactionManager ;
29
- import java .util .Collections ;
30
- import com .google .spanner .v1 .BatchWriteResponse ;
31
- import com .google .api .gax .rpc .ServerStream ;
32
- import com .google .rpc .Code ;
33
- import com .google .cloud .spanner .MutationGroup ;
34
31
import com .google .common .collect .ImmutableList ;
32
+ import com .google .rpc .Code ;
33
+ import com .google .spanner .v1 .BatchWriteResponse ;
34
+ import java .util .Collections ;
35
35
36
- /** Sample showing how to set exclude transaction from change streams in different write requests. */
36
+ /**
37
+ * Sample showing how to set exclude transaction from change streams in different write requests.
38
+ */
37
39
public class ChangeStreamsTxnExclusionSample {
38
40
39
41
static void setExcludeTxnFromChangeStreams () {
@@ -107,15 +109,16 @@ static void writeAtLeastOnceExcludedFromChangeStreams(DatabaseClient client) {
107
109
static void batchWriteAtLeastOnceExcludedFromChangeStreams (DatabaseClient client ) {
108
110
ServerStream <BatchWriteResponse > responses =
109
111
client .batchWriteAtLeastOnce (
110
- ImmutableList .of (MutationGroup .of (
111
- Mutation .newInsertOrUpdateBuilder ("Singers" )
112
- .set ("SingerId" )
113
- .to (116 )
114
- .set ("FirstName" )
115
- .to ("Scarlet" )
116
- .set ("LastName" )
117
- .to ("Terry" )
118
- .build ())),
112
+ ImmutableList .of (
113
+ MutationGroup .of (
114
+ Mutation .newInsertOrUpdateBuilder ("Singers" )
115
+ .set ("SingerId" )
116
+ .to (116 )
117
+ .set ("FirstName" )
118
+ .to ("Scarlet" )
119
+ .set ("LastName" )
120
+ .to ("Terry" )
121
+ .build ())),
119
122
Options .excludeTxnFromChangeStreams ());
120
123
for (BatchWriteResponse response : responses ) {
121
124
if (response .getStatus ().getCode () == Code .OK_VALUE ) {
@@ -124,9 +127,10 @@ static void batchWriteAtLeastOnceExcludedFromChangeStreams(DatabaseClient client
124
127
response .getIndexesList (), response .getCommitTimestamp ());
125
128
} else {
126
129
System .out .printf (
127
- "Mutation group could not be applied with error code %s and "
128
- + "error message %s" , response .getIndexesList (),
129
- Code .forNumber (response .getStatus ().getCode ()), response .getStatus ().getMessage ());
130
+ "Mutation group could not be applied with error code %s and " + "error message %s" ,
131
+ response .getIndexesList (),
132
+ Code .forNumber (response .getStatus ().getCode ()),
133
+ response .getStatus ().getMessage ());
130
134
}
131
135
}
132
136
}
@@ -138,7 +142,8 @@ static void pdmlExcludedFromChangeStreams(DatabaseClient client) {
138
142
}
139
143
140
144
static void txnManagerExcludedFromChangeStreams (DatabaseClient client ) {
141
- try (TransactionManager manager = client .transactionManager (Options .excludeTxnFromChangeStreams ())) {
145
+ try (TransactionManager manager =
146
+ client .transactionManager (Options .excludeTxnFromChangeStreams ())) {
142
147
TransactionContext transaction = manager .begin ();
143
148
transaction .buffer (
144
149
Mutation .newInsertOrUpdateBuilder ("Singers" )
0 commit comments