public static class OptionsMetadata.Builder
Builder class for creating an instance of OptionsMetadata.
A default instance of this Builder will create a PGAdapter proxy server that:
- Accepts connections to any Cloud Spanner database. The database name must be given as a fully qualified database name in the PostgreSQL connection URL.
- Accepts connections on a dynamically assigned port. You can get the port that was assigned to the server after the server has started by calling ProxyServer#getLocalPort().
- Uses the default credentials in the current runtime environment.
- Listens for Unix domain socket connections on '/tmp'.
Methods
autoConfigureEmulator()
public OptionsMetadata.Builder autoConfigureEmulator()
Instructs PGAdapter to connect to the Cloud Spanner emulator and to automatically create the instance and the database in the connection request if the instance or database does not yet exist on the emulator. Setting this flag takes care of everything you need to connect to the emulator (except for starting the emulator), and the auto-creation of the instance and database removes the need for any additional scripts that must be executed before connecting to the emulator.
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
build()
public OptionsMetadata build()
Returns | |
---|---|
Type | Description |
OptionsMetadata |
disableUnixDomainSockets()
public OptionsMetadata.Builder disableUnixDomainSockets()
Disables the use of Unix domain sockets. This is necessary on systems that do not support Unix domain sockets, or if you do not intend to use Unix domain sockets to connect to PGAdapter.
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setCredentials(Credentials credentials)
public OptionsMetadata.Builder setCredentials(Credentials credentials)
(Optional) The credentials that PGAdapter should use to connect to Cloud Spanner.
Note:Specifying a credentials file is only necessary if you do not want PGAdapter to use the default credentials of the runtime environment.
You can only specify either a credentials instance using this method or a credentials file using #setCredentialsFile(String).
Parameter | |
---|---|
Name | Description |
credentials | com.google.auth.Credentials |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setCredentialsFile(String credentialsFile)
public OptionsMetadata.Builder setCredentialsFile(String credentialsFile)
(Optional) The credentials file (user credentials or service account key file) that PGAdapter should use to connect to Cloud Spanner.
Note:Specifying a credentials file is only necessary if you do not want PGAdapter to use the default credentials of the runtime environment.
You can only specify either a credentials file using this method or a Credentials instance using #setCredentials(Credentials).
Parameter | |
---|---|
Name | Description |
credentialsFile | String |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setDatabase(String database)
public OptionsMetadata.Builder setDatabase(String database)
(Optional) The Google Cloud Spanner database ID that PGAdapter should connect to. You can only set this property if you also set the project and instance ID that PGAdapter should use.
Note:Setting a project, instance and database ID will lock PGAdapter to only this specific database. Any database information in a PostgreSQL connection URL that PGAdapter receives will be ignored.
It is not required to set a database ID for PGAdapter. You must include a database name in the PostgreSQL connection URL if you do not set a database name on this builder. The database name in the connection URL can be:
- A database ID: This is only supported if you have set a project and instance ID on this builder. The database ID must be a valid database ID on the selected Cloud Spanner instance.
- A fully qualified database name in the form
projects/my-project/instances/my-instance/databases/my-database
. This database can be on any Cloud Spanner instance, and is not restricted to any project and instance ID that might have been set on this builder.
Parameter | |
---|---|
Name | Description |
database | String |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setDatabaseRole(String databaseRole)
public OptionsMetadata.Builder setDatabaseRole(String databaseRole)
(Optional) The database role to use for connections to Cloud Spanner.
Parameter | |
---|---|
Name | Description |
databaseRole | String |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setDdlTransactionMode(OptionsMetadata.DdlTransactionMode ddlTransactionMode)
public OptionsMetadata.Builder setDdlTransactionMode(OptionsMetadata.DdlTransactionMode ddlTransactionMode)
(Optional) Sets the default DDL transaction mode. Cloud Spanner does not support DDL statements in transactions, but some tools and frameworks will assume that it does. This option enables you to specify the behavior that PGAdapter should use when it encounters a DDL statement in a read/write transaction.
See also DDL Options for more information.
Parameter | |
---|---|
Name | Description |
ddlTransactionMode | OptionsMetadata.DdlTransactionMode |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setDisableLocalhostCheck()
public OptionsMetadata.Builder setDisableLocalhostCheck()
PGAdapter by default only allows connections from localhost. Call this method to disable this check. You should only allow connections from private networks, unless you are also using SSL and require clients to authenticate.
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setInstance(String instance)
public OptionsMetadata.Builder setInstance(String instance)
(Optional) The Google Cloud Spanner instance ID that PGAdapter should connect to.
It is not required to set an instance ID for PGAdapter, but you are required to use a
fully qualified database name in the form
projects/my-project/instances/my-instance/databases/my-database
in any connection URL if
you do not set an instance ID here.
Parameter | |
---|---|
Name | Description |
instance | String |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setNumChannels(int numChannels)
public OptionsMetadata.Builder setNumChannels(int numChannels)
(Optional) The number of gRPC channels to use for connections to Cloud Spanner.
Parameter | |
---|---|
Name | Description |
numChannels | int |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setPort(int port)
public OptionsMetadata.Builder setPort(int port)
(Optional) Sets the port that PGAdapter should use to listen for incoming connections. The default is 0, which dynamically assigns an available port to PGAdapter. The port that was assigned can be retrieved by calling ProxyServer#getLocalPort() after the server has started.
Parameter | |
---|---|
Name | Description |
port | int |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setProject(String project)
public OptionsMetadata.Builder setProject(String project)
(Optional) The Google Cloud project ID that PGAdapter should connect to.
It is not required to set a project ID for PGAdapter, but you are required to use a fully
qualified database name in the form
projects/my-project/instances/my-instance/databases/my-database
in any connection URL if
you do not set a project ID here.
Parameter | |
---|---|
Name | Description |
project | String |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setRequireAuthentication()
public OptionsMetadata.Builder setRequireAuthentication()
Require PostgreSQL clients that connect to PGAdapter to authenticate. The PostgreSQL client should provide the serialized credentials that PGAdapter should use to connect to Cloud Spanner as a password.
See authentication.md for more information.
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setSessionPoolOptions(SessionPoolOptions sessionPoolOptions)
public OptionsMetadata.Builder setSessionPoolOptions(SessionPoolOptions sessionPoolOptions)
(Optional) The SessionPoolOptions to use for connections to Cloud Spanner.
Parameter | |
---|---|
Name | Description |
sessionPoolOptions | com.google.cloud.spanner.SessionPoolOptions |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setSslMode(OptionsMetadata.SslMode sslMode)
public OptionsMetadata.Builder setSslMode(OptionsMetadata.SslMode sslMode)
PGAdapter by default does not support SSL connections. Call this method to allow or require SSL connections.
See SSL options for more information on setting up SSL for PGAdapter.
Parameter | |
---|---|
Name | Description |
sslMode | OptionsMetadata.SslMode |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |
setUnixDomainSocketDirectory(String directory)
public OptionsMetadata.Builder setUnixDomainSocketDirectory(String directory)
(Optional) The directory to use for Unix domain socket connections. The default is '/tmp'.
Parameter | |
---|---|
Name | Description |
directory | String |
Returns | |
---|---|
Type | Description |
OptionsMetadata.Builder |