Skip to content

Commit

Permalink
chore: update sample files for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshachinta committed Jul 12, 2024
1 parent 3bc44dc commit b35ce1a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions google-cloud-spanner-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>grpc-gcp</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
Expand Down
1 change: 1 addition & 0 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>grpc-gcp</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down
3 changes: 3 additions & 0 deletions samples/snippets/grpc_java_logging_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
com.google.cloud.grpc.GcpManagedChannel.level=FINEST
6 changes: 6 additions & 0 deletions samples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>grpc-gcp</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.69.1-SNAPSHOT</version>
</dependency>
<!-- [END spanner_install_with_bom] -->

Expand Down
45 changes: 45 additions & 0 deletions samples/snippets/src/main/java/com/example/spanner/Mux.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.spanner;

import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.cloud.spanner.Statement;
import java.math.BigDecimal;
import java.util.logging.Level;
import java.util.logging.Logger;

class Mux {
public static void main(String[] args){
Logger.getLogger("com.google.cloud.grpc.GcpManagedChannel").setLevel(Level.FINEST);
queryWithNumericParameter();
}

static void queryWithNumericParameter() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "span-cloud-testing";
String instanceId = "harsha-test-gcloud";
String databaseId = "database1";

try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).enableGrpcGcpExtension().build().getService()) {
DatabaseClient client =
spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
queryWithNumericParameter(client);
}
}

static void queryWithNumericParameter(DatabaseClient client) {
Statement statement =
Statement.newBuilder(
"SELECT SingerId, FirstName, LastName FROM Singers")
.build();
try (ResultSet resultSet = client.singleUse().executeQuery(statement)) {
while (resultSet.next()) {
System.out.printf(
"%d %s %s %n", resultSet.getLong("SingerId"), resultSet.getString("FirstName"), resultSet.getString("LastName"));
}
}
}
}

0 comments on commit b35ce1a

Please sign in to comment.