GitHub Repository | Product Reference |
Service Description: Each RPC normalizes the partition IDs of the keys in its input entities, and always returns entities with keys with normalized partition IDs. This applies to all keys and entities, including those in values, except keys with both an empty path and an empty or unset partition ID. Normalization of input keys sets the project ID (if not already set) to the project ID from the request.
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.
Static Methods
create()
public static final DatastoreClient create()
Constructs an instance of DatastoreClient with default settings.
Returns | |
---|---|
Type | Description |
DatastoreClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(DatastoreSettings settings)
public static final DatastoreClient create(DatastoreSettings settings)
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.
Parameter | |
---|---|
Name | Description |
settings |
DatastoreSettings |
Returns | |
---|---|
Type | Description |
DatastoreClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(DatastoreStub stub)
public static final DatastoreClient create(DatastoreStub stub)
Constructs an instance of DatastoreClient, using the given stub for making calls. This is for advanced usage - prefer using create(DatastoreSettings).
Parameter | |
---|---|
Name | Description |
stub |
DatastoreStub |
Returns | |
---|---|
Type | Description |
DatastoreClient |
Constructors
DatastoreClient(DatastoreSettings settings)
protected DatastoreClient(DatastoreSettings settings)
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.
Parameter | |
---|---|
Name | Description |
settings |
DatastoreSettings |
DatastoreClient(DatastoreStub stub)
protected DatastoreClient(DatastoreStub stub)
Parameter | |
---|---|
Name | Description |
stub |
DatastoreStub |
Methods
allocateIds(AllocateIdsRequest request)
public final AllocateIdsResponse allocateIds(AllocateIdsRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
AllocateIdsRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
AllocateIdsResponse |
allocateIds(String projectId, List<Key> keys)
public final AllocateIdsResponse allocateIds(String projectId, List<Key> keys)
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 | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
keys |
List<Key> Required. A list of keys with incomplete key paths for which to allocate IDs. No key may be reserved/read-only. |
Returns | |
---|---|
Type | Description |
AllocateIdsResponse |
allocateIdsCallable()
public final 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<AllocateIdsRequest,AllocateIdsResponse> |
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 |
beginTransaction(BeginTransactionRequest request)
public final BeginTransactionResponse beginTransaction(BeginTransactionRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
BeginTransactionRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
BeginTransactionResponse |
beginTransaction(String projectId)
public final BeginTransactionResponse beginTransaction(String projectId)
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);
}
Parameter | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
Returns | |
---|---|
Type | Description |
BeginTransactionResponse |
beginTransactionCallable()
public final 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<BeginTransactionRequest,BeginTransactionResponse> |
close()
public final void close()
commit(CommitRequest request)
public final CommitResponse commit(CommitRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
CommitRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
CommitResponse |
commit(String projectId, CommitRequest.Mode mode, ByteString transaction, List<Mutation> mutations)
public final CommitResponse commit(String projectId, CommitRequest.Mode mode, 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 | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
mode |
CommitRequest.Mode The type of commit to perform. Defaults to |
transaction |
ByteString The identifier of the transaction associated with the commit. A transaction identifier is returned by a call to Datastore.BeginTransaction. |
mutations |
List<Mutation> The mutations to perform. When mode is - When mode is |
Returns | |
---|---|
Type | Description |
CommitResponse |
commit(String projectId, CommitRequest.Mode mode, List<Mutation> mutations)
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 | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
mode |
CommitRequest.Mode The type of commit to perform. Defaults to |
mutations |
List<Mutation> The mutations to perform. When mode is - When mode is |
Returns | |
---|---|
Type | Description |
CommitResponse |
commitCallable()
public final UnaryCallable<CommitRequest,CommitResponse> 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<CommitRequest,CommitResponse> |
getSettings()
public final DatastoreSettings getSettings()
Returns | |
---|---|
Type | Description |
DatastoreSettings |
getStub()
public DatastoreStub getStub()
Returns | |
---|---|
Type | Description |
DatastoreStub |
isShutdown()
public boolean isShutdown()
Returns | |
---|---|
Type | Description |
boolean |
isTerminated()
public boolean isTerminated()
Returns | |
---|---|
Type | Description |
boolean |
lookup(LookupRequest request)
public final LookupResponse lookup(LookupRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
LookupRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
LookupResponse |
lookup(String projectId, ReadOptions readOptions, List<Key> keys)
public final LookupResponse lookup(String projectId, ReadOptions readOptions, List<Key> keys)
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 | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
readOptions |
ReadOptions The options for this lookup request. |
keys |
List<Key> Required. Keys of entities to look up. |
Returns | |
---|---|
Type | Description |
LookupResponse |
lookupCallable()
public final UnaryCallable<LookupRequest,LookupResponse> 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<LookupRequest,LookupResponse> |
reserveIds(ReserveIdsRequest request)
public final ReserveIdsResponse reserveIds(ReserveIdsRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
ReserveIdsRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
ReserveIdsResponse |
reserveIds(String projectId, List<Key> keys)
public final ReserveIdsResponse reserveIds(String projectId, List<Key> keys)
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 | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
keys |
List<Key> Required. A list of keys with complete key paths whose numeric IDs should not be auto-allocated. |
Returns | |
---|---|
Type | Description |
ReserveIdsResponse |
reserveIdsCallable()
public final 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ReserveIdsRequest,ReserveIdsResponse> |
rollback(RollbackRequest request)
public final RollbackResponse rollback(RollbackRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
RollbackRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
RollbackResponse |
rollback(String projectId, ByteString transaction)
public final RollbackResponse rollback(String projectId, 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 | |
---|---|
Name | Description |
projectId |
String Required. The ID of the project against which to make the request. |
transaction |
ByteString Required. The transaction identifier, returned by a call to Datastore.BeginTransaction. |
Returns | |
---|---|
Type | Description |
RollbackResponse |
rollbackCallable()
public final 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<RollbackRequest,RollbackResponse> |
runAggregationQuery(RunAggregationQueryRequest request)
public final RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
RunAggregationQueryRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
RunAggregationQueryResponse |
runAggregationQueryCallable()
public final 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<RunAggregationQueryRequest,RunAggregationQueryResponse> |
runQuery(RunQueryRequest request)
public final RunQueryResponse runQuery(RunQueryRequest request)
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);
}
Parameter | |
---|---|
Name | Description |
request |
RunQueryRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
RunQueryResponse |
runQueryCallable()
public final 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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<RunQueryRequest,RunQueryResponse> |
shutdown()
public void shutdown()
shutdownNow()
public void shutdownNow()