Skip to content

Commit fbf8715

Browse files
nithinsujirpongad
authored andcommitted
Clean up snippets for BatchClient and Spanner (#3684)
* Clean up snippets for BatchClient and Spanner * Remove trivial batch_client_read_with_id snippet
1 parent 3fa1fa0 commit fbf8715

File tree

5 files changed

+20
-43
lines changed

5 files changed

+20
-43
lines changed

google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClient.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ public interface BatchClient {
5959
* @param batchTransactionId to re-initialize the transaction, re-using the timestamp for
6060
* successive read/query.
6161
*
62-
* <!--SNIPPET batch_client_read_with_id-->
63-
* <pre>{@code
64-
* BatchTransactionId txnId = my_txn.getBatchTransactionId();
65-
* BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
66-
* }</pre>
67-
* <!--SNIPPET batch_client_read_with_id-->
6862
*/
6963
BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batchTransactionId);
7064
}

google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchReadOnlyTransaction.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public interface BatchReadOnlyTransaction extends ReadOnlyTransaction {
7171
* long singerId = results.getLong(0);
7272
* String firstName = results.getString(1);
7373
* String lastName = results.getString(2);
74-
* System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
74+
* System.out.println("[" + singerId + "] " + firstName + " " + lastName);
7575
* }
7676
* }
7777
* }
@@ -110,14 +110,15 @@ List<Partition> partitionRead(
110110
* "Singers",
111111
* "SingerId",
112112
* KeySet.all(),
113-
* Arrays.asList("FirstName"));
114-
* BatchTransactionId txnID = txn.getBatchTransactionId();
115-
* int numRowsRead = 0;
113+
* Arrays.asList("SingerId", "FirstName", "LastName"));
114+
*
116115
* for (Partition p : partitions) {
117-
* BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
118-
* try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
116+
* try (ResultSet results = txn.execute(p)) {
119117
* while (results.next()) {
120-
* System.out.println(results.getString(0));
118+
* long singerId = results.getLong(0);
119+
* String firstName = results.getString(1);
120+
* String lastName = results.getString(2);
121+
* System.out.println("[" + singerId + "] " + firstName + " " + lastName);
121122
* }
122123
* }
123124
* }
@@ -198,13 +199,6 @@ List<Partition> partitionQuery(
198199
* Returns a {@link BatchTransactionId} to be re-used across several machines/processes. This
199200
* BatchTransactionId guarantees the subsequent read/query to be executed at the same timestamp.
200201
*
201-
* <!--SNIPPET batch_client_read_with_id-->
202-
* <pre>{@code
203-
* BatchTransactionId txnId = my_txn.getBatchTransactionId();
204-
* BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
205-
* }</pre>
206-
* <!--SNIPPET batch_client_read_with_id-->
207-
*
208202
*/
209203
BatchTransactionId getBatchTransactionId();
210204
}

google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Spanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public interface Spanner extends Service<SpannerOptions> {
6161
* final String instance = "test-instance";
6262
* final String database = "example-db";
6363
* DatabaseId db =
64-
* DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
64+
* DatabaseId.of(project, instance, database);
6565
* DatabaseClient dbClient = spanner.getDatabaseClient(db);
6666
* }</pre>
6767
* <!--SNIPPET get_db_client-->
@@ -85,7 +85,7 @@ public interface Spanner extends Service<SpannerOptions> {
8585
* final String instance = "test-instance";
8686
* final String database = "example-db";
8787
* DatabaseId db =
88-
* DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
88+
* DatabaseId.of(project, instance, database);
8989
* BatchClient batchClient = spanner.getBatchClient(db);
9090
* }</pre>
9191
* <!--SNIPPET get_batch_client-->

google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/BatchClientSnippets.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ BatchReadOnlyTransaction readStrong() {
5555
return txn;
5656
}
5757

58-
/**
59-
* Example to do a batch read with txn id.
60-
*/
61-
BatchReadOnlyTransaction readWithId(BatchReadOnlyTransaction my_txn) {
62-
// [START batch_client_read_with_id]
63-
BatchTransactionId txnId = my_txn.getBatchTransactionId();
64-
BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
65-
// [END batch_client_read_with_id]
66-
67-
return txn;
68-
}
69-
7058
void partitionQuery() {
7159
// [START partition_query]
7260
final BatchReadOnlyTransaction txn =
@@ -104,7 +92,7 @@ void partitionRead() {
10492
long singerId = results.getLong(0);
10593
String firstName = results.getString(1);
10694
String lastName = results.getString(2);
107-
System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
95+
System.out.println("[" + singerId + "] " + firstName + " " + lastName);
10896
}
10997
}
11098
}
@@ -121,14 +109,15 @@ void partitionReadUsingIndex() {
121109
"Singers",
122110
"SingerId",
123111
KeySet.all(),
124-
Arrays.asList("FirstName"));
125-
BatchTransactionId txnID = txn.getBatchTransactionId();
126-
int numRowsRead = 0;
112+
Arrays.asList("SingerId", "FirstName", "LastName"));
113+
127114
for (Partition p : partitions) {
128-
BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
129-
try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
115+
try (ResultSet results = txn.execute(p)) {
130116
while (results.next()) {
131-
System.out.println(results.getString(0));
117+
long singerId = results.getLong(0);
118+
String firstName = results.getString(1);
119+
String lastName = results.getString(2);
120+
System.out.println("[" + singerId + "] " + firstName + " " + lastName);
132121
}
133122
}
134123
}

google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/SpannerSnippets.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ DatabaseClient getDatabaseClient() {
5353
final String instance = "test-instance";
5454
final String database = "example-db";
5555
DatabaseId db =
56-
DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
56+
DatabaseId.of(project, instance, database);
5757
DatabaseClient dbClient = spanner.getDatabaseClient(db);
5858
// [END get_db_client]
5959

@@ -78,7 +78,7 @@ BatchClient getBatchClient() {
7878
final String instance = "test-instance";
7979
final String database = "example-db";
8080
DatabaseId db =
81-
DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
81+
DatabaseId.of(project, instance, database);
8282
BatchClient batchClient = spanner.getBatchClient(db);
8383
// [END get_batch_client]
8484

0 commit comments

Comments
 (0)