Class DatastoreClient

java.lang.Object
com.google.cloud.datastore.v1.DatastoreClient
All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource, AutoCloseable

@Generated("by gapic-generator-java") public class DatastoreClient extends Object implements com.google.api.gax.core.BackgroundResource
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().

Methods
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.

  • lookup(LookupRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • lookup(String projectId, ReadOptions readOptions, List<Key> keys)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • lookupCallable()

RunQuery

Queries for entities.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • runQuery(RunQueryRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • runQueryCallable()

RunAggregationQuery

Runs an aggregation query.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • runAggregationQuery(RunAggregationQueryRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • runAggregationQueryCallable()

BeginTransaction

Begins a new transaction.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • beginTransaction(BeginTransactionRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • beginTransaction(String projectId)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • beginTransactionCallable()

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.

  • commit(CommitRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • commit(String projectId, CommitRequest.Mode mode, List<Mutation> mutations)

  • commit(String projectId, CommitRequest.Mode mode, ByteString transaction, List<Mutation> mutations)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • commitCallable()

Rollback

Rolls back a transaction.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • rollback(RollbackRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • rollback(String projectId, ByteString transaction)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • rollbackCallable()

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.

  • allocateIds(AllocateIdsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • allocateIds(String projectId, List<Key> keys)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • allocateIdsCallable()

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.

  • reserveIds(ReserveIdsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • reserveIds(String projectId, List<Key> keys)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • reserveIdsCallable()

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 Details

    • DatastoreClient

      protected DatastoreClient(DatastoreSettings settings) throws IOException
      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

      protected DatastoreClient(DatastoreStub stub)
  • Method Details

    • create

      public static final DatastoreClient create() throws IOException
      Constructs an instance of DatastoreClient with default settings.
      Throws:
      IOException
    • create

      public static final DatastoreClient create(DatastoreSettings settings) throws IOException
      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

      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).
    • getSettings

      public final DatastoreSettings getSettings()
    • getStub

      public DatastoreStub getStub()
    • lookup

      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:
      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

      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);
       }
       
      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

      public final com.google.api.gax.rpc.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();
       }
       
    • runQuery

      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);
       }
       
      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

      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);
       }
       
      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

      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);
       }
       
      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

      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);
       }
       
      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

      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);
       }
       
      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

      public final com.google.api.gax.rpc.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();
       }
       
    • 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

      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);
       }
       
      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

      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:
      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

      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);
       }
       
      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

      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:
      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

      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);
       }
       
      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:
      close in interface AutoCloseable
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface com.google.api.gax.core.BackgroundResource
    • isShutdown

      public boolean isShutdown()
      Specified by:
      isShutdown in interface com.google.api.gax.core.BackgroundResource
    • isTerminated

      public boolean isTerminated()
      Specified by:
      isTerminated in interface com.google.api.gax.core.BackgroundResource
    • shutdownNow

      public void shutdownNow()
      Specified by:
      shutdownNow in interface com.google.api.gax.core.BackgroundResource
    • awaitTermination

      public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
      Specified by:
      awaitTermination in interface com.google.api.gax.core.BackgroundResource
      Throws:
      InterruptedException