use of com.google.cloud.spanner.DatabaseId in project java-docs-samples by GoogleCloudPlatform.
the class SpannerSample method main.
public static void main(String[] args) throws Exception {
if (args.length != 3) {
printUsageAndExit();
}
// [START init_client]
SpannerOptions options = SpannerOptions.newBuilder().build();
Spanner spanner = options.getService();
try {
String command = args[0];
DatabaseId db = DatabaseId.of(options.getProjectId(), args[1], args[2]);
// [END init_client]
// This will return the default project id based on the environment.
String clientProject = spanner.getOptions().getProjectId();
if (!db.getInstanceId().getProject().equals(clientProject)) {
System.err.println("Invalid project specified. Project in the database id should match" + "the project name set in the environment variable GCLOUD_PROJECT. Expected: " + clientProject);
printUsageAndExit();
}
// [START init_client]
DatabaseClient dbClient = spanner.getDatabaseClient(db);
DatabaseAdminClient dbAdminClient = spanner.getDatabaseAdminClient();
// [END init_client]
run(dbClient, dbAdminClient, command, db);
} finally {
spanner.close();
}
System.out.println("Closed client");
}
use of com.google.cloud.spanner.DatabaseId 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.DatabaseId in project google-cloud-java by GoogleCloudPlatform.
the class SpannerSnippets method getBatchClient.
BatchClient getBatchClient() {
// [START get_batch_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);
BatchClient batchClient = spanner.getBatchClient(db);
return batchClient;
}
Aggregations