Repository: googleapis/java-datastore
Pull request #1283 (2024-01-08 16:23:18)

refactor: rename internal class QueryAndReadOptions to QueryConfig
cherry pick of #1245


Patch:
diff --git a/google-cloud-datastore/clirr-ignored-differences.xml b/google-cloud-datastore/clirr-ignored-differences.xml
index f80562fb..9972e93e 100644
--- a/google-cloud-datastore/clirr-ignored-differences.xml
+++ b/google-cloud-datastore/clirr-ignored-differences.xml
@@ -1,30 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- see http://mojo.codehaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
 <differences>
+    <!-- renaming internal only class-->
     <difference>
-        <className>com/google/cloud/datastore/Datastore</className>
-        <method>java.util.List reserveIds(com.google.cloud.datastore.Key[])</method>
-        <differenceType>7012</differenceType>
-    </difference>
-    <difference>
-        <className>com/google/cloud/datastore/spi/v1/DatastoreRpc</className>
-        <method>com.google.datastore.v1.ReserveIdsResponse reserveIds(com.google.datastore.v1.ReserveIdsRequest)</method>
-        <differenceType>7012</differenceType>
+        <className>com/google/cloud/datastore/ReadOption$QueryAndReadOptions</className>
+        <method>*</method>
+        <differenceType>8001</differenceType>
     </difference>
     <difference>
-        <className>com/google/cloud/datastore/spi/v1/DatastoreRpc</className>
-        <method>com.google.datastore.v1.RunAggregationQueryResponse runAggregationQuery(com.google.datastore.v1.RunAggregationQueryRequest)</method>
-        <differenceType>7012</differenceType>
-    </difference>
-    <difference>
-        <className>com/google/cloud/datastore/Datastore</className>
-        <method>com.google.cloud.datastore.AggregationResults runAggregation(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.ReadOption[])</method>
-        <differenceType>7012</differenceType>
-    </difference>
-    <difference>
-        <className>com/google/cloud/datastore/DatastoreReader</className>
-        <method>com.google.cloud.datastore.AggregationResults runAggregation(com.google.cloud.datastore.AggregationQuery)</method>
-        <differenceType>7012</differenceType>
+        <className>com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer</className>
+        <method>*QueryAndReadOptions*</method>
+        <to>*QueryConfig*</to>
+        <differenceType>7005</differenceType>
     </difference>
     <difference>
         <!-- Added BaseGrpcServiceException as a superclass -->
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ReadOption.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ReadOption.java
index be5644da..c249e45a 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ReadOption.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ReadOption.java
@@ -142,17 +142,17 @@ public abstract class ReadOption implements Serializable {
   }
 
   @InternalApi
-  public static class QueryAndReadOptions<Q extends Query<?>> {
+  public static class QueryConfig<Q extends Query<?>> {
 
     Q query;
     List<ReadOption> readOptions;
 
-    private QueryAndReadOptions(Q query, List<ReadOption> readOptions) {
+    private QueryConfig(Q query, List<ReadOption> readOptions) {
       this.query = query;
       this.readOptions = readOptions;
     }
 
-    private QueryAndReadOptions(Q query) {
+    private QueryConfig(Q query) {
       this.query = query;
       this.readOptions = Collections.emptyList();
     }
@@ -165,13 +165,13 @@ public abstract class ReadOption implements Serializable {
       return readOptions;
     }
 
-    public static <Q extends Query<?>> QueryAndReadOptions<Q> create(Q query) {
-      return new QueryAndReadOptions<>(query);
+    public static <Q extends Query<?>> QueryConfig<Q> create(Q query) {
+      return new QueryConfig<>(query);
     }
 
-    public static <Q extends Query<?>> QueryAndReadOptions<Q> create(
+    public static <Q extends Query<?>> QueryConfig<Q> create(
         Q query, List<ReadOption> readOptions) {
-      return new QueryAndReadOptions<>(query, readOptions);
+      return new QueryConfig<>(query, readOptions);
     }
   }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/AggregationQueryExecutor.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/AggregationQueryExecutor.java
index 14e42584..5a1fdd2c 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/AggregationQueryExecutor.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/AggregationQueryExecutor.java
@@ -20,7 +20,7 @@ import com.google.cloud.datastore.AggregationQuery;
 import com.google.cloud.datastore.AggregationResults;
 import com.google.cloud.datastore.DatastoreOptions;
 import com.google.cloud.datastore.ReadOption;
-import com.google.cloud.datastore.ReadOption.QueryAndReadOptions;
+import com.google.cloud.datastore.ReadOption.QueryConfig;
 import com.google.cloud.datastore.execution.request.AggregationQueryRequestProtoPreparer;
 import com.google.cloud.datastore.execution.response.AggregationQueryResponseTransformer;
 import com.google.cloud.datastore.spi.v1.DatastoreRpc;
@@ -57,10 +57,10 @@ public class AggregationQueryExecutor
 
   private RunAggregationQueryRequest getRunAggregationQueryRequest(
       AggregationQuery query, ReadOption... readOptions) {
-    QueryAndReadOptions<AggregationQuery> queryAndReadOptions =
+    QueryConfig<AggregationQuery> queryConfig =
         readOptions == null
-            ? QueryAndReadOptions.create(query)
-            : QueryAndReadOptions.create(query, Arrays.asList(readOptions));
-    return this.protoPreparer.prepare(queryAndReadOptions);
+            ? QueryConfig.create(query)
+            : QueryConfig.create(query, Arrays.asList(readOptions));
+    return this.protoPreparer.prepare(queryConfig);
   }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer.java
index 5c4fb3e5..475a47b5 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer.java
@@ -22,7 +22,7 @@ import com.google.cloud.datastore.AggregationQuery;
 import com.google.cloud.datastore.DatastoreOptions;
 import com.google.cloud.datastore.GqlQueryProtoPreparer;
 import com.google.cloud.datastore.ReadOption;
-import com.google.cloud.datastore.ReadOption.QueryAndReadOptions;
+import com.google.cloud.datastore.ReadOption.QueryConfig;
 import com.google.cloud.datastore.ReadOptionProtoPreparer;
 import com.google.cloud.datastore.StructuredQueryProtoPreparer;
 import com.google.cloud.datastore.aggregation.Aggregation;
@@ -37,7 +37,7 @@ import java.util.Optional;
 
 @InternalApi
 public class AggregationQueryRequestProtoPreparer
-    implements ProtoPreparer<QueryAndReadOptions<AggregationQuery>, RunAggregationQueryRequest> {
+    implements ProtoPreparer<QueryConfig<AggregationQuery>, RunAggregationQueryRequest> {
 
   private final DatastoreOptions datastoreOptions;
   private final StructuredQueryProtoPreparer structuredQueryProtoPreparer;
@@ -52,10 +52,9 @@ public class AggregationQueryRequestProtoPreparer
   }
 
   @Override
-  public RunAggregationQueryRequest prepare(
-      QueryAndReadOptions<AggregationQuery> aggregationQueryAndReadOptions) {
-    AggregationQuery aggregationQuery = aggregationQueryAndReadOptions.getQuery();
-    List<ReadOption> readOptions = aggregationQueryAndReadOptions.getReadOptions();
+  public RunAggregationQueryRequest prepare(QueryConfig<AggregationQuery> queryConfig) {
+    AggregationQuery aggregationQuery = queryConfig.getQuery();
+    List<ReadOption> readOptions = queryConfig.getReadOptions();
     PartitionId partitionId = getPartitionId(aggregationQuery);
     RunAggregationQueryRequest.Builder aggregationQueryRequestBuilder =
         RunAggregationQueryRequest.newBuilder()


Test patch:
diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparerTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparerTest.java
index 5fbb35b6..0f22828d 100644
--- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparerTest.java
+++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparerTest.java
@@ -38,7 +38,7 @@ import com.google.cloud.datastore.EntityQuery;
 import com.google.cloud.datastore.GqlQuery;
 import com.google.cloud.datastore.Query;
 import com.google.cloud.datastore.ReadOption;
-import com.google.cloud.datastore.ReadOption.QueryAndReadOptions;
+import com.google.cloud.datastore.ReadOption.QueryConfig;
 import com.google.common.collect.ImmutableMap;
 import com.google.datastore.v1.RunAggregationQueryRequest;
 import java.util.HashMap;
@@ -91,7 +91,7 @@ public class AggregationQueryRequestProtoPreparerTest {
   @Test
   public void shouldPrepareAggregationQueryRequestWithGivenStructuredQuery() {
     RunAggregationQueryRequest runAggregationQueryRequest =
-        protoPreparer.prepare(QueryAndReadOptions.create(AGGREGATION_OVER_STRUCTURED_QUERY));
+        protoPreparer.prepare(QueryConfig.create(AGGREGATION_OVER_STRUCTURED_QUERY));
 
     assertThat(runAggregationQueryRequest.getProjectId()).isEqualTo(PROJECT_ID);
     assertThat(runAggregationQueryRequest.getDatabaseId()).isEqualTo(DATABASE_ID);
@@ -114,7 +114,7 @@ public class AggregationQueryRequestProtoPreparerTest {
   @Test
   public void shouldPrepareAggregationQueryRequestWithGivenGqlQuery() {
     RunAggregationQueryRequest runAggregationQueryRequest =
-        protoPreparer.prepare(QueryAndReadOptions.create(AGGREGATION_OVER_GQL_QUERY));
+        protoPreparer.prepare(QueryConfig.create(AGGREGATION_OVER_GQL_QUERY));
 
     assertThat(runAggregationQueryRequest.getProjectId()).isEqualTo(PROJECT_ID);
     assertThat(runAggregationQueryRequest.getDatabaseId()).isEqualTo(DATABASE_ID);
@@ -172,9 +172,9 @@ public class AggregationQueryRequestProtoPreparerTest {
         Query.newAggregationQueryBuilder().over(COMPLETED_TASK_GQL_QUERY).build();
 
     RunAggregationQueryRequest runAggregationQueryFromStructuredQuery =
-        protoPreparer.prepare(QueryAndReadOptions.create(structuredQueryWithoutNamespace));
+        protoPreparer.prepare(QueryConfig.create(structuredQueryWithoutNamespace));
     RunAggregationQueryRequest runAggregationQueryFromGqlQuery =
-        protoPreparer.prepare(QueryAndReadOptions.create(gqlQueryWithoutNamespace));
+        protoPreparer.prepare(QueryConfig.create(gqlQueryWithoutNamespace));
 
     assertThat(runAggregationQueryFromStructuredQuery.getPartitionId().getNamespaceId())
         .isEqualTo(NAMESPACE);
@@ -183,6 +183,6 @@ public class AggregationQueryRequestProtoPreparerTest {
   }
 
   private RunAggregationQueryRequest prepareQuery(AggregationQuery query, ReadOption readOption) {
-    return protoPreparer.prepare(QueryAndReadOptions.create(query, singletonList(readOption)));
+    return protoPreparer.prepare(QueryConfig.create(query, singletonList(readOption)));
   }
 }