| GitHub Repository | Product Reference |
Service Description: Cloud SQL users 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersDeleteRequest request =
SqlUsersDeleteRequest.newBuilder()
.setHost("host3208616")
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.build();
Operation response = sqlUsersServiceClient.delete(request);
}
Note: close() needs to be called on the SqlUsersServiceClient 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 |
|---|---|---|
Delete |
Deletes a user from 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.
|
Get |
Retrieves a resource containing information about a user. |
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.
|
Insert |
Creates a new user in 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.
|
List |
Lists users in the specified 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.
|
Update |
Updates an existing user in 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.
|
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 SqlUsersServiceSettings 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
SqlUsersServiceSettings sqlUsersServiceSettings =
SqlUsersServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SqlUsersServiceClient sqlUsersServiceClient =
SqlUsersServiceClient.create(sqlUsersServiceSettings);
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
SqlUsersServiceSettings sqlUsersServiceSettings =
SqlUsersServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
SqlUsersServiceClient sqlUsersServiceClient =
SqlUsersServiceClient.create(sqlUsersServiceSettings);
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
SqlUsersServiceSettings sqlUsersServiceSettings =
SqlUsersServiceSettings.newHttpJsonBuilder().build();
SqlUsersServiceClient sqlUsersServiceClient =
SqlUsersServiceClient.create(sqlUsersServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Static Methods
create()
public static final SqlUsersServiceClient create()Constructs an instance of SqlUsersServiceClient with default settings.
| Returns | |
|---|---|
| Type | Description |
SqlUsersServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
create(SqlUsersServiceSettings settings)
public static final SqlUsersServiceClient create(SqlUsersServiceSettings settings)Constructs an instance of SqlUsersServiceClient, 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 |
SqlUsersServiceSettings |
| Returns | |
|---|---|
| Type | Description |
SqlUsersServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
create(SqlUsersServiceStub stub)
public static final SqlUsersServiceClient create(SqlUsersServiceStub stub)Constructs an instance of SqlUsersServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(SqlUsersServiceSettings).
| Parameter | |
|---|---|
| Name | Description |
stub |
SqlUsersServiceStub |
| Returns | |
|---|---|
| Type | Description |
SqlUsersServiceClient |
|
Constructors
SqlUsersServiceClient(SqlUsersServiceSettings settings)
protected SqlUsersServiceClient(SqlUsersServiceSettings settings)Constructs an instance of SqlUsersServiceClient, 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 |
SqlUsersServiceSettings |
SqlUsersServiceClient(SqlUsersServiceStub stub)
protected SqlUsersServiceClient(SqlUsersServiceStub stub)| Parameter | |
|---|---|
| Name | Description |
stub |
SqlUsersServiceStub |
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()delete(SqlUsersDeleteRequest request)
public final Operation delete(SqlUsersDeleteRequest request)Deletes a user from 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersDeleteRequest request =
SqlUsersDeleteRequest.newBuilder()
.setHost("host3208616")
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.build();
Operation response = sqlUsersServiceClient.delete(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlUsersDeleteRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
deleteCallable()
public final UnaryCallable<SqlUsersDeleteRequest,Operation> deleteCallable()Deletes a user from 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersDeleteRequest request =
SqlUsersDeleteRequest.newBuilder()
.setHost("host3208616")
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.build();
ApiFuture<Operation> future = sqlUsersServiceClient.deleteCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlUsersDeleteRequest,Operation> |
|
get(SqlUsersGetRequest request)
public final User get(SqlUsersGetRequest request)Retrieves a resource containing information about a user.
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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersGetRequest request =
SqlUsersGetRequest.newBuilder()
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.setHost("host3208616")
.build();
User response = sqlUsersServiceClient.get(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlUsersGetRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
User |
|
getCallable()
public final UnaryCallable<SqlUsersGetRequest,User> getCallable()Retrieves a resource containing information about a user.
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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersGetRequest request =
SqlUsersGetRequest.newBuilder()
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.setHost("host3208616")
.build();
ApiFuture<User> future = sqlUsersServiceClient.getCallable().futureCall(request);
// Do something.
User response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlUsersGetRequest,User> |
|
getSettings()
public final @Nullable SqlUsersServiceSettings getSettings()| Returns | |
|---|---|
| Type | Description |
@org.jspecify.annotations.Nullable com.google.cloud.sql.v1.SqlUsersServiceSettings |
|
getStub()
public SqlUsersServiceStub getStub()| Returns | |
|---|---|
| Type | Description |
SqlUsersServiceStub |
|
insert(SqlUsersInsertRequest request)
public final Operation insert(SqlUsersInsertRequest request)Creates a new user in 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersInsertRequest request =
SqlUsersInsertRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(User.newBuilder().build())
.build();
Operation response = sqlUsersServiceClient.insert(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlUsersInsertRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
insertCallable()
public final UnaryCallable<SqlUsersInsertRequest,Operation> insertCallable()Creates a new user in 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersInsertRequest request =
SqlUsersInsertRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(User.newBuilder().build())
.build();
ApiFuture<Operation> future = sqlUsersServiceClient.insertCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlUsersInsertRequest,Operation> |
|
isShutdown()
public boolean isShutdown()| Returns | |
|---|---|
| Type | Description |
boolean |
|
isTerminated()
public boolean isTerminated()| Returns | |
|---|---|
| Type | Description |
boolean |
|
list(SqlUsersListRequest request)
public final UsersListResponse list(SqlUsersListRequest request)Lists users in the specified 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersListRequest request =
SqlUsersListRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
UsersListResponse response = sqlUsersServiceClient.list(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlUsersListRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
UsersListResponse |
|
listCallable()
public final UnaryCallable<SqlUsersListRequest,UsersListResponse> listCallable()Lists users in the specified 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersListRequest request =
SqlUsersListRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
ApiFuture<UsersListResponse> future =
sqlUsersServiceClient.listCallable().futureCall(request);
// Do something.
UsersListResponse response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlUsersListRequest,UsersListResponse> |
|
shutdown()
public void shutdown()shutdownNow()
public void shutdownNow()update(SqlUsersUpdateRequest request)
public final Operation update(SqlUsersUpdateRequest request)Updates an existing user in 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersUpdateRequest request =
SqlUsersUpdateRequest.newBuilder()
.setHost("host3208616")
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.addAllDatabaseRoles(new ArrayList<String>())
.setRevokeExistingRoles(true)
.addAllServerRoles(new ArrayList<String>())
.setRevokeExistingServerRoles(true)
.setBody(User.newBuilder().build())
.build();
Operation response = sqlUsersServiceClient.update(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlUsersUpdateRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
updateCallable()
public final UnaryCallable<SqlUsersUpdateRequest,Operation> updateCallable()Updates an existing user in 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 (SqlUsersServiceClient sqlUsersServiceClient = SqlUsersServiceClient.create()) {
SqlUsersUpdateRequest request =
SqlUsersUpdateRequest.newBuilder()
.setHost("host3208616")
.setInstance("instance555127957")
.setName("name3373707")
.setProject("project-309310695")
.addAllDatabaseRoles(new ArrayList<String>())
.setRevokeExistingRoles(true)
.addAllServerRoles(new ArrayList<String>())
.setRevokeExistingServerRoles(true)
.setBody(User.newBuilder().build())
.build();
ApiFuture<Operation> future = sqlUsersServiceClient.updateCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlUsersUpdateRequest,Operation> |
|