use of com.google.cloud.spanner.SpannerOptions in project google-cloud-java by GoogleCloudPlatform.
the class SpannerSnippets method getDatabaseAdminClient.
DatabaseAdminClient getDatabaseAdminClient() {
// [START get_dbadmin_client]
SpannerOptions options = SpannerOptions.newBuilder().build();
Spanner spanner = options.getService();
DatabaseAdminClient dbAdminClient = spanner.getDatabaseAdminClient();
return dbAdminClient;
}
use of com.google.cloud.spanner.SpannerOptions in project google-cloud-java by GoogleCloudPlatform.
the class SpannerSnippets method getDatabaseClient.
DatabaseClient getDatabaseClient() {
// [START get_db_client]
SpannerOptions options = SpannerOptions.newBuilder().build();
Spanner spanner = options.getService();
final String project = "test-project";
final String instance = "test-instance";
final String database = "example-db";
DatabaseId db = DatabaseId.of(project, instance, database);
DatabaseClient dbClient = spanner.getDatabaseClient(db);
return dbClient;
}
use of com.google.cloud.spanner.SpannerOptions in project spring-cloud-gcp by spring-cloud.
the class GcpSpannerEmulatorAutoConfigurationTests method testEmulatorAutoConfigurationEnabled.
@Test
public void testEmulatorAutoConfigurationEnabled() {
this.contextRunner.withPropertyValues("spring.cloud.gcp.spanner.emulator.enabled=true").run(context -> {
SpannerOptions spannerOptions = context.getBean(SpannerOptions.class);
assertThat(spannerOptions.getEndpoint()).isEqualTo("localhost:9010");
});
}
use of com.google.cloud.spanner.SpannerOptions in project google-cloud-java by GoogleCloudPlatform.
the class RemoteSpannerHelper method create.
/**
* Creates a {@code RemoteSpannerHelper} bound to the given instance ID. All databases created
* using this will be created in the given instance.
*/
public static RemoteSpannerHelper create(InstanceId instanceId) throws Throwable {
SpannerOptions options = SpannerOptions.newBuilder().setProjectId(instanceId.getProject()).build();
Spanner client = options.getService();
return new RemoteSpannerHelper(options, instanceId, client);
}
use of com.google.cloud.spanner.SpannerOptions in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartSample method main.
public static void main(String... args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: QuickStartSample <instance_id> <database_id>");
return;
}
// Instantiates a client
SpannerOptions options = SpannerOptions.newBuilder().build();
Spanner spanner = options.getService();
// Name of your instance & database.
String instanceId = args[0];
String databaseId = args[1];
try {
// Creates a database client
DatabaseClient dbClient = spanner.getDatabaseClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId));
// Queries the database
ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1"));
System.out.println("\n\nResults:");
// Prints the results
while (resultSet.next()) {
System.out.printf("%d\n\n", resultSet.getLong(0));
}
} finally {
// Closes the client which will free up the resources used
spanner.close();
}
}
Aggregations