Class DatastoreClient
- All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource,AutoCloseable
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 (DatastoreClient datastoreClient = DatastoreClient.create()) {
String projectId = "projectId-894832108";
ReadOptions readOptions = ReadOptions.newBuilder().build();
List<Key> keys = new ArrayList<>();
LookupResponse response = datastoreClient.lookup(projectId, readOptions, keys);
}
Note: close() needs to be called on the DatastoreClient 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 |
|---|---|---|
Lookup |
Looks up entities by key. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
RunQuery |
Queries for entities. |
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.
|
RunAggregationQuery |
Runs an aggregation query. |
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.
|
BeginTransaction |
Begins a new transaction. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
Commit |
Commits a transaction, optionally creating, deleting or modifying some entities. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
Rollback |
Rolls back a transaction. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
AllocateIds |
Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ReserveIds |
Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
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 DatastoreSettings 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
DatastoreSettings datastoreSettings =
DatastoreSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
DatastoreClient datastoreClient = DatastoreClient.create(datastoreSettings);
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
DatastoreSettings datastoreSettings =
DatastoreSettings.newBuilder().setEndpoint(myEndpoint).build();
DatastoreClient datastoreClient = DatastoreClient.create(datastoreSettings);
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
DatastoreSettings datastoreSettings = DatastoreSettings.newHttpJsonBuilder().build();
DatastoreClient datastoreClient = DatastoreClient.create(datastoreSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDatastoreClient(DatastoreSettings settings) Constructs an instance of DatastoreClient, using the given settings.protectedDatastoreClient(DatastoreStub stub) -
Method Summary
Modifier and TypeMethodDescriptionfinal AllocateIdsResponseallocateIds(AllocateIdsRequest request) Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.final AllocateIdsResponseallocateIds(String projectId, List<Key> keys) Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.final com.google.api.gax.rpc.UnaryCallable<AllocateIdsRequest,AllocateIdsResponse> Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.booleanawaitTermination(long duration, TimeUnit unit) final BeginTransactionResponsebeginTransaction(BeginTransactionRequest request) Begins a new transaction.final BeginTransactionResponsebeginTransaction(String projectId) Begins a new transaction.final com.google.api.gax.rpc.UnaryCallable<BeginTransactionRequest,BeginTransactionResponse> Begins a new transaction.final voidclose()final CommitResponsecommit(CommitRequest request) Commits a transaction, optionally creating, deleting or modifying some entities.final CommitResponsecommit(String projectId, CommitRequest.Mode mode, com.google.protobuf.ByteString transaction, List<Mutation> mutations) Commits a transaction, optionally creating, deleting or modifying some entities.final CommitResponsecommit(String projectId, CommitRequest.Mode mode, List<Mutation> mutations) Commits a transaction, optionally creating, deleting or modifying some entities.final com.google.api.gax.rpc.UnaryCallable<CommitRequest,CommitResponse> Commits a transaction, optionally creating, deleting or modifying some entities.static final DatastoreClientcreate()Constructs an instance of DatastoreClient with default settings.static final DatastoreClientcreate(DatastoreSettings settings) Constructs an instance of DatastoreClient, using the given settings.static final DatastoreClientcreate(DatastoreStub stub) Constructs an instance of DatastoreClient, using the given stub for making calls.final DatastoreSettingsgetStub()booleanbooleanfinal LookupResponselookup(LookupRequest request) Looks up entities by key.final LookupResponselookup(String projectId, ReadOptions readOptions, List<Key> keys) Looks up entities by key.final com.google.api.gax.rpc.UnaryCallable<LookupRequest,LookupResponse> Looks up entities by key.final ReserveIdsResponsereserveIds(ReserveIdsRequest request) Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.final ReserveIdsResponsereserveIds(String projectId, List<Key> keys) Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.final com.google.api.gax.rpc.UnaryCallable<ReserveIdsRequest,ReserveIdsResponse> Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.final RollbackResponserollback(RollbackRequest request) Rolls back a transaction.final RollbackResponseRolls back a transaction.final com.google.api.gax.rpc.UnaryCallable<RollbackRequest,RollbackResponse> Rolls back a transaction.Runs an aggregation query.final com.google.api.gax.rpc.UnaryCallable<RunAggregationQueryRequest,RunAggregationQueryResponse> Runs an aggregation query.final RunQueryResponserunQuery(RunQueryRequest request) Queries for entities.final com.google.api.gax.rpc.UnaryCallable<RunQueryRequest,RunQueryResponse> Queries for entities.voidshutdown()void
-
Constructor Details
-
DatastoreClient
Constructs an instance of DatastoreClient, 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.- Throws:
IOException
-
DatastoreClient
-
-
Method Details
-
create
Constructs an instance of DatastoreClient with default settings.- Throws:
IOException
-
create
Constructs an instance of DatastoreClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.- Throws:
IOException
-
create
Constructs an instance of DatastoreClient, using the given stub for making calls. This is for advanced usage - prefer using create(DatastoreSettings). -
getSettings
-
getStub
-
lookup
Looks up entities by key.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; ReadOptions readOptions = ReadOptions.newBuilder().build(); List<Key> keys = new ArrayList<>(); LookupResponse response = datastoreClient.lookup(projectId, readOptions, keys); }- Parameters:
projectId- Required. The ID of the project against which to make the request.readOptions- The options for this lookup request.keys- Required. Keys of entities to look up.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
lookup
Looks up entities by key.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { LookupRequest request = LookupRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setReadOptions(ReadOptions.newBuilder().build()) .addAllKeys(new ArrayList<Key>()) .setPropertyMask(PropertyMask.newBuilder().build()) .build(); LookupResponse response = datastoreClient.lookup(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
lookupCallable
Looks up entities by key.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { LookupRequest request = LookupRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setReadOptions(ReadOptions.newBuilder().build()) .addAllKeys(new ArrayList<Key>()) .setPropertyMask(PropertyMask.newBuilder().build()) .build(); ApiFuture<LookupResponse> future = datastoreClient.lookupCallable().futureCall(request); // Do something. LookupResponse response = future.get(); } -
runQuery
Queries for entities.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { RunQueryRequest request = RunQueryRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setPartitionId(PartitionId.newBuilder().build()) .setReadOptions(ReadOptions.newBuilder().build()) .setPropertyMask(PropertyMask.newBuilder().build()) .setExplainOptions(ExplainOptions.newBuilder().build()) .build(); RunQueryResponse response = datastoreClient.runQuery(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
runQueryCallable
public final com.google.api.gax.rpc.UnaryCallable<RunQueryRequest,RunQueryResponse> runQueryCallable()Queries for entities.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { RunQueryRequest request = RunQueryRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setPartitionId(PartitionId.newBuilder().build()) .setReadOptions(ReadOptions.newBuilder().build()) .setPropertyMask(PropertyMask.newBuilder().build()) .setExplainOptions(ExplainOptions.newBuilder().build()) .build(); ApiFuture<RunQueryResponse> future = datastoreClient.runQueryCallable().futureCall(request); // Do something. RunQueryResponse response = future.get(); } -
runAggregationQuery
Runs an aggregation query.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { RunAggregationQueryRequest request = RunAggregationQueryRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setPartitionId(PartitionId.newBuilder().build()) .setReadOptions(ReadOptions.newBuilder().build()) .setExplainOptions(ExplainOptions.newBuilder().build()) .build(); RunAggregationQueryResponse response = datastoreClient.runAggregationQuery(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
runAggregationQueryCallable
public final com.google.api.gax.rpc.UnaryCallable<RunAggregationQueryRequest,RunAggregationQueryResponse> runAggregationQueryCallable()Runs an aggregation query.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { RunAggregationQueryRequest request = RunAggregationQueryRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setPartitionId(PartitionId.newBuilder().build()) .setReadOptions(ReadOptions.newBuilder().build()) .setExplainOptions(ExplainOptions.newBuilder().build()) .build(); ApiFuture<RunAggregationQueryResponse> future = datastoreClient.runAggregationQueryCallable().futureCall(request); // Do something. RunAggregationQueryResponse response = future.get(); } -
beginTransaction
Begins a new transaction.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; BeginTransactionResponse response = datastoreClient.beginTransaction(projectId); }- Parameters:
projectId- Required. The ID of the project against which to make the request.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
beginTransaction
Begins a new transaction.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { BeginTransactionRequest request = BeginTransactionRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setTransactionOptions(TransactionOptions.newBuilder().build()) .build(); BeginTransactionResponse response = datastoreClient.beginTransaction(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
beginTransactionCallable
public final com.google.api.gax.rpc.UnaryCallable<BeginTransactionRequest,BeginTransactionResponse> beginTransactionCallable()Begins a new transaction.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { BeginTransactionRequest request = BeginTransactionRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setTransactionOptions(TransactionOptions.newBuilder().build()) .build(); ApiFuture<BeginTransactionResponse> future = datastoreClient.beginTransactionCallable().futureCall(request); // Do something. BeginTransactionResponse response = future.get(); } -
commit
public final CommitResponse commit(String projectId, CommitRequest.Mode mode, List<Mutation> mutations) Commits a transaction, optionally creating, deleting or modifying some entities.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); List<Mutation> mutations = new ArrayList<>(); CommitResponse response = datastoreClient.commit(projectId, mode, mutations); }- Parameters:
projectId- Required. The ID of the project against which to make the request.mode- The type of commit to perform. Defaults to `TRANSACTIONAL`.mutations- The mutations to perform.When mode is `TRANSACTIONAL`, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single `Commit` request:
- `insert` followed by `insert` - `update` followed by `insert` - `upsert` followed by `insert` - `delete` followed by `update`
When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single entity.
- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
commit
public final CommitResponse commit(String projectId, CommitRequest.Mode mode, com.google.protobuf.ByteString transaction, List<Mutation> mutations) Commits a transaction, optionally creating, deleting or modifying some entities.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); ByteString transaction = ByteString.EMPTY; List<Mutation> mutations = new ArrayList<>(); CommitResponse response = datastoreClient.commit(projectId, mode, transaction, mutations); }- Parameters:
projectId- Required. The ID of the project against which to make the request.mode- The type of commit to perform. Defaults to `TRANSACTIONAL`.transaction- The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].mutations- The mutations to perform.When mode is `TRANSACTIONAL`, mutations affecting a single entity are applied in order. The following sequences of mutations affecting a single entity are not permitted in a single `Commit` request:
- `insert` followed by `insert` - `update` followed by `insert` - `upsert` followed by `insert` - `delete` followed by `update`
When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single entity.
- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
commit
Commits a transaction, optionally creating, deleting or modifying some entities.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { CommitRequest request = CommitRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .addAllMutations(new ArrayList<Mutation>()) .build(); CommitResponse response = datastoreClient.commit(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
commitCallable
Commits a transaction, optionally creating, deleting or modifying some entities.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { CommitRequest request = CommitRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .addAllMutations(new ArrayList<Mutation>()) .build(); ApiFuture<CommitResponse> future = datastoreClient.commitCallable().futureCall(request); // Do something. CommitResponse response = future.get(); } -
rollback
public final RollbackResponse rollback(String projectId, com.google.protobuf.ByteString transaction) Rolls back a transaction.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; ByteString transaction = ByteString.EMPTY; RollbackResponse response = datastoreClient.rollback(projectId, transaction); }- Parameters:
projectId- Required. The ID of the project against which to make the request.transaction- Required. The transaction identifier, returned by a call to [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
rollback
Rolls back a transaction.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { RollbackRequest request = RollbackRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setTransaction(ByteString.EMPTY) .build(); RollbackResponse response = datastoreClient.rollback(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
rollbackCallable
public final com.google.api.gax.rpc.UnaryCallable<RollbackRequest,RollbackResponse> rollbackCallable()Rolls back a transaction.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { RollbackRequest request = RollbackRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .setTransaction(ByteString.EMPTY) .build(); ApiFuture<RollbackResponse> future = datastoreClient.rollbackCallable().futureCall(request); // Do something. RollbackResponse response = future.get(); } -
allocateIds
Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; List<Key> keys = new ArrayList<>(); AllocateIdsResponse response = datastoreClient.allocateIds(projectId, keys); }- Parameters:
projectId- Required. The ID of the project against which to make the request.keys- Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
allocateIds
Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { AllocateIdsRequest request = AllocateIdsRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .addAllKeys(new ArrayList<Key>()) .build(); AllocateIdsResponse response = datastoreClient.allocateIds(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
allocateIdsCallable
public final com.google.api.gax.rpc.UnaryCallable<AllocateIdsRequest,AllocateIdsResponse> allocateIdsCallable()Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { AllocateIdsRequest request = AllocateIdsRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .addAllKeys(new ArrayList<Key>()) .build(); ApiFuture<AllocateIdsResponse> future = datastoreClient.allocateIdsCallable().futureCall(request); // Do something. AllocateIdsResponse response = future.get(); } -
reserveIds
Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { String projectId = "projectId-894832108"; List<Key> keys = new ArrayList<>(); ReserveIdsResponse response = datastoreClient.reserveIds(projectId, keys); }- Parameters:
projectId- Required. The ID of the project against which to make the request.keys- Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
reserveIds
Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { ReserveIdsRequest request = ReserveIdsRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .addAllKeys(new ArrayList<Key>()) .build(); ReserveIdsResponse response = datastoreClient.reserveIds(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
reserveIdsCallable
public final com.google.api.gax.rpc.UnaryCallable<ReserveIdsRequest,ReserveIdsResponse> reserveIdsCallable()Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.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 (DatastoreClient datastoreClient = DatastoreClient.create()) { ReserveIdsRequest request = ReserveIdsRequest.newBuilder() .setProjectId("projectId-894832108") .setDatabaseId("databaseId1688905718") .addAllKeys(new ArrayList<Key>()) .build(); ApiFuture<ReserveIdsResponse> future = datastoreClient.reserveIdsCallable().futureCall(request); // Do something. ReserveIdsResponse response = future.get(); } -
close
public final void close()- Specified by:
closein interfaceAutoCloseable
-
shutdown
public void shutdown()- Specified by:
shutdownin interfacecom.google.api.gax.core.BackgroundResource
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfacecom.google.api.gax.core.BackgroundResource
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfacecom.google.api.gax.core.BackgroundResource
-
shutdownNow
public void shutdownNow()- Specified by:
shutdownNowin interfacecom.google.api.gax.core.BackgroundResource
-
awaitTermination
- Specified by:
awaitTerminationin interfacecom.google.api.gax.core.BackgroundResource- Throws:
InterruptedException
-