public class ConnectionOptions
Internal connection API for Google Cloud Spanner. This class may introduce breaking changes
without prior notice.
Options for creating a Connection to a Google Cloud Spanner database.
Usage:
ConnectionOptions options = ConnectionOptions.newBuilder()
.setUri("cloudspanner:/projects/my_project_id/instances/my_instance_id/databases/my_database_name?autocommit=false")
.setCredentialsUrl("/home/cloudspanner-keys/my-key.json")
.build();
try(Connection connection = options.getConnection()) {
try(ResultSet rs = connection.executeQuery(Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"))) {
while(rs.next()) {
// do something
}
}
}
Static Fields
AUTOCOMMIT_PROPERTY_NAME
public static final String AUTOCOMMIT_PROPERTY_NAME
Name of the 'autocommit' connection property.
Field Value |
Type |
Description |
String |
|
AUTO_PARTITION_MODE_PROPERTY_NAME
public static final String AUTO_PARTITION_MODE_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
CHANNEL_PROVIDER_PROPERTY_NAME
public static final String CHANNEL_PROVIDER_PROPERTY_NAME
Name of the 'channelProvider' connection property.
Field Value |
Type |
Description |
String |
|
CREDENTIALS_PROPERTY_NAME
public static final String CREDENTIALS_PROPERTY_NAME
Name of the 'credentials' connection property.
Field Value |
Type |
Description |
String |
|
CREDENTIALS_PROVIDER_PROPERTY_NAME
public static final String CREDENTIALS_PROVIDER_PROPERTY_NAME
Name of the 'credentialsProvider' connection property.
Field Value |
Type |
Description |
String |
|
DATABASE_ROLE_PROPERTY_NAME
public static final String DATABASE_ROLE_PROPERTY_NAME
Name of the 'databaseRole' connection property.
Field Value |
Type |
Description |
String |
|
DATA_BOOST_ENABLED_PROPERTY_NAME
public static final String DATA_BOOST_ENABLED_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
DDL_IN_TRANSACTION_MODE_PROPERTY_NAME
public static final String DDL_IN_TRANSACTION_MODE_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE_NAME
public static final String DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE_NAME
Name of the 'delay transaction start until first write' property.
Field Value |
Type |
Description |
String |
|
ENABLE_API_TRACING_PROPERTY_NAME
public static final String ENABLE_API_TRACING_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
ENABLE_CHANNEL_PROVIDER_SYSTEM_PROPERTY
public static final String ENABLE_CHANNEL_PROVIDER_SYSTEM_PROPERTY
Field Value |
Type |
Description |
String |
|
ENABLE_CREDENTIALS_PROVIDER_SYSTEM_PROPERTY
public static final String ENABLE_CREDENTIALS_PROVIDER_SYSTEM_PROPERTY
Field Value |
Type |
Description |
String |
|
ENABLE_ENCODED_CREDENTIALS_SYSTEM_PROPERTY
public static final String ENABLE_ENCODED_CREDENTIALS_SYSTEM_PROPERTY
Field Value |
Type |
Description |
String |
|
ENABLE_EXTENDED_TRACING_PROPERTY_NAME
public static final String ENABLE_EXTENDED_TRACING_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
ENCODED_CREDENTIALS_PROPERTY_NAME
public static final String ENCODED_CREDENTIALS_PROPERTY_NAME
Name of the 'encodedCredentials' connection property.
Field Value |
Type |
Description |
String |
|
ENDPOINT_PROPERTY_NAME
public static final String ENDPOINT_PROPERTY_NAME
Name of the 'endpoint' connection property.
Field Value |
Type |
Description |
String |
|
KEEP_TRANSACTION_ALIVE_PROPERTY_NAME
public static final String KEEP_TRANSACTION_ALIVE_PROPERTY_NAME
Name of the 'keep transaction alive' property.
Field Value |
Type |
Description |
String |
|
LENIENT_PROPERTY_NAME
public static final String LENIENT_PROPERTY_NAME
Name of the 'lenientMode' connection property.
Field Value |
Type |
Description |
String |
|
MAX_PARTITIONED_PARALLELISM_PROPERTY_NAME
public static final String MAX_PARTITIONED_PARALLELISM_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
MAX_PARTITIONS_PROPERTY_NAME
public static final String MAX_PARTITIONS_PROPERTY_NAME
Field Value |
Type |
Description |
String |
|
MAX_SESSIONS_PROPERTY_NAME
public static final String MAX_SESSIONS_PROPERTY_NAME
Name of the 'maxSessions' connection property.
Field Value |
Type |
Description |
String |
|
MIN_SESSIONS_PROPERTY_NAME
public static final String MIN_SESSIONS_PROPERTY_NAME
Name of the 'minSessions' connection property.
Field Value |
Type |
Description |
String |
|
NUM_CHANNELS_PROPERTY_NAME
public static final String NUM_CHANNELS_PROPERTY_NAME
Name of the 'numChannels' connection property.
Field Value |
Type |
Description |
String |
|
OAUTH_TOKEN_PROPERTY_NAME
public static final String OAUTH_TOKEN_PROPERTY_NAME
OAuth token to use for authentication. Cannot be used in combination with a credentials file.
Field Value |
Type |
Description |
String |
|
READONLY_PROPERTY_NAME
public static final String READONLY_PROPERTY_NAME
Name of the 'readonly' connection property.
Field Value |
Type |
Description |
String |
|
RETRY_ABORTS_INTERNALLY_PROPERTY_NAME
public static final String RETRY_ABORTS_INTERNALLY_PROPERTY_NAME
Name of the 'retry aborts internally' connection property.
Field Value |
Type |
Description |
String |
|
ROUTE_TO_LEADER_PROPERTY_NAME
public static final String ROUTE_TO_LEADER_PROPERTY_NAME
Name of the 'routeToLeader' connection property.
Field Value |
Type |
Description |
String |
|
RPC_PRIORITY_NAME
public static final String RPC_PRIORITY_NAME
Name of the 'rpcPriority' connection property.
Field Value |
Type |
Description |
String |
|
TRACK_CONNECTION_LEAKS_PROPERTY_NAME
public static final String TRACK_CONNECTION_LEAKS_PROPERTY_NAME
Name of the 'trackStackTraceOfConnectionCreation' connection property.
Field Value |
Type |
Description |
String |
|
TRACK_SESSION_LEAKS_PROPERTY_NAME
public static final String TRACK_SESSION_LEAKS_PROPERTY_NAME
Name of the 'trackStackTraceOfSessionCheckout' connection property.
Field Value |
Type |
Description |
String |
|
USE_VIRTUAL_GRPC_TRANSPORT_THREADS_PROPERTY_NAME
public static final String USE_VIRTUAL_GRPC_TRANSPORT_THREADS_PROPERTY_NAME
Name of the property to enable/disable virtual threads for gRPC transport.
Field Value |
Type |
Description |
String |
|
USE_VIRTUAL_THREADS_PROPERTY_NAME
public static final String USE_VIRTUAL_THREADS_PROPERTY_NAME
Name of the property to enable/disable virtual threads for the statement executor.
Field Value |
Type |
Description |
String |
|
VALID_PROPERTIES
public static final Set<ConnectionOptions.ConnectionProperty> VALID_PROPERTIES
All valid connection properties.
Static Methods
closeSpanner()
public static void closeSpanner()
Closes all Spanner instances that have been opened by connections
during the lifetime of this JVM. Call this method at the end of your application to free up
resources. You must close all Connections that have been opened by your application
before calling this method. Failing to do so, will cause this method to throw a SpannerException.
This method is also automatically called by a shutdown hook (see Runtime#addShutdownHook(Thread)) when the JVM is shutdown gracefully.
getDefaultProjectId(Credentials credentials)
public static String getDefaultProjectId(Credentials credentials)
Gets the default project-id for the current environment as defined by ServiceOptions#getDefaultProjectId(), and if none could be found, the project-id of the given
credentials if it contains any.
Parameter |
Name |
Description |
credentials |
com.google.auth.Credentials
The credentials to use to get the default project-id if none could be found
in the environment.
|
Returns |
Type |
Description |
String |
the default project-id.
|
newBuilder()
public static ConnectionOptions.Builder newBuilder()
Methods
getChannelProvider()
public TransportChannelProvider getChannelProvider()
Calls the getChannelProvider() method from the supplied class.
getConnection()
public Connection getConnection()
getCredentials()
public Credentials getCredentials()
The Credentials of this ConnectionOptions. This is either the credentials
specified in the credentialsUrl or the default Google application credentials
Returns |
Type |
Description |
com.google.auth.Credentials |
|
getCredentialsUrl()
public String getCredentialsUrl()
Returns |
Type |
Description |
String |
|
getDatabaseId()
public DatabaseId getDatabaseId()
getDatabaseName()
public String getDatabaseName()
Returns |
Type |
Description |
String |
|
getDatabaseRole()
public String getDatabaseRole()
The database role that is used for this connection. Assigning a role to a connection can be
used to for example restrict the access of a connection to a specific set of tables.
Returns |
Type |
Description |
String |
|
getDialect()
public Dialect getDialect()
getHost()
Returns |
Type |
Description |
String |
|
getInstanceId()
public String getInstanceId()
Returns |
Type |
Description |
String |
|
getMaxCommitDelay()
public Duration getMaxCommitDelay()
The max_commit_delay that should be applied to commit operations on this connection.
getMaxSessions()
public Integer getMaxSessions()
The maximum number of sessions in the backing session pool of this connection. The session pool
is shared between all connections in the same JVM that connect to the same Cloud Spanner
database using the same connection settings.
getMinSessions()
public Integer getMinSessions()
The minimum number of sessions in the backing session pool of this connection. The session pool
is shared between all connections in the same JVM that connect to the same Cloud Spanner
database using the same connection settings.
getNumChannels()
public Integer getNumChannels()
The number of channels to use for the connection.
getProjectId()
public String getProjectId()
Returns |
Type |
Description |
String |
|
getSessionPoolOptions()
public SessionPoolOptions getSessionPoolOptions()
getUri()
Returns |
Type |
Description |
String |
|
getWarnings()
public String getWarnings()
Returns |
Type |
Description |
String |
|
isAutoConfigEmulator()
public boolean isAutoConfigEmulator()
Whether connections created by this ConnectionOptions will automatically try to connect
to the emulator using the default host/port of the emulator, and automatically create the
instance and database that is specified in the connection string if these do not exist on the
emulator instance.
isAutocommit()
public boolean isAutocommit()
isReadOnly()
public boolean isReadOnly()
isRetryAbortsInternally()
public boolean isRetryAbortsInternally()
The initial retryAbortsInternally value for connections created by this ConnectionOptions
isReturnCommitStats()
public boolean isReturnCommitStats()
isRouteToLeader()
public boolean isRouteToLeader()
Whether read/write transactions and partitioned DML are preferred to be routed to the leader
region.
isUseVirtualGrpcTransportThreads()
public boolean isUseVirtualGrpcTransportThreads()
Whether virtual threads should be used for gRPC transport.
isUseVirtualThreads()
public boolean isUseVirtualThreads()
Whether connections should use virtual threads for connection executors.
toString()
Returns |
Type |
Description |
String |
|
Overrides