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]