Skip to content

Commit f1311d9

Browse files
feat(datastore): add support for request tags
1 parent 6aec127 commit f1311d9

10 files changed

Lines changed: 573 additions & 84 deletions

File tree

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.google.api.core.InternalExtensionOnly;
2121
import com.google.cloud.Service;
2222
import com.google.cloud.datastore.models.ExplainOptions;
23+
import com.google.common.collect.ImmutableList;
24+
import com.google.datastore.v1.RequestOptions;
2325
import com.google.datastore.v1.TransactionOptions;
2426
import java.util.Iterator;
2527
import java.util.List;
@@ -492,6 +494,30 @@ interface TransactionCallable<T> {
492494
@BetaApi
493495
<T> QueryResults<T> run(Query<T> query, ExplainOptions explainOptions, ReadOption... options);
494496

497+
/**
498+
* Submits a {@link Query} with specified {@link com.google.datastore.v1.RequestOptions} and
499+
* returns its result.
500+
*/
501+
<T> QueryResults<T> run(Query<T> query, RequestOptions requestOptions);
502+
503+
/**
504+
* Submits a {@link Query} with specified {@link com.google.datastore.v1.RequestOptions} and
505+
* returns its result. {@link ReadOption}s can be specified if desired.
506+
*/
507+
<T> QueryResults<T> run(Query<T> query, RequestOptions requestOptions, ReadOption... options);
508+
509+
/**
510+
* Submits a {@link Query} with specified {@link com.google.cloud.datastore.models.ExplainOptions}
511+
* and {@link com.google.datastore.v1.RequestOptions} and returns its result. {@link ReadOption}s
512+
* can be specified if desired.
513+
*/
514+
@BetaApi
515+
<T> QueryResults<T> run(
516+
Query<T> query,
517+
ExplainOptions explainOptions,
518+
RequestOptions requestOptions,
519+
ReadOption... options);
520+
495521
/**
496522
* Submits a {@link AggregationQuery} and returns {@link AggregationResults}. {@link ReadOption}s
497523
* can be specified if desired.
@@ -537,6 +563,20 @@ interface TransactionCallable<T> {
537563
*/
538564
AggregationResults runAggregation(AggregationQuery query, ReadOption... options);
539565

566+
/**
567+
* Submits an {@link AggregationQuery} with specified {@link
568+
* com.google.datastore.v1.RequestOptions} and returns {@link AggregationResults}.
569+
*/
570+
AggregationResults runAggregation(AggregationQuery query, RequestOptions requestOptions);
571+
572+
/**
573+
* Submits an {@link AggregationQuery} with specified {@link
574+
* com.google.datastore.v1.RequestOptions} and returns {@link AggregationResults}. {@link
575+
* ReadOption}s can be specified if desired.
576+
*/
577+
AggregationResults runAggregation(
578+
AggregationQuery query, RequestOptions requestOptions, ReadOption... options);
579+
540580
/**
541581
* Submits a {@link AggregationQuery} with specified {@link
542582
* com.google.cloud.datastore.models.ExplainOptions} and returns {@link AggregationResults}.
@@ -564,6 +604,28 @@ interface TransactionCallable<T> {
564604
AggregationResults runAggregation(
565605
AggregationQuery query, ExplainOptions explainOptions, ReadOption... options);
566606

607+
/**
608+
* Submits an {@link AggregationQuery} with specified {@link
609+
* com.google.cloud.datastore.models.ExplainOptions} and {@link
610+
* com.google.datastore.v1.RequestOptions} and returns {@link AggregationResults}.
611+
*/
612+
@BetaApi
613+
AggregationResults runAggregation(
614+
AggregationQuery query, ExplainOptions explainOptions, RequestOptions requestOptions);
615+
616+
/**
617+
* Submits an {@link AggregationQuery} with specified {@link
618+
* com.google.cloud.datastore.models.ExplainOptions} and {@link
619+
* com.google.datastore.v1.RequestOptions} and returns {@link AggregationResults}. {@link
620+
* ReadOption}s can be specified if desired.
621+
*/
622+
@BetaApi
623+
AggregationResults runAggregation(
624+
AggregationQuery query,
625+
ExplainOptions explainOptions,
626+
RequestOptions requestOptions,
627+
ReadOption... options);
628+
567629
/**
568630
* Closes the gRPC channels associated with this instance and frees up their resources. This
569631
* method blocks until all channels are closed. Once this method is called, this Datastore client
@@ -574,4 +636,27 @@ AggregationResults runAggregation(
574636

575637
/** Returns true if this background resource has been shut down. */
576638
boolean isClosed();
639+
640+
/**
641+
* Returns a new Datastore client with the specified request tags added.
642+
*
643+
* @param requestTags the request tags to append to existing ones
644+
*/
645+
default Datastore withRequestTags(String... requestTags) {
646+
ImmutableList.Builder<String> builder = ImmutableList.builder();
647+
builder.addAll(getOptions().getRequestTags()).add(requestTags);
648+
return getOptions().toBuilder().setTags(builder.build()).build().getService();
649+
}
650+
651+
/**
652+
* Returns a new Datastore client with the specified request tags added.
653+
*
654+
* @param requestTags the request tags to append to existing ones
655+
*/
656+
default Datastore withRequestTags(List<String> requestTags) {
657+
ImmutableList.Builder<String> builder = ImmutableList.builder();
658+
builder.addAll(getOptions().getRequestTags());
659+
builder.addAll(requestTags);
660+
return getOptions().toBuilder().setTags(builder.build()).build().getService();
661+
}
577662
}

0 commit comments

Comments
 (0)