FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update writeWithTransactionUsingDml for quickstart · jsimonweb/java-docs-samples@8de0b8b · GitHub

Commit 8de0b8b

Browse files
committed
Update writeWithTransactionUsingDml for quickstart
1 parent 63728b3 commit 8de0b8b

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,26 +1047,26 @@ public Void run(TransactionContext transaction) throws Exception {
10471047
// Transfer marketing budget from one album to another. We do it in a transaction to
10481048
// ensure that the transfer is atomic.
10491049
String sql1 =
1050-
"SELECT MarketingBudget from Albums WHERE SingerId = 1 and AlbumId = 1";
1050+
"SELECT MarketingBudget from Albums WHERE SingerId = 2 and AlbumId = 2";
10511051
ResultSet resultSet = transaction.executeQuery(Statement.of(sql1));
1052-
long album1Budget = 0;
1052+
long album2Budget = 0;
10531053
while (resultSet.next()) {
1054-
album1Budget = resultSet.getLong("MarketingBudget");
1054+
album2Budget = resultSet.getLong("MarketingBudget");
10551055
}
10561056
// Transaction will only be committed if this condition still holds at the time of
10571057
// commit. Otherwise it will be aborted and the callable will be rerun by the
10581058
// client library.
1059-
if (album1Budget >= 300000) {
1059+
if (album2Budget >= 300000) {
10601060
String sql2 =
1061-
"SELECT MarketingBudget from Albums WHERE SingerId = 2 and AlbumId = 2";
1061+
"SELECT MarketingBudget from Albums WHERE SingerId = 1 and AlbumId = 1";
10621062
ResultSet resultSet2 = transaction.executeQuery(Statement.of(sql2));
1063-
long album2Budget = 0;
1064-
while (resultSet.next()) {
1065-
album2Budget = resultSet2.getLong("MarketingBudget");
1063+
long album1Budget = 0;
1064+
while (resultSet2.next()) {
1065+
album1Budget = resultSet2.getLong("MarketingBudget");
10661066
}
10671067
long transfer = 200000;
1068-
album2Budget += transfer;
1069-
album1Budget -= transfer;
1068+
album2Budget -= transfer;
1069+
album1Budget += transfer;
10701070
Statement updateStatement =
10711071
Statement.newBuilder(
10721072
"UPDATE Albums "

‎spanner/cloud-client/src/test/java/com/example/spanner/SpannerSampleIT.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ public void testSample() throws Exception {
186186

187187
runSample("writewithtransactionusingdml");
188188
out = runSample("querymarketingbudget");
189-
assertThat(out).contains("1 1 1800000");
190-
assertThat(out).contains("2 2 200000");
189+
assertThat(out).contains("1 1 2200000");
190+
assertThat(out).contains("2 2 550000");
191191

192192
runSample("updateusingpartitioneddml");
193193
out = runSample("querymarketingbudget");
194-
assertThat(out).contains("1 1 1800000");
194+
assertThat(out).contains("1 1 2200000");
195195
assertThat(out).contains("2 2 100000");
196196

197197
runSample("deleteusingpartitioneddml");

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL