| GitHub Repository | Product Reference |
Service Description: Cloud SQL connect service.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
GetConnectSettingsRequest request =
GetConnectSettingsRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setReadTime(Timestamp.newBuilder().build())
.build();
ConnectSettings response = sqlConnectServiceClient.getConnectSettings(request);
}
Note: close() needs to be called on the SqlConnectServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
GetConnectSettings |
Retrieves connect settings about a Cloud SQL instance. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ResolveConnectSettings |
Retrieves connect settings about a Cloud SQL instance using the instance DNS name. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GenerateEphemeralCert |
Generates a short-lived X509 certificate containing the provided public key and signed by a private key specific to the target instance. Users may use the certificate to authenticate as themselves when connecting to the database. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SqlConnectServiceSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
SqlConnectServiceSettings sqlConnectServiceSettings =
SqlConnectServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SqlConnectServiceClient sqlConnectServiceClient =
SqlConnectServiceClient.create(sqlConnectServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
SqlConnectServiceSettings sqlConnectServiceSettings =
SqlConnectServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
SqlConnectServiceClient sqlConnectServiceClient =
SqlConnectServiceClient.create(sqlConnectServiceSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
SqlConnectServiceSettings sqlConnectServiceSettings =
SqlConnectServiceSettings.newHttpJsonBuilder().build();
SqlConnectServiceClient sqlConnectServiceClient =
SqlConnectServiceClient.create(sqlConnectServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Static Methods
create()
public static final SqlConnectServiceClient create()Constructs an instance of SqlConnectServiceClient with default settings.
| Returns | |
|---|---|
| Type | Description |
SqlConnectServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
create(SqlConnectServiceSettings settings)
public static final SqlConnectServiceClient create(SqlConnectServiceSettings settings)Constructs an instance of SqlConnectServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
| Parameter | |
|---|---|
| Name | Description |
settings |
SqlConnectServiceSettings |
| Returns | |
|---|---|
| Type | Description |
SqlConnectServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
create(SqlConnectServiceStub stub)
public static final SqlConnectServiceClient create(SqlConnectServiceStub stub)Constructs an instance of SqlConnectServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(SqlConnectServiceSettings).
| Parameter | |
|---|---|
| Name | Description |
stub |
SqlConnectServiceStub |
| Returns | |
|---|---|
| Type | Description |
SqlConnectServiceClient |
|
Constructors
SqlConnectServiceClient(SqlConnectServiceSettings settings)
protected SqlConnectServiceClient(SqlConnectServiceSettings settings)Constructs an instance of SqlConnectServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
| Parameter | |
|---|---|
| Name | Description |
settings |
SqlConnectServiceSettings |
SqlConnectServiceClient(SqlConnectServiceStub stub)
protected SqlConnectServiceClient(SqlConnectServiceStub stub)| Parameter | |
|---|---|
| Name | Description |
stub |
SqlConnectServiceStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)| Parameters | |
|---|---|
| Name | Description |
duration |
long |
unit |
TimeUnit |
| Returns | |
|---|---|
| Type | Description |
boolean |
|
| Exceptions | |
|---|---|
| Type | Description |
InterruptedException |
|
close()
public final void close()generateEphemeralCert(GenerateEphemeralCertRequest request)
public final GenerateEphemeralCertResponse generateEphemeralCert(GenerateEphemeralCertRequest request)Generates a short-lived X509 certificate containing the provided public key and signed by a private key specific to the target instance. Users may use the certificate to authenticate as themselves when connecting to the database.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
GenerateEphemeralCertRequest request =
GenerateEphemeralCertRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setPublicKey("publicKey1446899510")
.setAccessToken("accessToken-1042689291")
.setReadTime(Timestamp.newBuilder().build())
.setValidDuration(Duration.newBuilder().build())
.build();
GenerateEphemeralCertResponse response =
sqlConnectServiceClient.generateEphemeralCert(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
GenerateEphemeralCertRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
GenerateEphemeralCertResponse |
|
generateEphemeralCertCallable()
public final UnaryCallable<GenerateEphemeralCertRequest,GenerateEphemeralCertResponse> generateEphemeralCertCallable()Generates a short-lived X509 certificate containing the provided public key and signed by a private key specific to the target instance. Users may use the certificate to authenticate as themselves when connecting to the database.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
GenerateEphemeralCertRequest request =
GenerateEphemeralCertRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setPublicKey("publicKey1446899510")
.setAccessToken("accessToken-1042689291")
.setReadTime(Timestamp.newBuilder().build())
.setValidDuration(Duration.newBuilder().build())
.build();
ApiFuture<GenerateEphemeralCertResponse> future =
sqlConnectServiceClient.generateEphemeralCertCallable().futureCall(request);
// Do something.
GenerateEphemeralCertResponse response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<GenerateEphemeralCertRequest,GenerateEphemeralCertResponse> |
|
getConnectSettings(GetConnectSettingsRequest request)
public final ConnectSettings getConnectSettings(GetConnectSettingsRequest request)Retrieves connect settings about a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
GetConnectSettingsRequest request =
GetConnectSettingsRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setReadTime(Timestamp.newBuilder().build())
.build();
ConnectSettings response = sqlConnectServiceClient.getConnectSettings(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
GetConnectSettingsRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
ConnectSettings |
|
getConnectSettingsCallable()
public final UnaryCallable<GetConnectSettingsRequest,ConnectSettings> getConnectSettingsCallable()Retrieves connect settings about a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
GetConnectSettingsRequest request =
GetConnectSettingsRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setReadTime(Timestamp.newBuilder().build())
.build();
ApiFuture<ConnectSettings> future =
sqlConnectServiceClient.getConnectSettingsCallable().futureCall(request);
// Do something.
ConnectSettings response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<GetConnectSettingsRequest,ConnectSettings> |
|
getSettings()
public final @Nullable SqlConnectServiceSettings getSettings()| Returns | |
|---|---|
| Type | Description |
@org.jspecify.annotations.Nullable com.google.cloud.sql.v1beta4.SqlConnectServiceSettings |
|
getStub()
public SqlConnectServiceStub getStub()| Returns | |
|---|---|
| Type | Description |
SqlConnectServiceStub |
|
isShutdown()
public boolean isShutdown()| Returns | |
|---|---|
| Type | Description |
boolean |
|
isTerminated()
public boolean isTerminated()| Returns | |
|---|---|
| Type | Description |
boolean |
|
resolveConnectSettings(ResolveConnectSettingsRequest request)
public final ConnectSettings resolveConnectSettings(ResolveConnectSettingsRequest request)Retrieves connect settings about a Cloud SQL instance using the instance DNS name.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
ResolveConnectSettingsRequest request =
ResolveConnectSettingsRequest.newBuilder()
.setDnsName("dnsName1813886804")
.setLocation("location1901043637")
.build();
ConnectSettings response = sqlConnectServiceClient.resolveConnectSettings(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
ResolveConnectSettingsRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
ConnectSettings |
|
resolveConnectSettingsCallable()
public final UnaryCallable<ResolveConnectSettingsRequest,ConnectSettings> resolveConnectSettingsCallable()Retrieves connect settings about a Cloud SQL instance using the instance DNS name.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlConnectServiceClient sqlConnectServiceClient = SqlConnectServiceClient.create()) {
ResolveConnectSettingsRequest request =
ResolveConnectSettingsRequest.newBuilder()
.setDnsName("dnsName1813886804")
.setLocation("location1901043637")
.build();
ApiFuture<ConnectSettings> future =
sqlConnectServiceClient.resolveConnectSettingsCallable().futureCall(request);
// Do something.
ConnectSettings response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<ResolveConnectSettingsRequest,ConnectSettings> |
|
shutdown()
public void shutdown()shutdownNow()
public void shutdownNow()