From fbf87155296322786c7443cbb453ead7a06d6801 Mon Sep 17 00:00:00 2001
From: Nithin Sujir <118742+nithinsujir@users.noreply.github.com>
Date: Tue, 18 Sep 2018 15:52:52 -0700
Subject: [PATCH] Clean up snippets for BatchClient and Spanner (#3684)
* Clean up snippets for BatchClient and Spanner
* Remove trivial batch_client_read_with_id snippet
---
.../com/google/cloud/spanner/BatchClient.java | 6 -----
.../spanner/BatchReadOnlyTransaction.java | 22 ++++++---------
.../com/google/cloud/spanner/Spanner.java | 4 +--
.../spanner/snippets/BatchClientSnippets.java | 27 ++++++-------------
.../spanner/snippets/SpannerSnippets.java | 4 +--
5 files changed, 20 insertions(+), 43 deletions(-)
diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClient.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClient.java
index e038cfa6fa26..4872d7b46ada 100644
--- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClient.java
+++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClient.java
@@ -59,12 +59,6 @@ public interface BatchClient {
* @param batchTransactionId to re-initialize the transaction, re-using the timestamp for
* successive read/query.
*
- *
- *
{@code
- * BatchTransactionId txnId = my_txn.getBatchTransactionId();
- * BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
- * }
- *
*/
BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batchTransactionId);
}
diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchReadOnlyTransaction.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchReadOnlyTransaction.java
index 6371c456dc06..1b434b693048 100644
--- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchReadOnlyTransaction.java
+++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchReadOnlyTransaction.java
@@ -71,7 +71,7 @@ public interface BatchReadOnlyTransaction extends ReadOnlyTransaction {
* long singerId = results.getLong(0);
* String firstName = results.getString(1);
* String lastName = results.getString(2);
- * System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
+ * System.out.println("[" + singerId + "] " + firstName + " " + lastName);
* }
* }
* }
@@ -110,14 +110,15 @@ List partitionRead(
* "Singers",
* "SingerId",
* KeySet.all(),
- * Arrays.asList("FirstName"));
- * BatchTransactionId txnID = txn.getBatchTransactionId();
- * int numRowsRead = 0;
+ * Arrays.asList("SingerId", "FirstName", "LastName"));
+ *
* for (Partition p : partitions) {
- * BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
- * try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
+ * try (ResultSet results = txn.execute(p)) {
* while (results.next()) {
- * System.out.println(results.getString(0));
+ * long singerId = results.getLong(0);
+ * String firstName = results.getString(1);
+ * String lastName = results.getString(2);
+ * System.out.println("[" + singerId + "] " + firstName + " " + lastName);
* }
* }
* }
@@ -198,13 +199,6 @@ List partitionQuery(
* Returns a {@link BatchTransactionId} to be re-used across several machines/processes. This
* BatchTransactionId guarantees the subsequent read/query to be executed at the same timestamp.
*
- *
- * {@code
- * BatchTransactionId txnId = my_txn.getBatchTransactionId();
- * BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
- * }
- *
- *
*/
BatchTransactionId getBatchTransactionId();
}
diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Spanner.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Spanner.java
index 4f6cb1b901a6..fbad68059db9 100644
--- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Spanner.java
+++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Spanner.java
@@ -61,7 +61,7 @@ public interface Spanner extends Service {
* final String instance = "test-instance";
* final String database = "example-db";
* DatabaseId db =
- * DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
+ * DatabaseId.of(project, instance, database);
* DatabaseClient dbClient = spanner.getDatabaseClient(db);
* }
*
@@ -85,7 +85,7 @@ public interface Spanner extends Service {
* final String instance = "test-instance";
* final String database = "example-db";
* DatabaseId db =
- * DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
+ * DatabaseId.of(project, instance, database);
* BatchClient batchClient = spanner.getBatchClient(db);
* }
*
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/BatchClientSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/BatchClientSnippets.java
index 835a3f195140..2b0dff1171be 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/BatchClientSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/BatchClientSnippets.java
@@ -55,18 +55,6 @@ BatchReadOnlyTransaction readStrong() {
return txn;
}
- /**
- * Example to do a batch read with txn id.
- */
- BatchReadOnlyTransaction readWithId(BatchReadOnlyTransaction my_txn) {
- // [START batch_client_read_with_id]
- BatchTransactionId txnId = my_txn.getBatchTransactionId();
- BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
- // [END batch_client_read_with_id]
-
- return txn;
- }
-
void partitionQuery() {
// [START partition_query]
final BatchReadOnlyTransaction txn =
@@ -104,7 +92,7 @@ void partitionRead() {
long singerId = results.getLong(0);
String firstName = results.getString(1);
String lastName = results.getString(2);
- System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
+ System.out.println("[" + singerId + "] " + firstName + " " + lastName);
}
}
}
@@ -121,14 +109,15 @@ void partitionReadUsingIndex() {
"Singers",
"SingerId",
KeySet.all(),
- Arrays.asList("FirstName"));
- BatchTransactionId txnID = txn.getBatchTransactionId();
- int numRowsRead = 0;
+ Arrays.asList("SingerId", "FirstName", "LastName"));
+
for (Partition p : partitions) {
- BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
- try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
+ try (ResultSet results = txn.execute(p)) {
while (results.next()) {
- System.out.println(results.getString(0));
+ long singerId = results.getLong(0);
+ String firstName = results.getString(1);
+ String lastName = results.getString(2);
+ System.out.println("[" + singerId + "] " + firstName + " " + lastName);
}
}
}
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/SpannerSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/SpannerSnippets.java
index b57c9dc80433..1844ca6ffbf3 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/SpannerSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/SpannerSnippets.java
@@ -53,7 +53,7 @@ DatabaseClient getDatabaseClient() {
final String instance = "test-instance";
final String database = "example-db";
DatabaseId db =
- DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
+ DatabaseId.of(project, instance, database);
DatabaseClient dbClient = spanner.getDatabaseClient(db);
// [END get_db_client]
@@ -78,7 +78,7 @@ BatchClient getBatchClient() {
final String instance = "test-instance";
final String database = "example-db";
DatabaseId db =
- DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
+ DatabaseId.of(project, instance, database);
BatchClient batchClient = spanner.getBatchClient(db);
// [END get_batch_client]