Class ConnectionOptions.Builder
java.lang.Object
com.google.cloud.spanner.connection.ConnectionOptions.Builder
- Enclosing class:
- ConnectionOptions
Builder for
ConnectionOptions
instances.-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
setCredentialsUrl
(String credentialsUrl) Sets the URL of the credentials file to use for this connection.setOAuthToken
(String oauthToken) Sets the OAuth token to use with this connection.setSessionPoolOptions
(SessionPoolOptions sessionPoolOptions) Sets theSessionPoolOptions
to use for the connection.Sets the URI of the Cloud Spanner database to connect to.
-
Field Details
-
SPANNER_URI_FORMAT
SpannerConnectionOptions
URI format.- See Also:
-
-
Method Details
-
setUri
Sets the URI of the Cloud Spanner database to connect to. A connection URI must be specified in this format:cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\?property-name=property-value[;property-name=property-value]*]?
The property-value strings should be url-encoded.The project-id part of the URI may be filled with the placeholder DEFAULT_PROJECT_ID. This placeholder will be replaced by the default project id of the environment that is requesting a connection.
The supported properties are:
- credentials (String): URL for the credentials file to use for the connection. This
property is only used if no credentials have been specified using the
setCredentialsUrl(String)
method. If you do not specify any credentials at all, the default credentials of the environment as returned byGoogleCredentials.getApplicationDefault()
will be used. - encodedCredentials (String): A Base64 encoded string containing the Google credentials to use. You should only set either this property or the `credentials` (file location) property, but not both at the same time.
- credentialsProvider (String): Class name of the
CredentialsProvider
that should be used to get credentials for a connection that is created by thisConnectionOptions
. The credentials will be retrieved from theCredentialsProvider
when a new connection is created. A connection will use the credentials that were obtained at creation during its lifetime. - autocommit (boolean): Sets the initial autocommit mode for the connection. Default is true.
- readonly (boolean): Sets the initial readonly mode for the connection. Default is false.
- minSessions (int): Sets the minimum number of sessions in the backing session pool.
- maxSessions (int): Sets the maximum number of sessions in the backing session pool.
- numChannels (int): Sets the number of gRPC channels to use for the connection.
- retryAbortsInternally (boolean): Sets the initial retryAbortsInternally mode for the connection. Default is true.
- optimizerVersion (string): Sets the query optimizer version to use for the connection.
- autoConfigEmulator (boolean): Automatically configures the connection to connect to the Cloud Spanner emulator. If no host and port is specified in the connection string, the connection will automatically use the default emulator host/port combination (localhost:9010). Plain text communication will be enabled and authentication will be disabled. The instance and database in the connection string will automatically be created on the emulator if any of them do not yet exist. Any existing instance or database on the emulator will remain untouched. No other configuration is needed in order to connect to the emulator than setting this property.
- routeToLeader (boolean): Sets the routeToLeader flag to route requests to leader (true) or any region (false) in read/write transactions and Partitioned DML. Default is true.
- Parameters:
uri
- The URI of the Spanner database to connect to.- Returns:
- this builder
- credentials (String): URL for the credentials file to use for the connection. This
property is only used if no credentials have been specified using the
-
setSessionPoolOptions
Sets theSessionPoolOptions
to use for the connection. -
setCredentialsUrl
Sets the URL of the credentials file to use for this connection. The URL may be a reference to a file on the local file system, or to a file on Google Cloud Storage. References to Google Cloud Storage files are only allowed when the application is running on Google Cloud and the environment has access to the specified storage location. It also requires that the Google Cloud Storage client library is present on the class path. The Google Cloud Storage library is not automatically added as a dependency by the JDBC driver.If you do not specify a credentialsUrl (either by using this setter, or by specifying on the connection URI), the credentials returned by
GoogleCredentials.getApplicationDefault()
will be used for the connection.- Parameters:
credentialsUrl
- A valid file or Google Cloud Storage URL for the credentials file to be used.- Returns:
- this builder
-
setOAuthToken
Sets the OAuth token to use with this connection. The token must be a valid token with access to the resources (project/instance/database) that the connection will be accessing. This authentication method cannot be used in combination with a credentials file. If both an OAuth token and a credentials file is specified, thebuild()
method will throw an exception.- Parameters:
oauthToken
- A valid OAuth token for the Google Cloud project that is used by this connection.- Returns:
- this builder
-
build
- Returns:
- the
ConnectionOptions
-