Package com.google.cloud.spanner
Interface Spanner
-
- All Superinterfaces:
AutoCloseable
,com.google.cloud.Service<SpannerOptions>
public interface Spanner extends com.google.cloud.Service<SpannerOptions>, AutoCloseable
An interface for Cloud Spanner. Typically, there would only be one instance of this for the lifetime of the application which must be closed by invokingclose()
when it is no longer needed. Failure to do so may result in leaking session resources and exhausting session quota.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes all the clients associated with this instance and frees up all the resources.com.google.api.gax.core.ExecutorProvider
getAsyncExecutorProvider()
BatchClient
getBatchClient(DatabaseId db)
Returns aBatchClient
to do batch operations on Cloud Spanner databases.DatabaseAdminClient
getDatabaseAdminClient()
Returns aDatabaseAdminClient
to do admin operations on Cloud Spanner databases.DatabaseClient
getDatabaseClient(DatabaseId db)
Returns aDatabaseClient
for the given database.InstanceAdminClient
getInstanceAdminClient()
Returns anInstanceAdminClient
to do admin operations on Cloud Spanner instances.boolean
isClosed()
-
-
-
Method Detail
-
getDatabaseAdminClient
DatabaseAdminClient getDatabaseAdminClient()
Returns aDatabaseAdminClient
to do admin operations on Cloud Spanner databases.
-
getInstanceAdminClient
InstanceAdminClient getInstanceAdminClient()
Returns anInstanceAdminClient
to do admin operations on Cloud Spanner instances.
-
getDatabaseClient
DatabaseClient getDatabaseClient(DatabaseId db)
Returns aDatabaseClient
for the given database. It uses a pool of sessions to talk to the database.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);
-
getBatchClient
BatchClient getBatchClient(DatabaseId db)
Returns aBatchClient
to do batch operations on Cloud Spanner databases. Batch client is useful when one wants to read/query a large amount of data from Cloud Spanner across multiple processes, even across different machines. It allows to create partitions of Cloud Spanner database and then read/query over each partition independently yet at the same snapshot.For all other use cases,
DatabaseClient
is more appropriate and performant.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);
-
close
void close()
Closes all the clients associated with this instance and frees up all the resources. This method will block until it can clean up all the resources. Specifically, it deletes all the underlying sessions (which involves rpcs) and closes all the gRPC channels. Once this method called, this object is no longer usable. It is strongly advised to call this method when you are done with theSpanner
object, typically when your application shuts down. There is a hard limit on number of sessions in Cloud Spanner and not calling this method can lead to unused sessions piling up on the backend.- Specified by:
close
in interfaceAutoCloseable
-
isClosed
boolean isClosed()
- Returns:
true
if thisSpanner
object is closed.
-
getAsyncExecutorProvider
com.google.api.gax.core.ExecutorProvider getAsyncExecutorProvider()
- Returns:
- the
ExecutorProvider
that is used for asynchronous queries and operations.
-
-