|
16 | 16 |
|
17 | 17 | package com.example.spanner;
|
18 | 18 |
|
19 |
| -import com.google.api.gax.rpc.ServerStream; |
20 |
| -import com.google.cloud.spanner.CommitResponse; |
21 | 19 | import com.google.cloud.spanner.DatabaseClient;
|
22 | 20 | import com.google.cloud.spanner.DatabaseId;
|
23 |
| -import com.google.cloud.spanner.Mutation; |
24 |
| -import com.google.cloud.spanner.MutationGroup; |
25 | 21 | import com.google.cloud.spanner.Options;
|
26 | 22 | import com.google.cloud.spanner.Spanner;
|
27 | 23 | import com.google.cloud.spanner.SpannerOptions;
|
28 | 24 | import com.google.cloud.spanner.Statement;
|
29 |
| -import com.google.cloud.spanner.TransactionContext; |
30 |
| -import com.google.cloud.spanner.TransactionManager; |
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 | 25 |
|
36 | 26 | /**
|
37 | 27 | * Sample showing how to set exclude transaction from change streams in different write requests.
|
@@ -73,92 +63,6 @@ static void rwTxnExcludedFromChangeStreams(DatabaseClient client) {
|
73 | 63 | return null;
|
74 | 64 | });
|
75 | 65 | }
|
76 |
| - |
77 |
| - static void writeExcludedFromChangeStreams(DatabaseClient client) { |
78 |
| - CommitResponse response = |
79 |
| - client.writeWithOptions( |
80 |
| - Collections.singletonList( |
81 |
| - Mutation.newInsertOrUpdateBuilder("Singers") |
82 |
| - .set("SingerId") |
83 |
| - .to(4520) |
84 |
| - .set("FirstName") |
85 |
| - .to("Lauren") |
86 |
| - .set("LastName") |
87 |
| - .to("Lee") |
88 |
| - .build()), |
89 |
| - Options.excludeTxnFromChangeStreams()); |
90 |
| - System.out.println("New singer inserted."); |
91 |
| - } |
92 |
| - |
93 |
| - static void writeAtLeastOnceExcludedFromChangeStreams(DatabaseClient client) { |
94 |
| - CommitResponse response = |
95 |
| - client.writeAtLeastOnceWithOptions( |
96 |
| - Collections.singletonList( |
97 |
| - Mutation.newInsertOrUpdateBuilder("Singers") |
98 |
| - .set("SingerId") |
99 |
| - .to(45201) |
100 |
| - .set("FirstName") |
101 |
| - .to("Laura") |
102 |
| - .set("LastName") |
103 |
| - .to("Johnson") |
104 |
| - .build()), |
105 |
| - Options.excludeTxnFromChangeStreams()); |
106 |
| - System.out.println("New singer inserted."); |
107 |
| - } |
108 |
| - |
109 |
| - static void batchWriteAtLeastOnceExcludedFromChangeStreams(DatabaseClient client) { |
110 |
| - ServerStream<BatchWriteResponse> responses = |
111 |
| - client.batchWriteAtLeastOnce( |
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())), |
122 |
| - Options.excludeTxnFromChangeStreams()); |
123 |
| - for (BatchWriteResponse response : responses) { |
124 |
| - if (response.getStatus().getCode() == Code.OK_VALUE) { |
125 |
| - System.out.printf( |
126 |
| - "Mutation group have been applied with commit timestamp %s", |
127 |
| - response.getIndexesList(), response.getCommitTimestamp()); |
128 |
| - } else { |
129 |
| - System.out.printf( |
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()); |
134 |
| - } |
135 |
| - } |
136 |
| - } |
137 |
| - |
138 |
| - static void pdmlExcludedFromChangeStreams(DatabaseClient client) { |
139 |
| - client.executePartitionedUpdate( |
140 |
| - Statement.of("DELETE FROM Singers WHERE TRUE"), Options.excludeTxnFromChangeStreams()); |
141 |
| - System.out.println("Singers deleted."); |
142 |
| - } |
143 |
| - |
144 |
| - static void txnManagerExcludedFromChangeStreams(DatabaseClient client) { |
145 |
| - try (TransactionManager manager = |
146 |
| - client.transactionManager(Options.excludeTxnFromChangeStreams())) { |
147 |
| - TransactionContext transaction = manager.begin(); |
148 |
| - transaction.buffer( |
149 |
| - Mutation.newInsertOrUpdateBuilder("Singers") |
150 |
| - .set("SingerId") |
151 |
| - .to(888) |
152 |
| - .set("FirstName") |
153 |
| - .to("Johnson") |
154 |
| - .set("LastName") |
155 |
| - .to("Doug") |
156 |
| - .build()); |
157 |
| - manager.commit(); |
158 |
| - System.out.println("New singer inserted."); |
159 |
| - } |
160 |
| - } |
161 |
| - |
162 | 66 | // [END spanner_set_exclude_txn_from_change_streams]
|
163 | 67 |
|
164 | 68 | }
|
0 commit comments