|
17 | 17 | package com.example.spanner; |
18 | 18 |
|
19 | 19 | //[START spanner_set_custom_timeout_and_retry] |
| 20 | + |
20 | 21 | import com.google.api.gax.retrying.RetrySettings; |
21 | 22 | import com.google.api.gax.rpc.StatusCode.Code; |
22 | 23 | import com.google.cloud.spanner.DatabaseClient; |
23 | 24 | import com.google.cloud.spanner.DatabaseId; |
24 | 25 | import com.google.cloud.spanner.Spanner; |
25 | 26 | import com.google.cloud.spanner.SpannerOptions; |
26 | 27 | import com.google.cloud.spanner.Statement; |
27 | | -import com.google.cloud.spanner.TransactionContext; |
28 | | -import com.google.cloud.spanner.TransactionRunner.TransactionCallable; |
29 | 28 | import org.threeten.bp.Duration; |
30 | 29 |
|
31 | 30 | class CustomTimeoutAndRetrySettingsExample { |
@@ -70,18 +69,14 @@ static void executeSqlWithCustomTimeoutAndRetrySettings( |
70 | 69 | spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId)); |
71 | 70 | client |
72 | 71 | .readWriteTransaction() |
73 | | - .run( |
74 | | - new TransactionCallable<Void>() { |
75 | | - @Override |
76 | | - public Void run(TransactionContext transaction) throws Exception { |
77 | | - String sql = |
78 | | - "INSERT Singers (SingerId, FirstName, LastName)\n" |
79 | | - + "VALUES (20, 'George', 'Washington')"; |
80 | | - long rowCount = transaction.executeUpdate(Statement.of(sql)); |
81 | | - System.out.printf("%d record inserted.%n", rowCount); |
82 | | - return null; |
83 | | - } |
84 | | - }); |
| 72 | + .run(transaction -> { |
| 73 | + String sql = |
| 74 | + "INSERT Singers (SingerId, FirstName, LastName)\n" |
| 75 | + + "VALUES (20, 'George', 'Washington')"; |
| 76 | + long rowCount = transaction.executeUpdate(Statement.of(sql)); |
| 77 | + System.out.printf("%d record inserted.%n", rowCount); |
| 78 | + return null; |
| 79 | + }); |
85 | 80 | } |
86 | 81 | } |
87 | 82 | } |
|
0 commit comments