Class ConnectionOptions.Builder (6.25.0)

public static class ConnectionOptions.Builder

Builder for ConnectionOptions instances.

Inheritance

java.lang.Object > ConnectionOptions.Builder

Static Fields

SPANNER_URI_FORMAT

public static final String SPANNER_URI_FORMAT

Spanner ConnectionOptions URI format.

Field Value
TypeDescription
String

Methods

build()

public ConnectionOptions build()
Returns
TypeDescription
ConnectionOptions

the ConnectionOptions

setCredentialsUrl(String credentialsUrl)

public ConnectionOptions.Builder setCredentialsUrl(String credentialsUrl)

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.

Parameter
NameDescription
credentialsUrlString

A valid file or Google Cloud Storage URL for the credentials file to be used.

Returns
TypeDescription
ConnectionOptions.Builder

this builder

setOAuthToken(String oauthToken)

public ConnectionOptions.Builder setOAuthToken(String oauthToken)

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, the #build() method will throw an exception.

Parameter
NameDescription
oauthTokenString

A valid OAuth token for the Google Cloud project that is used by this connection.

Returns
TypeDescription
ConnectionOptions.Builder

this builder

setSessionPoolOptions(SessionPoolOptions sessionPoolOptions)

public ConnectionOptions.Builder setSessionPoolOptions(SessionPoolOptions sessionPoolOptions)

Sets the SessionPoolOptions to use for the connection.

Parameter
NameDescription
sessionPoolOptionsSessionPoolOptions
Returns
TypeDescription
ConnectionOptions.Builder

setUri(String uri)

public ConnectionOptions.Builder setUri(String uri)

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 ConnectionOptions.Builder#setCredentialsUrl(String) method. If you do not specify any credentials at all, the default credentials of the environment as returned by GoogleCredentials#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 com.google.api.gax.core.CredentialsProvider that should be used to get credentials for a connection that is created by this ConnectionOptions. The credentials will be retrieved from the com.google.api.gax.core.CredentialsProvider 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.
Parameter
NameDescription
uriString

The URI of the Spanner database to connect to.

Returns
TypeDescription
ConnectionOptions.Builder

this builder