|
18 | 18 |
|
19 | 19 | import com.google.cloud.Timestamp;
|
20 | 20 | import com.google.cloud.spanner.Options.TransactionOption;
|
| 21 | +import com.google.cloud.spanner.Options.UpdateOption; |
21 | 22 | import com.google.cloud.spanner.SessionPool.PooledSessionFuture;
|
22 | 23 | import com.google.cloud.spanner.SpannerImpl.ClosedException;
|
23 | 24 | import com.google.common.annotations.VisibleForTesting;
|
@@ -54,13 +55,20 @@ PooledSessionFuture getSession() {
|
54 | 55 |
|
55 | 56 | @Override
|
56 | 57 | public Timestamp write(final Iterable<Mutation> mutations) throws SpannerException {
|
| 58 | +return writeWithOptions(mutations).getCommitTimestamp(); |
| 59 | +} |
| 60 | + |
| 61 | +@Override |
| 62 | +public CommitResponse writeWithOptions( |
| 63 | +final Iterable<Mutation> mutations, final TransactionOption... options) |
| 64 | +throws SpannerException { |
57 | 65 | Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
|
58 | 66 | try (Scope s = tracer.withSpan(span)) {
|
59 | 67 | return runWithSessionRetry(
|
60 |
| -new Function<Session, Timestamp>() { |
| 68 | +new Function<Session, CommitResponse>() { |
61 | 69 | @Override
|
62 |
| -public Timestamp apply(Session session) { |
63 |
| -return session.write(mutations); |
| 70 | +public CommitResponse apply(Session session) { |
| 71 | +return session.writeWithOptions(mutations, options); |
64 | 72 | }
|
65 | 73 | });
|
66 | 74 | } catch (RuntimeException e) {
|
@@ -72,21 +80,21 @@ public Timestamp apply(Session session) {
|
72 | 80 | }
|
73 | 81 |
|
74 | 82 | @Override
|
75 |
| -public CommitResponse writeWithOptions(Iterable<Mutation> mutations, TransactionOption... options) |
76 |
| -throws SpannerException { |
77 |
| -final Timestamp commitTimestamp = write(mutations); |
78 |
| -return new CommitResponse(commitTimestamp); |
| 83 | +public Timestamp writeAtLeastOnce(final Iterable<Mutation> mutations) throws SpannerException { |
| 84 | +return writeAtLeastOnceWithOptions(mutations).getCommitTimestamp(); |
79 | 85 | }
|
80 | 86 |
|
81 | 87 | @Override
|
82 |
| -public Timestamp writeAtLeastOnce(final Iterable<Mutation> mutations) throws SpannerException { |
| 88 | +public CommitResponse writeAtLeastOnceWithOptions( |
| 89 | +final Iterable<Mutation> mutations, final TransactionOption... options) |
| 90 | +throws SpannerException { |
83 | 91 | Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
|
84 | 92 | try (Scope s = tracer.withSpan(span)) {
|
85 | 93 | return runWithSessionRetry(
|
86 |
| -new Function<Session, Timestamp>() { |
| 94 | +new Function<Session, CommitResponse>() { |
87 | 95 | @Override
|
88 |
| -public Timestamp apply(Session session) { |
89 |
| -return session.writeAtLeastOnce(mutations); |
| 96 | +public CommitResponse apply(Session session) { |
| 97 | +return session.writeAtLeastOnceWithOptions(mutations, options); |
90 | 98 | }
|
91 | 99 | });
|
92 | 100 | } catch (RuntimeException e) {
|
@@ -97,13 +105,6 @@ public Timestamp apply(Session session) {
|
97 | 105 | }
|
98 | 106 | }
|
99 | 107 |
|
100 |
| -@Override |
101 |
| -public CommitResponse writeAtLeastOnceWithOptions( |
102 |
| -Iterable<Mutation> mutations, TransactionOption... options) throws SpannerException { |
103 |
| -final Timestamp commitTimestamp = writeAtLeastOnce(mutations); |
104 |
| -return new CommitResponse(commitTimestamp); |
105 |
| -} |
106 |
| - |
107 | 108 | @Override
|
108 | 109 | public ReadContext singleUse() {
|
109 | 110 | Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
|
@@ -171,10 +172,10 @@ public ReadOnlyTransaction readOnlyTransaction(TimestampBound bound) {
|
171 | 172 | }
|
172 | 173 |
|
173 | 174 | @Override
|
174 |
| -public TransactionRunner readWriteTransaction() { |
| 175 | +public TransactionRunner readWriteTransaction(TransactionOption... options) { |
175 | 176 | Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
|
176 | 177 | try (Scope s = tracer.withSpan(span)) {
|
177 |
| -return getSession().readWriteTransaction(); |
| 178 | +return getSession().readWriteTransaction(options); |
178 | 179 | } catch (RuntimeException e) {
|
179 | 180 | TraceUtil.endSpanWithFailure(span, e);
|
180 | 181 | throw e;
|
@@ -184,47 +185,47 @@ public TransactionRunner readWriteTransaction() {
|
184 | 185 | }
|
185 | 186 |
|
186 | 187 | @Override
|
187 |
| -public TransactionManager transactionManager() { |
| 188 | +public TransactionManager transactionManager(TransactionOption... options) { |
188 | 189 | Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
|
189 | 190 | try (Scope s = tracer.withSpan(span)) {
|
190 |
| -return getSession().transactionManager(); |
| 191 | +return getSession().transactionManager(options); |
191 | 192 | } catch (RuntimeException e) {
|
192 | 193 | TraceUtil.endSpanWithFailure(span, e);
|
193 | 194 | throw e;
|
194 | 195 | }
|
195 | 196 | }
|
196 | 197 |
|
197 | 198 | @Override
|
198 |
| -public AsyncRunner runAsync() { |
| 199 | +public AsyncRunner runAsync(TransactionOption... options) { |
199 | 200 | Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
|
200 | 201 | try (Scope s = tracer.withSpan(span)) {
|
201 |
| -return getSession().runAsync(); |
| 202 | +return getSession().runAsync(options); |
202 | 203 | } catch (RuntimeException e) {
|
203 | 204 | TraceUtil.endSpanWithFailure(span, e);
|
204 | 205 | throw e;
|
205 | 206 | }
|
206 | 207 | }
|
207 | 208 |
|
208 | 209 | @Override
|
209 |
| -public AsyncTransactionManager transactionManagerAsync() { |
| 210 | +public AsyncTransactionManager transactionManagerAsync(TransactionOption... options) { |
210 | 211 | Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
|
211 | 212 | try (Scope s = tracer.withSpan(span)) {
|
212 |
| -return getSession().transactionManagerAsync(); |
| 213 | +return getSession().transactionManagerAsync(options); |
213 | 214 | } catch (RuntimeException e) {
|
214 | 215 | TraceUtil.endSpanWithFailure(span, e);
|
215 | 216 | throw e;
|
216 | 217 | }
|
217 | 218 | }
|
218 | 219 |
|
219 | 220 | @Override
|
220 |
| -public long executePartitionedUpdate(final Statement stmt) { |
| 221 | +public long executePartitionedUpdate(final Statement stmt, final UpdateOption... options) { |
221 | 222 | Span span = tracer.spanBuilder(PARTITION_DML_TRANSACTION).startSpan();
|
222 | 223 | try (Scope s = tracer.withSpan(span)) {
|
223 | 224 | return runWithSessionRetry(
|
224 | 225 | new Function<Session, Long>() {
|
225 | 226 | @Override
|
226 | 227 | public Long apply(Session session) {
|
227 |
| -return session.executePartitionedUpdate(stmt); |
| 228 | +return session.executePartitionedUpdate(stmt, options); |
228 | 229 | }
|
229 | 230 | });
|
230 | 231 | } catch (RuntimeException e) {
|
|
0 commit comments