diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java index 8e2bc0f78852..2ae9c150b3d9 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java @@ -25,18 +25,20 @@ import com.google.api.gax.paging.AbstractPagedListResponse; import com.google.api.gax.rpc.PageContext; import com.google.api.gax.rpc.UnaryCallable; -import com.google.api.pathtemplate.PathTemplate; import com.google.cloud.firestore.v1.stub.FirestoreAdminStub; import com.google.cloud.firestore.v1.stub.FirestoreAdminStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.firestore.admin.v1.CreateIndexRequest; +import com.google.firestore.admin.v1.DatabaseName; import com.google.firestore.admin.v1.DeleteIndexRequest; import com.google.firestore.admin.v1.ExportDocumentsRequest; import com.google.firestore.admin.v1.Field; +import com.google.firestore.admin.v1.FieldName; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; +import com.google.firestore.admin.v1.IndexName; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; @@ -60,7 +62,7 @@ *
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* Index index = Index.newBuilder().build();
* Operation response = firestoreAdminClient.createIndex(formattedParent, index);
* }
@@ -123,133 +125,6 @@ public class FirestoreAdminClient implements BackgroundResource {
private final FirestoreAdminSettings settings;
private final FirestoreAdminStub stub;
- private static final PathTemplate DATABASE_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding("projects/{project}/databases/{database}");
-
- private static final PathTemplate PARENT_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/collectionGroups/{collection_id}");
-
- private static final PathTemplate INDEX_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/collectionGroups/{collection_id}/indexes/{index_id}");
-
- private static final PathTemplate FIELD_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/collectionGroups/{collection_id}/fields/{field_id}");
-
- /** Formats a string containing the fully-qualified path to represent a database resource. */
- public static final String formatDatabaseName(String project, String database) {
- return DATABASE_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database);
- }
-
- /** Formats a string containing the fully-qualified path to represent a parent resource. */
- public static final String formatParentName(
- String project, String database, String collectionId) {
- return PARENT_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "collection_id", collectionId);
- }
-
- /** Formats a string containing the fully-qualified path to represent a index resource. */
- public static final String formatIndexName(
- String project, String database, String collectionId, String indexId) {
- return INDEX_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "collection_id", collectionId,
- "index_id", indexId);
- }
-
- /** Formats a string containing the fully-qualified path to represent a field resource. */
- public static final String formatFieldName(
- String project, String database, String collectionId, String fieldId) {
- return FIELD_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "collection_id", collectionId,
- "field_id", fieldId);
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a database resource.
- */
- public static final String parseProjectFromDatabaseName(String databaseName) {
- return DATABASE_PATH_TEMPLATE.parse(databaseName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a database resource.
- */
- public static final String parseDatabaseFromDatabaseName(String databaseName) {
- return DATABASE_PATH_TEMPLATE.parse(databaseName).get("database");
- }
-
- /** Parses the project from the given fully-qualified path which represents a parent resource. */
- public static final String parseProjectFromParentName(String parentName) {
- return PARENT_PATH_TEMPLATE.parse(parentName).get("project");
- }
-
- /** Parses the database from the given fully-qualified path which represents a parent resource. */
- public static final String parseDatabaseFromParentName(String parentName) {
- return PARENT_PATH_TEMPLATE.parse(parentName).get("database");
- }
-
- /**
- * Parses the collection_id from the given fully-qualified path which represents a parent
- * resource.
- */
- public static final String parseCollectionIdFromParentName(String parentName) {
- return PARENT_PATH_TEMPLATE.parse(parentName).get("collection_id");
- }
-
- /** Parses the project from the given fully-qualified path which represents a index resource. */
- public static final String parseProjectFromIndexName(String indexName) {
- return INDEX_PATH_TEMPLATE.parse(indexName).get("project");
- }
-
- /** Parses the database from the given fully-qualified path which represents a index resource. */
- public static final String parseDatabaseFromIndexName(String indexName) {
- return INDEX_PATH_TEMPLATE.parse(indexName).get("database");
- }
-
- /**
- * Parses the collection_id from the given fully-qualified path which represents a index resource.
- */
- public static final String parseCollectionIdFromIndexName(String indexName) {
- return INDEX_PATH_TEMPLATE.parse(indexName).get("collection_id");
- }
-
- /** Parses the index_id from the given fully-qualified path which represents a index resource. */
- public static final String parseIndexIdFromIndexName(String indexName) {
- return INDEX_PATH_TEMPLATE.parse(indexName).get("index_id");
- }
-
- /** Parses the project from the given fully-qualified path which represents a field resource. */
- public static final String parseProjectFromFieldName(String fieldName) {
- return FIELD_PATH_TEMPLATE.parse(fieldName).get("project");
- }
-
- /** Parses the database from the given fully-qualified path which represents a field resource. */
- public static final String parseDatabaseFromFieldName(String fieldName) {
- return FIELD_PATH_TEMPLATE.parse(fieldName).get("database");
- }
-
- /**
- * Parses the collection_id from the given fully-qualified path which represents a field resource.
- */
- public static final String parseCollectionIdFromFieldName(String fieldName) {
- return FIELD_PATH_TEMPLATE.parse(fieldName).get("collection_id");
- }
-
- /** Parses the field_id from the given fully-qualified path which represents a field resource. */
- public static final String parseFieldIdFromFieldName(String fieldName) {
- return FIELD_PATH_TEMPLATE.parse(fieldName).get("field_id");
- }
-
/** Constructs an instance of FirestoreAdminClient with default settings. */
public static final FirestoreAdminClient create() throws IOException {
return create(FirestoreAdminSettings.newBuilder().build());
@@ -309,7 +184,7 @@ public FirestoreAdminStub getStub() {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* Index index = Index.newBuilder().build();
* Operation response = firestoreAdminClient.createIndex(formattedParent, index);
* }
@@ -321,7 +196,7 @@ public FirestoreAdminStub getStub() {
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Operation createIndex(String parent, Index index) {
- PARENT_PATH_TEMPLATE.validate(parent, "createIndex");
+
CreateIndexRequest request =
CreateIndexRequest.newBuilder().setParent(parent).setIndex(index).build();
return createIndex(request);
@@ -338,7 +213,7 @@ public final Operation createIndex(String parent, Index index) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* Index index = Index.newBuilder().build();
* CreateIndexRequest request = CreateIndexRequest.newBuilder()
* .setParent(formattedParent)
@@ -366,7 +241,7 @@ public final Operation createIndex(CreateIndexRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* Index index = Index.newBuilder().build();
* CreateIndexRequest request = CreateIndexRequest.newBuilder()
* .setParent(formattedParent)
@@ -390,7 +265,7 @@ public final UnaryCallable createIndexCallable()
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* for (Index element : firestoreAdminClient.listIndexes(formattedParent).iterateAll()) {
* // doThingsWith(element);
* }
@@ -402,7 +277,6 @@ public final UnaryCallable createIndexCallable()
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListIndexesPagedResponse listIndexes(String parent) {
- PARENT_PATH_TEMPLATE.validate(parent, "listIndexes");
ListIndexesRequest request = ListIndexesRequest.newBuilder().setParent(parent).build();
return listIndexes(request);
}
@@ -415,7 +289,7 @@ public final ListIndexesPagedResponse listIndexes(String parent) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* ListIndexesRequest request = ListIndexesRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -440,7 +314,7 @@ public final ListIndexesPagedResponse listIndexes(ListIndexesRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* ListIndexesRequest request = ListIndexesRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -465,7 +339,7 @@ public final ListIndexesPagedResponse listIndexes(ListIndexesRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* ListIndexesRequest request = ListIndexesRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -496,8 +370,32 @@ public final UnaryCallable listIndexesC
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatIndexName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
- * Index response = firestoreAdminClient.getIndex(formattedName);
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * Index response = firestoreAdminClient.getIndex(name);
+ * }
+ *
+ *
+ * @param name A name of the form
+ * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Index getIndex(IndexName name) {
+
+ GetIndexRequest request =
+ GetIndexRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ return getIndex(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Gets a composite index.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * Index response = firestoreAdminClient.getIndex(name.toString());
* }
*
*
@@ -506,7 +404,7 @@ public final UnaryCallable listIndexesC
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Index getIndex(String name) {
- INDEX_PATH_TEMPLATE.validate(name, "getIndex");
+
GetIndexRequest request = GetIndexRequest.newBuilder().setName(name).build();
return getIndex(request);
}
@@ -519,9 +417,9 @@ public final Index getIndex(String name) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatIndexName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
* GetIndexRequest request = GetIndexRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* Index response = firestoreAdminClient.getIndex(request);
* }
@@ -542,9 +440,9 @@ public final Index getIndex(GetIndexRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatIndexName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
* GetIndexRequest request = GetIndexRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Index> future = firestoreAdminClient.getIndexCallable().futureCall(request);
* // Do something
@@ -564,8 +462,32 @@ public final UnaryCallable getIndexCallable() {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatIndexName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
- * firestoreAdminClient.deleteIndex(formattedName);
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * firestoreAdminClient.deleteIndex(name);
+ * }
+ *
+ *
+ * @param name A name of the form
+ * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteIndex(IndexName name) {
+
+ DeleteIndexRequest request =
+ DeleteIndexRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ deleteIndex(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Deletes a composite index.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * firestoreAdminClient.deleteIndex(name.toString());
* }
*
*
@@ -574,7 +496,7 @@ public final UnaryCallable getIndexCallable() {
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteIndex(String name) {
- INDEX_PATH_TEMPLATE.validate(name, "deleteIndex");
+
DeleteIndexRequest request = DeleteIndexRequest.newBuilder().setName(name).build();
deleteIndex(request);
}
@@ -587,9 +509,9 @@ public final void deleteIndex(String name) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatIndexName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
* DeleteIndexRequest request = DeleteIndexRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* firestoreAdminClient.deleteIndex(request);
* }
@@ -610,9 +532,9 @@ public final void deleteIndex(DeleteIndexRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatIndexName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ * IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
* DeleteIndexRequest request = DeleteIndexRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Void> future = firestoreAdminClient.deleteIndexCallable().futureCall(request);
* // Do something
@@ -635,8 +557,35 @@ public final UnaryCallable deleteIndexCallable() {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
- * Operation response = firestoreAdminClient.importDocuments(formattedName);
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ * Operation response = firestoreAdminClient.importDocuments(name);
+ * }
+ *
+ *
+ * @param name Database to import into. Should be of the form:
+ * `projects/{project_id}/databases/{database_id}`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Operation importDocuments(DatabaseName name) {
+
+ ImportDocumentsRequest request =
+ ImportDocumentsRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ return importDocuments(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Imports documents into Google Cloud Firestore. Existing documents with the same name are
+ * overwritten. The import occurs in the background and its progress can be monitored and managed
+ * via the Operation resource that is created. If an ImportDocuments operation is cancelled, it is
+ * possible that a subset of the data has already been imported to Cloud Firestore.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ * Operation response = firestoreAdminClient.importDocuments(name.toString());
* }
*
*
@@ -645,7 +594,7 @@ public final UnaryCallable deleteIndexCallable() {
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Operation importDocuments(String name) {
- DATABASE_PATH_TEMPLATE.validate(name, "importDocuments");
+
ImportDocumentsRequest request = ImportDocumentsRequest.newBuilder().setName(name).build();
return importDocuments(request);
}
@@ -661,9 +610,9 @@ public final Operation importDocuments(String name) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
* ImportDocumentsRequest request = ImportDocumentsRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* Operation response = firestoreAdminClient.importDocuments(request);
* }
@@ -687,9 +636,9 @@ public final Operation importDocuments(ImportDocumentsRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
* ImportDocumentsRequest request = ImportDocumentsRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Operation> future = firestoreAdminClient.importDocumentsCallable().futureCall(request);
* // Do something
@@ -714,8 +663,37 @@ public final UnaryCallable importDocumentsCal
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
- * Operation response = firestoreAdminClient.exportDocuments(formattedName);
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ * Operation response = firestoreAdminClient.exportDocuments(name);
+ * }
+ *
+ *
+ * @param name Database to export. Should be of the form:
+ * `projects/{project_id}/databases/{database_id}`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Operation exportDocuments(DatabaseName name) {
+
+ ExportDocumentsRequest request =
+ ExportDocumentsRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ return exportDocuments(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Exports a copy of all or a subset of documents from Google Cloud Firestore to another storage
+ * system, such as Google Cloud Storage. Recent updates to documents may not be reflected in the
+ * export. The export occurs in the background and its progress can be monitored and managed via
+ * the Operation resource that is created. The output of an export may only be used once the
+ * associated operation is done. If an export operation is cancelled before completion it may
+ * leave partial data behind in Google Cloud Storage.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ * Operation response = firestoreAdminClient.exportDocuments(name.toString());
* }
*
*
@@ -724,7 +702,7 @@ public final UnaryCallable importDocumentsCal
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Operation exportDocuments(String name) {
- DATABASE_PATH_TEMPLATE.validate(name, "exportDocuments");
+
ExportDocumentsRequest request = ExportDocumentsRequest.newBuilder().setName(name).build();
return exportDocuments(request);
}
@@ -742,9 +720,9 @@ public final Operation exportDocuments(String name) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
* ExportDocumentsRequest request = ExportDocumentsRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* Operation response = firestoreAdminClient.exportDocuments(request);
* }
@@ -770,9 +748,9 @@ public final Operation exportDocuments(ExportDocumentsRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ * DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
* ExportDocumentsRequest request = ExportDocumentsRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Operation> future = firestoreAdminClient.exportDocumentsCallable().futureCall(request);
* // Do something
@@ -792,8 +770,32 @@ public final UnaryCallable exportDocumentsCal
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatFieldName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
- * Field response = firestoreAdminClient.getField(formattedName);
+ * FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
+ * Field response = firestoreAdminClient.getField(name);
+ * }
+ *
+ *
+ * @param name A name of the form
+ * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/fields/{field_id}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Field getField(FieldName name) {
+
+ GetFieldRequest request =
+ GetFieldRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ return getField(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Gets the metadata and configuration for a Field.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+ * FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
+ * Field response = firestoreAdminClient.getField(name.toString());
* }
*
*
@@ -802,7 +804,7 @@ public final UnaryCallable exportDocumentsCal
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Field getField(String name) {
- FIELD_PATH_TEMPLATE.validate(name, "getField");
+
GetFieldRequest request = GetFieldRequest.newBuilder().setName(name).build();
return getField(request);
}
@@ -815,9 +817,9 @@ public final Field getField(String name) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatFieldName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
+ * FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
* GetFieldRequest request = GetFieldRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* Field response = firestoreAdminClient.getField(request);
* }
@@ -838,9 +840,9 @@ public final Field getField(GetFieldRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedName = FirestoreAdminClient.formatFieldName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
+ * FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
* GetFieldRequest request = GetFieldRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Field> future = firestoreAdminClient.getFieldCallable().futureCall(request);
* // Do something
@@ -865,7 +867,7 @@ public final UnaryCallable getFieldCallable() {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* for (Field element : firestoreAdminClient.listFields(formattedParent).iterateAll()) {
* // doThingsWith(element);
* }
@@ -877,7 +879,6 @@ public final UnaryCallable getFieldCallable() {
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListFieldsPagedResponse listFields(String parent) {
- PARENT_PATH_TEMPLATE.validate(parent, "listFields");
ListFieldsRequest request = ListFieldsRequest.newBuilder().setParent(parent).build();
return listFields(request);
}
@@ -895,7 +896,7 @@ public final ListFieldsPagedResponse listFields(String parent) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* ListFieldsRequest request = ListFieldsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -925,7 +926,7 @@ public final ListFieldsPagedResponse listFields(ListFieldsRequest request) {
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* ListFieldsRequest request = ListFieldsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -954,7 +955,7 @@ public final UnaryCallable listField
*
*
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
- * String formattedParent = FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ * String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
* ListFieldsRequest request = ListFieldsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java
index e5cc08d0913c..7231d31111f3 100644
--- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java
+++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java
@@ -27,10 +27,10 @@
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
-import com.google.api.pathtemplate.PathTemplate;
import com.google.cloud.firestore.v1.stub.FirestoreStub;
import com.google.cloud.firestore.v1.stub.FirestoreStubSettings;
import com.google.common.util.concurrent.MoreExecutors;
+import com.google.firestore.v1.AnyPathName;
import com.google.firestore.v1.BatchGetDocumentsRequest;
import com.google.firestore.v1.BatchGetDocumentsResponse;
import com.google.firestore.v1.BeginTransactionRequest;
@@ -146,137 +146,6 @@ public class FirestoreClient implements BackgroundResource {
private final FirestoreSettings settings;
private final FirestoreStub stub;
- private static final PathTemplate DATABASE_ROOT_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding("projects/{project}/databases/{database}");
-
- private static final PathTemplate DOCUMENT_ROOT_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding("projects/{project}/databases/{database}/documents");
-
- private static final PathTemplate DOCUMENT_PATH_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/documents/{document_path=**}");
-
- private static final PathTemplate ANY_PATH_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/documents/{document}/{any_path=**}");
-
- /** Formats a string containing the fully-qualified path to represent a database_root resource. */
- public static final String formatDatabaseRootName(String project, String database) {
- return DATABASE_ROOT_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database);
- }
-
- /** Formats a string containing the fully-qualified path to represent a document_root resource. */
- public static final String formatDocumentRootName(String project, String database) {
- return DOCUMENT_ROOT_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database);
- }
-
- /** Formats a string containing the fully-qualified path to represent a document_path resource. */
- public static final String formatDocumentPathName(
- String project, String database, String documentPath) {
- return DOCUMENT_PATH_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "document_path", documentPath);
- }
-
- /** Formats a string containing the fully-qualified path to represent a any_path resource. */
- public static final String formatAnyPathName(
- String project, String database, String document, String anyPath) {
- return ANY_PATH_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "document", document,
- "any_path", anyPath);
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a database_root
- * resource.
- */
- public static final String parseProjectFromDatabaseRootName(String databaseRootName) {
- return DATABASE_ROOT_PATH_TEMPLATE.parse(databaseRootName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a database_root
- * resource.
- */
- public static final String parseDatabaseFromDatabaseRootName(String databaseRootName) {
- return DATABASE_ROOT_PATH_TEMPLATE.parse(databaseRootName).get("database");
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a document_root
- * resource.
- */
- public static final String parseProjectFromDocumentRootName(String documentRootName) {
- return DOCUMENT_ROOT_PATH_TEMPLATE.parse(documentRootName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a document_root
- * resource.
- */
- public static final String parseDatabaseFromDocumentRootName(String documentRootName) {
- return DOCUMENT_ROOT_PATH_TEMPLATE.parse(documentRootName).get("database");
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a document_path
- * resource.
- */
- public static final String parseProjectFromDocumentPathName(String documentPathName) {
- return DOCUMENT_PATH_PATH_TEMPLATE.parse(documentPathName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a document_path
- * resource.
- */
- public static final String parseDatabaseFromDocumentPathName(String documentPathName) {
- return DOCUMENT_PATH_PATH_TEMPLATE.parse(documentPathName).get("database");
- }
-
- /**
- * Parses the document_path from the given fully-qualified path which represents a document_path
- * resource.
- */
- public static final String parseDocumentPathFromDocumentPathName(String documentPathName) {
- return DOCUMENT_PATH_PATH_TEMPLATE.parse(documentPathName).get("document_path");
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseProjectFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseDatabaseFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("database");
- }
-
- /**
- * Parses the document from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseDocumentFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("document");
- }
-
- /**
- * Parses the any_path from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseAnyPathFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("any_path");
- }
-
/** Constructs an instance of FirestoreClient with default settings. */
public static final FirestoreClient create() throws IOException {
return create(FirestoreSettings.newBuilder().build());
@@ -331,9 +200,9 @@ public FirestoreStub getStub() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* GetDocumentRequest request = GetDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* Document response = firestoreClient.getDocument(request);
* }
@@ -354,9 +223,9 @@ public final Document getDocument(GetDocumentRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* GetDocumentRequest request = GetDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Document> future = firestoreClient.getDocumentCallable().futureCall(request);
* // Do something
@@ -376,7 +245,7 @@ public final UnaryCallable getDocumentCallable() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
* .setParent(formattedParent)
@@ -403,7 +272,7 @@ public final ListDocumentsPagedResponse listDocuments(ListDocumentsRequest reque
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
* .setParent(formattedParent)
@@ -430,7 +299,7 @@ public final ListDocumentsPagedResponse listDocuments(ListDocumentsRequest reque
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
* .setParent(formattedParent)
@@ -463,7 +332,7 @@ public final UnaryCallable listDocu
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* String documentId = "";
* Document document = Document.newBuilder().build();
@@ -492,7 +361,7 @@ public final Document createDocument(CreateDocumentRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* String documentId = "";
* Document document = Document.newBuilder().build();
@@ -598,8 +467,32 @@ public final UnaryCallable updateDocumentCallab
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
- * firestoreClient.deleteDocument(formattedName);
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * firestoreClient.deleteDocument(name);
+ * }
+ *
+ *
+ * @param name The resource name of the Document to delete. In the format:
+ * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteDocument(AnyPathName name) {
+
+ DeleteDocumentRequest request =
+ DeleteDocumentRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ deleteDocument(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Deletes a document.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreClient firestoreClient = FirestoreClient.create()) {
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * firestoreClient.deleteDocument(name.toString());
* }
*
*
@@ -608,7 +501,7 @@ public final UnaryCallable updateDocumentCallab
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteDocument(String name) {
- ANY_PATH_PATH_TEMPLATE.validate(name, "deleteDocument");
+
DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder().setName(name).build();
deleteDocument(request);
}
@@ -621,9 +514,9 @@ public final void deleteDocument(String name) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* firestoreClient.deleteDocument(request);
* }
@@ -644,9 +537,9 @@ public final void deleteDocument(DeleteDocumentRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Void> future = firestoreClient.deleteDocumentCallable().futureCall(request);
* // Do something
@@ -669,7 +562,7 @@ public final UnaryCallable deleteDocumentCallable(
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<String> documents = new ArrayList<>();
* BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -696,7 +589,7 @@ public final UnaryCallable deleteDocumentCallable(
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* BeginTransactionResponse response = firestoreClient.beginTransaction(formattedDatabase);
* }
*
@@ -706,7 +599,7 @@ public final UnaryCallable deleteDocumentCallable(
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final BeginTransactionResponse beginTransaction(String database) {
- DATABASE_ROOT_PATH_TEMPLATE.validate(database, "beginTransaction");
+
BeginTransactionRequest request =
BeginTransactionRequest.newBuilder().setDatabase(database).build();
return beginTransaction(request);
@@ -720,7 +613,7 @@ public final BeginTransactionResponse beginTransaction(String database) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* BeginTransactionRequest request = BeginTransactionRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -743,7 +636,7 @@ public final BeginTransactionResponse beginTransaction(BeginTransactionRequest r
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* BeginTransactionRequest request = BeginTransactionRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -766,7 +659,7 @@ public final BeginTransactionResponse beginTransaction(BeginTransactionRequest r
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<Write> writes = new ArrayList<>();
* CommitResponse response = firestoreClient.commit(formattedDatabase, writes);
* }
@@ -779,7 +672,7 @@ public final BeginTransactionResponse beginTransaction(BeginTransactionRequest r
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final CommitResponse commit(String database, List writes) {
- DATABASE_ROOT_PATH_TEMPLATE.validate(database, "commit");
+
CommitRequest request =
CommitRequest.newBuilder().setDatabase(database).addAllWrites(writes).build();
return commit(request);
@@ -793,7 +686,7 @@ public final CommitResponse commit(String database, List writes) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<Write> writes = new ArrayList<>();
* CommitRequest request = CommitRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -818,7 +711,7 @@ public final CommitResponse commit(CommitRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<Write> writes = new ArrayList<>();
* CommitRequest request = CommitRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -842,7 +735,7 @@ public final UnaryCallable commitCallable() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ByteString transaction = ByteString.copyFromUtf8("");
* firestoreClient.rollback(formattedDatabase, transaction);
* }
@@ -854,7 +747,7 @@ public final UnaryCallable commitCallable() {
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void rollback(String database, ByteString transaction) {
- DATABASE_ROOT_PATH_TEMPLATE.validate(database, "rollback");
+
RollbackRequest request =
RollbackRequest.newBuilder().setDatabase(database).setTransaction(transaction).build();
rollback(request);
@@ -868,7 +761,7 @@ public final void rollback(String database, ByteString transaction) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ByteString transaction = ByteString.copyFromUtf8("");
* RollbackRequest request = RollbackRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -893,7 +786,7 @@ public final void rollback(RollbackRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ByteString transaction = ByteString.copyFromUtf8("");
* RollbackRequest request = RollbackRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -917,7 +810,7 @@ public final UnaryCallable rollbackCallable() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* RunQueryRequest request = RunQueryRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -944,7 +837,7 @@ public final ServerStreamingCallable runQuery
* BidiStream<WriteRequest, WriteResponse> bidiStream =
* firestoreClient.writeCallable().call();
*
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* WriteRequest request = WriteRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -970,7 +863,7 @@ public final BidiStreamingCallable writeCallable()
* BidiStream<ListenRequest, ListenResponse> bidiStream =
* firestoreClient.listenCallable().call();
*
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ListenRequest request = ListenRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -993,7 +886,7 @@ public final BidiStreamingCallable listenCallable
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* for (String element : firestoreClient.listCollectionIds(formattedParent).iterateAll()) {
* // doThingsWith(element);
* }
@@ -1006,7 +899,6 @@ public final BidiStreamingCallable listenCallable
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListCollectionIdsPagedResponse listCollectionIds(String parent) {
- ANY_PATH_PATH_TEMPLATE.validate(parent, "listCollectionIds");
ListCollectionIdsRequest request =
ListCollectionIdsRequest.newBuilder().setParent(parent).build();
return listCollectionIds(request);
@@ -1020,7 +912,7 @@ public final ListCollectionIdsPagedResponse listCollectionIds(String parent) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* ListCollectionIdsRequest request = ListCollectionIdsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -1045,7 +937,7 @@ public final ListCollectionIdsPagedResponse listCollectionIds(ListCollectionIdsR
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* ListCollectionIdsRequest request = ListCollectionIdsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -1070,7 +962,7 @@ public final ListCollectionIdsPagedResponse listCollectionIds(ListCollectionIdsR
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* ListCollectionIdsRequest request = ListCollectionIdsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreClient.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreClient.java
index f0e2e21eb346..3fe59e27e9b4 100644
--- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreClient.java
+++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1beta1/FirestoreClient.java
@@ -27,10 +27,10 @@
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
-import com.google.api.pathtemplate.PathTemplate;
import com.google.cloud.firestore.v1beta1.stub.FirestoreStub;
import com.google.cloud.firestore.v1beta1.stub.FirestoreStubSettings;
import com.google.common.util.concurrent.MoreExecutors;
+import com.google.firestore.v1beta1.AnyPathName;
import com.google.firestore.v1beta1.BatchGetDocumentsRequest;
import com.google.firestore.v1beta1.BatchGetDocumentsResponse;
import com.google.firestore.v1beta1.BeginTransactionRequest;
@@ -146,137 +146,6 @@ public class FirestoreClient implements BackgroundResource {
private final FirestoreSettings settings;
private final FirestoreStub stub;
- private static final PathTemplate DATABASE_ROOT_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding("projects/{project}/databases/{database}");
-
- private static final PathTemplate DOCUMENT_ROOT_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding("projects/{project}/databases/{database}/documents");
-
- private static final PathTemplate DOCUMENT_PATH_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/documents/{document_path=**}");
-
- private static final PathTemplate ANY_PATH_PATH_TEMPLATE =
- PathTemplate.createWithoutUrlEncoding(
- "projects/{project}/databases/{database}/documents/{document}/{any_path=**}");
-
- /** Formats a string containing the fully-qualified path to represent a database_root resource. */
- public static final String formatDatabaseRootName(String project, String database) {
- return DATABASE_ROOT_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database);
- }
-
- /** Formats a string containing the fully-qualified path to represent a document_root resource. */
- public static final String formatDocumentRootName(String project, String database) {
- return DOCUMENT_ROOT_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database);
- }
-
- /** Formats a string containing the fully-qualified path to represent a document_path resource. */
- public static final String formatDocumentPathName(
- String project, String database, String documentPath) {
- return DOCUMENT_PATH_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "document_path", documentPath);
- }
-
- /** Formats a string containing the fully-qualified path to represent a any_path resource. */
- public static final String formatAnyPathName(
- String project, String database, String document, String anyPath) {
- return ANY_PATH_PATH_TEMPLATE.instantiate(
- "project", project,
- "database", database,
- "document", document,
- "any_path", anyPath);
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a database_root
- * resource.
- */
- public static final String parseProjectFromDatabaseRootName(String databaseRootName) {
- return DATABASE_ROOT_PATH_TEMPLATE.parse(databaseRootName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a database_root
- * resource.
- */
- public static final String parseDatabaseFromDatabaseRootName(String databaseRootName) {
- return DATABASE_ROOT_PATH_TEMPLATE.parse(databaseRootName).get("database");
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a document_root
- * resource.
- */
- public static final String parseProjectFromDocumentRootName(String documentRootName) {
- return DOCUMENT_ROOT_PATH_TEMPLATE.parse(documentRootName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a document_root
- * resource.
- */
- public static final String parseDatabaseFromDocumentRootName(String documentRootName) {
- return DOCUMENT_ROOT_PATH_TEMPLATE.parse(documentRootName).get("database");
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a document_path
- * resource.
- */
- public static final String parseProjectFromDocumentPathName(String documentPathName) {
- return DOCUMENT_PATH_PATH_TEMPLATE.parse(documentPathName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a document_path
- * resource.
- */
- public static final String parseDatabaseFromDocumentPathName(String documentPathName) {
- return DOCUMENT_PATH_PATH_TEMPLATE.parse(documentPathName).get("database");
- }
-
- /**
- * Parses the document_path from the given fully-qualified path which represents a document_path
- * resource.
- */
- public static final String parseDocumentPathFromDocumentPathName(String documentPathName) {
- return DOCUMENT_PATH_PATH_TEMPLATE.parse(documentPathName).get("document_path");
- }
-
- /**
- * Parses the project from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseProjectFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("project");
- }
-
- /**
- * Parses the database from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseDatabaseFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("database");
- }
-
- /**
- * Parses the document from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseDocumentFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("document");
- }
-
- /**
- * Parses the any_path from the given fully-qualified path which represents a any_path resource.
- */
- public static final String parseAnyPathFromAnyPathName(String anyPathName) {
- return ANY_PATH_PATH_TEMPLATE.parse(anyPathName).get("any_path");
- }
-
/** Constructs an instance of FirestoreClient with default settings. */
public static final FirestoreClient create() throws IOException {
return create(FirestoreSettings.newBuilder().build());
@@ -331,9 +200,9 @@ public FirestoreStub getStub() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* GetDocumentRequest request = GetDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* Document response = firestoreClient.getDocument(request);
* }
@@ -354,9 +223,9 @@ public final Document getDocument(GetDocumentRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* GetDocumentRequest request = GetDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Document> future = firestoreClient.getDocumentCallable().futureCall(request);
* // Do something
@@ -376,7 +245,7 @@ public final UnaryCallable getDocumentCallable() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
* .setParent(formattedParent)
@@ -403,7 +272,7 @@ public final ListDocumentsPagedResponse listDocuments(ListDocumentsRequest reque
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
* .setParent(formattedParent)
@@ -430,7 +299,7 @@ public final ListDocumentsPagedResponse listDocuments(ListDocumentsRequest reque
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
* .setParent(formattedParent)
@@ -463,7 +332,7 @@ public final UnaryCallable listDocu
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* String documentId = "";
* Document document = Document.newBuilder().build();
@@ -492,7 +361,7 @@ public final Document createDocument(CreateDocumentRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* String collectionId = "";
* String documentId = "";
* Document document = Document.newBuilder().build();
@@ -598,8 +467,32 @@ public final UnaryCallable updateDocumentCallab
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
- * firestoreClient.deleteDocument(formattedName);
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * firestoreClient.deleteDocument(name);
+ * }
+ *
+ *
+ * @param name The resource name of the Document to delete. In the format:
+ * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteDocument(AnyPathName name) {
+
+ DeleteDocumentRequest request =
+ DeleteDocumentRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ deleteDocument(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Deletes a document.
+ *
+ * Sample code:
+ *
+ *
+ * try (FirestoreClient firestoreClient = FirestoreClient.create()) {
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * firestoreClient.deleteDocument(name.toString());
* }
*
*
@@ -608,7 +501,7 @@ public final UnaryCallable updateDocumentCallab
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteDocument(String name) {
- ANY_PATH_PATH_TEMPLATE.validate(name, "deleteDocument");
+
DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder().setName(name).build();
deleteDocument(request);
}
@@ -621,9 +514,9 @@ public final void deleteDocument(String name) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* firestoreClient.deleteDocument(request);
* }
@@ -644,9 +537,9 @@ public final void deleteDocument(DeleteDocumentRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedName = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
- * .setName(formattedName)
+ * .setName(name.toString())
* .build();
* ApiFuture<Void> future = firestoreClient.deleteDocumentCallable().futureCall(request);
* // Do something
@@ -669,7 +562,7 @@ public final UnaryCallable deleteDocumentCallable(
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<String> documents = new ArrayList<>();
* BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -696,7 +589,7 @@ public final UnaryCallable deleteDocumentCallable(
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* BeginTransactionResponse response = firestoreClient.beginTransaction(formattedDatabase);
* }
*
@@ -706,7 +599,7 @@ public final UnaryCallable deleteDocumentCallable(
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final BeginTransactionResponse beginTransaction(String database) {
- DATABASE_ROOT_PATH_TEMPLATE.validate(database, "beginTransaction");
+
BeginTransactionRequest request =
BeginTransactionRequest.newBuilder().setDatabase(database).build();
return beginTransaction(request);
@@ -720,7 +613,7 @@ public final BeginTransactionResponse beginTransaction(String database) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* BeginTransactionRequest request = BeginTransactionRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -743,7 +636,7 @@ public final BeginTransactionResponse beginTransaction(BeginTransactionRequest r
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* BeginTransactionRequest request = BeginTransactionRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -766,7 +659,7 @@ public final BeginTransactionResponse beginTransaction(BeginTransactionRequest r
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<Write> writes = new ArrayList<>();
* CommitResponse response = firestoreClient.commit(formattedDatabase, writes);
* }
@@ -779,7 +672,7 @@ public final BeginTransactionResponse beginTransaction(BeginTransactionRequest r
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final CommitResponse commit(String database, List writes) {
- DATABASE_ROOT_PATH_TEMPLATE.validate(database, "commit");
+
CommitRequest request =
CommitRequest.newBuilder().setDatabase(database).addAllWrites(writes).build();
return commit(request);
@@ -793,7 +686,7 @@ public final CommitResponse commit(String database, List writes) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<Write> writes = new ArrayList<>();
* CommitRequest request = CommitRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -818,7 +711,7 @@ public final CommitResponse commit(CommitRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* List<Write> writes = new ArrayList<>();
* CommitRequest request = CommitRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -842,7 +735,7 @@ public final UnaryCallable commitCallable() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ByteString transaction = ByteString.copyFromUtf8("");
* firestoreClient.rollback(formattedDatabase, transaction);
* }
@@ -854,7 +747,7 @@ public final UnaryCallable commitCallable() {
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void rollback(String database, ByteString transaction) {
- DATABASE_ROOT_PATH_TEMPLATE.validate(database, "rollback");
+
RollbackRequest request =
RollbackRequest.newBuilder().setDatabase(database).setTransaction(transaction).build();
rollback(request);
@@ -868,7 +761,7 @@ public final void rollback(String database, ByteString transaction) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ByteString transaction = ByteString.copyFromUtf8("");
* RollbackRequest request = RollbackRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -893,7 +786,7 @@ public final void rollback(RollbackRequest request) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ByteString transaction = ByteString.copyFromUtf8("");
* RollbackRequest request = RollbackRequest.newBuilder()
* .setDatabase(formattedDatabase)
@@ -917,7 +810,7 @@ public final UnaryCallable rollbackCallable() {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* RunQueryRequest request = RunQueryRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -944,7 +837,7 @@ public final ServerStreamingCallable runQuery
* BidiStream<WriteRequest, WriteResponse> bidiStream =
* firestoreClient.writeCallable().call();
*
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* WriteRequest request = WriteRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -970,7 +863,7 @@ public final BidiStreamingCallable writeCallable()
* BidiStream<ListenRequest, ListenResponse> bidiStream =
* firestoreClient.listenCallable().call();
*
- * String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ * String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
* ListenRequest request = ListenRequest.newBuilder()
* .setDatabase(formattedDatabase)
* .build();
@@ -993,7 +886,7 @@ public final BidiStreamingCallable listenCallable
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* for (String element : firestoreClient.listCollectionIds(formattedParent).iterateAll()) {
* // doThingsWith(element);
* }
@@ -1006,7 +899,6 @@ public final BidiStreamingCallable listenCallable
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListCollectionIdsPagedResponse listCollectionIds(String parent) {
- ANY_PATH_PATH_TEMPLATE.validate(parent, "listCollectionIds");
ListCollectionIdsRequest request =
ListCollectionIdsRequest.newBuilder().setParent(parent).build();
return listCollectionIds(request);
@@ -1020,7 +912,7 @@ public final ListCollectionIdsPagedResponse listCollectionIds(String parent) {
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* ListCollectionIdsRequest request = ListCollectionIdsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -1045,7 +937,7 @@ public final ListCollectionIdsPagedResponse listCollectionIds(ListCollectionIdsR
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* ListCollectionIdsRequest request = ListCollectionIdsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
@@ -1070,7 +962,7 @@ public final ListCollectionIdsPagedResponse listCollectionIds(ListCollectionIdsR
*
*
* try (FirestoreClient firestoreClient = FirestoreClient.create()) {
- * String formattedParent = FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ * String formattedParent = AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
* ListCollectionIdsRequest request = ListCollectionIdsRequest.newBuilder()
* .setParent(formattedParent)
* .build();
diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java
index d71cf13492b2..2372f9cb344b 100644
--- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java
+++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java
@@ -27,17 +27,21 @@
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.common.collect.Lists;
import com.google.firestore.admin.v1.CreateIndexRequest;
+import com.google.firestore.admin.v1.DatabaseName;
import com.google.firestore.admin.v1.DeleteIndexRequest;
import com.google.firestore.admin.v1.ExportDocumentsRequest;
import com.google.firestore.admin.v1.Field;
+import com.google.firestore.admin.v1.FieldName;
import com.google.firestore.admin.v1.GetFieldRequest;
import com.google.firestore.admin.v1.GetIndexRequest;
import com.google.firestore.admin.v1.ImportDocumentsRequest;
import com.google.firestore.admin.v1.Index;
+import com.google.firestore.admin.v1.IndexName;
import com.google.firestore.admin.v1.ListFieldsRequest;
import com.google.firestore.admin.v1.ListFieldsResponse;
import com.google.firestore.admin.v1.ListIndexesRequest;
import com.google.firestore.admin.v1.ListIndexesResponse;
+import com.google.firestore.admin.v1.ParentName;
import com.google.firestore.admin.v1.UpdateFieldRequest;
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
@@ -99,8 +103,7 @@ public void createIndexTest() {
Operation expectedResponse = Operation.newBuilder().setName(name).setDone(done).build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedParent =
- FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
Index index = Index.newBuilder().build();
Operation actualResponse = client.createIndex(formattedParent, index);
@@ -125,8 +128,7 @@ public void createIndexExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedParent =
- FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
Index index = Index.newBuilder().build();
client.createIndex(formattedParent, index);
@@ -149,8 +151,7 @@ public void listIndexesTest() {
.build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedParent =
- FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
ListIndexesPagedResponse pagedListResponse = client.listIndexes(formattedParent);
@@ -176,8 +177,7 @@ public void listIndexesExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedParent =
- FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
client.listIndexes(formattedParent);
Assert.fail("No exception raised");
@@ -193,18 +193,16 @@ public void getIndexTest() {
Index expectedResponse = Index.newBuilder().setName(name2).build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedName =
- FirestoreAdminClient.formatIndexName(
- "[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
- Index actualResponse = client.getIndex(formattedName);
+ Index actualResponse = client.getIndex(name);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetIndexRequest actualRequest = (GetIndexRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, IndexName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -218,11 +216,9 @@ public void getIndexExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedName =
- FirestoreAdminClient.formatIndexName(
- "[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
- client.getIndex(formattedName);
+ client.getIndex(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -235,17 +231,15 @@ public void deleteIndexTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedName =
- FirestoreAdminClient.formatIndexName(
- "[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
- client.deleteIndex(formattedName);
+ client.deleteIndex(name);
List actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteIndexRequest actualRequest = (DeleteIndexRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, IndexName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -259,11 +253,9 @@ public void deleteIndexExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedName =
- FirestoreAdminClient.formatIndexName(
- "[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[INDEX_ID]");
- client.deleteIndex(formattedName);
+ client.deleteIndex(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -278,16 +270,16 @@ public void importDocumentsTest() {
Operation expectedResponse = Operation.newBuilder().setName(name2).setDone(done).build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
- Operation actualResponse = client.importDocuments(formattedName);
+ Operation actualResponse = client.importDocuments(name);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ImportDocumentsRequest actualRequest = (ImportDocumentsRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, DatabaseName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -301,9 +293,9 @@ public void importDocumentsExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
- client.importDocuments(formattedName);
+ client.importDocuments(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -318,16 +310,16 @@ public void exportDocumentsTest() {
Operation expectedResponse = Operation.newBuilder().setName(name2).setDone(done).build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
- Operation actualResponse = client.exportDocuments(formattedName);
+ Operation actualResponse = client.exportDocuments(name);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExportDocumentsRequest actualRequest = (ExportDocumentsRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, DatabaseName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -341,9 +333,9 @@ public void exportDocumentsExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedName = FirestoreAdminClient.formatDatabaseName("[PROJECT]", "[DATABASE]");
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
- client.exportDocuments(formattedName);
+ client.exportDocuments(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -357,18 +349,16 @@ public void getFieldTest() {
Field expectedResponse = Field.newBuilder().setName(name2).build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedName =
- FirestoreAdminClient.formatFieldName(
- "[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
+ FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
- Field actualResponse = client.getField(formattedName);
+ Field actualResponse = client.getField(name);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetFieldRequest actualRequest = (GetFieldRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, FieldName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -382,11 +372,9 @@ public void getFieldExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedName =
- FirestoreAdminClient.formatFieldName(
- "[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
+ FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]", "[FIELD_ID]");
- client.getField(formattedName);
+ client.getField(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -406,8 +394,7 @@ public void listFieldsTest() {
.build();
mockFirestoreAdmin.addResponse(expectedResponse);
- String formattedParent =
- FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
ListFieldsPagedResponse pagedListResponse = client.listFields(formattedParent);
@@ -433,8 +420,7 @@ public void listFieldsExceptionTest() throws Exception {
mockFirestoreAdmin.addException(exception);
try {
- String formattedParent =
- FirestoreAdminClient.formatParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
+ String formattedParent = ParentName.format("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]");
client.listFields(formattedParent);
Assert.fail("No exception raised");
diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java
index 209551659f01..90642f92ba1b 100644
--- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java
+++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java
@@ -30,12 +30,14 @@
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.StatusCode;
import com.google.common.collect.Lists;
+import com.google.firestore.v1.AnyPathName;
import com.google.firestore.v1.BatchGetDocumentsRequest;
import com.google.firestore.v1.BatchGetDocumentsResponse;
import com.google.firestore.v1.BeginTransactionRequest;
import com.google.firestore.v1.BeginTransactionResponse;
import com.google.firestore.v1.CommitRequest;
import com.google.firestore.v1.CommitResponse;
+import com.google.firestore.v1.DatabaseRootName;
import com.google.firestore.v1.DeleteDocumentRequest;
import com.google.firestore.v1.Document;
import com.google.firestore.v1.DocumentMask;
@@ -152,16 +154,15 @@ public void deleteDocumentTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedName =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
- client.deleteDocument(formattedName);
+ client.deleteDocument(name);
List actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteDocumentRequest actualRequest = (DeleteDocumentRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, AnyPathName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -175,10 +176,9 @@ public void deleteDocumentExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedName =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
- client.deleteDocument(formattedName);
+ client.deleteDocument(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -196,7 +196,7 @@ public void batchGetDocumentsTest() throws Exception {
.setTransaction(transaction)
.build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List documents = new ArrayList<>();
BatchGetDocumentsRequest request =
BatchGetDocumentsRequest.newBuilder()
@@ -220,7 +220,7 @@ public void batchGetDocumentsTest() throws Exception {
public void batchGetDocumentsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List documents = new ArrayList<>();
BatchGetDocumentsRequest request =
BatchGetDocumentsRequest.newBuilder()
@@ -252,7 +252,7 @@ public void beginTransactionTest() {
BeginTransactionResponse.newBuilder().setTransaction(transaction).build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
BeginTransactionResponse actualResponse = client.beginTransaction(formattedDatabase);
Assert.assertEquals(expectedResponse, actualResponse);
@@ -275,7 +275,7 @@ public void beginTransactionExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
client.beginTransaction(formattedDatabase);
Assert.fail("No exception raised");
@@ -290,7 +290,7 @@ public void commitTest() {
CommitResponse expectedResponse = CommitResponse.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List writes = new ArrayList<>();
CommitResponse actualResponse = client.commit(formattedDatabase, writes);
@@ -315,7 +315,7 @@ public void commitExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List writes = new ArrayList<>();
client.commit(formattedDatabase, writes);
@@ -331,7 +331,7 @@ public void rollbackTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ByteString transaction = ByteString.copyFromUtf8("-34");
client.rollback(formattedDatabase, transaction);
@@ -355,7 +355,7 @@ public void rollbackExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ByteString transaction = ByteString.copyFromUtf8("-34");
client.rollback(formattedDatabase, transaction);
@@ -377,7 +377,7 @@ public void runQueryTest() throws Exception {
.build();
mockFirestore.addResponse(expectedResponse);
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
RunQueryRequest request = RunQueryRequest.newBuilder().setParent(formattedParent).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -396,7 +396,7 @@ public void runQueryExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
RunQueryRequest request = RunQueryRequest.newBuilder().setParent(formattedParent).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -422,7 +422,7 @@ public void writeTest() throws Exception {
WriteResponse expectedResponse =
WriteResponse.newBuilder().setStreamId(streamId).setStreamToken(streamToken).build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
WriteRequest request = WriteRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -443,7 +443,7 @@ public void writeTest() throws Exception {
public void writeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
WriteRequest request = WriteRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -468,7 +468,7 @@ public void writeExceptionTest() throws Exception {
public void listenTest() throws Exception {
ListenResponse expectedResponse = ListenResponse.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ListenRequest request = ListenRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -489,7 +489,7 @@ public void listenTest() throws Exception {
public void listenExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ListenRequest request = ListenRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -523,7 +523,7 @@ public void listCollectionIdsTest() {
mockFirestore.addResponse(expectedResponse);
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
ListCollectionIdsPagedResponse pagedListResponse = client.listCollectionIds(formattedParent);
@@ -550,7 +550,7 @@ public void listCollectionIdsExceptionTest() throws Exception {
try {
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
client.listCollectionIds(formattedParent);
Assert.fail("No exception raised");
diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1beta1/FirestoreClientTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1beta1/FirestoreClientTest.java
index 192c4f271da2..c901c4a65cc1 100644
--- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1beta1/FirestoreClientTest.java
+++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1beta1/FirestoreClientTest.java
@@ -30,12 +30,14 @@
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.StatusCode;
import com.google.common.collect.Lists;
+import com.google.firestore.v1beta1.AnyPathName;
import com.google.firestore.v1beta1.BatchGetDocumentsRequest;
import com.google.firestore.v1beta1.BatchGetDocumentsResponse;
import com.google.firestore.v1beta1.BeginTransactionRequest;
import com.google.firestore.v1beta1.BeginTransactionResponse;
import com.google.firestore.v1beta1.CommitRequest;
import com.google.firestore.v1beta1.CommitResponse;
+import com.google.firestore.v1beta1.DatabaseRootName;
import com.google.firestore.v1beta1.DeleteDocumentRequest;
import com.google.firestore.v1beta1.Document;
import com.google.firestore.v1beta1.DocumentMask;
@@ -152,16 +154,15 @@ public void deleteDocumentTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedName =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
- client.deleteDocument(formattedName);
+ client.deleteDocument(name);
List actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteDocumentRequest actualRequest = (DeleteDocumentRequest) actualRequests.get(0);
- Assert.assertEquals(formattedName, actualRequest.getName());
+ Assert.assertEquals(name, AnyPathName.parse(actualRequest.getName()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
@@ -175,10 +176,9 @@ public void deleteDocumentExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedName =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName name = AnyPathName.of("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
- client.deleteDocument(formattedName);
+ client.deleteDocument(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -196,7 +196,7 @@ public void batchGetDocumentsTest() throws Exception {
.setTransaction(transaction)
.build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List documents = new ArrayList<>();
BatchGetDocumentsRequest request =
BatchGetDocumentsRequest.newBuilder()
@@ -220,7 +220,7 @@ public void batchGetDocumentsTest() throws Exception {
public void batchGetDocumentsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List documents = new ArrayList<>();
BatchGetDocumentsRequest request =
BatchGetDocumentsRequest.newBuilder()
@@ -252,7 +252,7 @@ public void beginTransactionTest() {
BeginTransactionResponse.newBuilder().setTransaction(transaction).build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
BeginTransactionResponse actualResponse = client.beginTransaction(formattedDatabase);
Assert.assertEquals(expectedResponse, actualResponse);
@@ -275,7 +275,7 @@ public void beginTransactionExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
client.beginTransaction(formattedDatabase);
Assert.fail("No exception raised");
@@ -290,7 +290,7 @@ public void commitTest() {
CommitResponse expectedResponse = CommitResponse.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List writes = new ArrayList<>();
CommitResponse actualResponse = client.commit(formattedDatabase, writes);
@@ -315,7 +315,7 @@ public void commitExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
List writes = new ArrayList<>();
client.commit(formattedDatabase, writes);
@@ -331,7 +331,7 @@ public void rollbackTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ByteString transaction = ByteString.copyFromUtf8("-34");
client.rollback(formattedDatabase, transaction);
@@ -355,7 +355,7 @@ public void rollbackExceptionTest() throws Exception {
mockFirestore.addException(exception);
try {
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ByteString transaction = ByteString.copyFromUtf8("-34");
client.rollback(formattedDatabase, transaction);
@@ -377,7 +377,7 @@ public void runQueryTest() throws Exception {
.build();
mockFirestore.addResponse(expectedResponse);
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
RunQueryRequest request = RunQueryRequest.newBuilder().setParent(formattedParent).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -396,7 +396,7 @@ public void runQueryExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
RunQueryRequest request = RunQueryRequest.newBuilder().setParent(formattedParent).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -422,7 +422,7 @@ public void writeTest() throws Exception {
WriteResponse expectedResponse =
WriteResponse.newBuilder().setStreamId(streamId).setStreamToken(streamToken).build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
WriteRequest request = WriteRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -443,7 +443,7 @@ public void writeTest() throws Exception {
public void writeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
WriteRequest request = WriteRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -468,7 +468,7 @@ public void writeExceptionTest() throws Exception {
public void listenTest() throws Exception {
ListenResponse expectedResponse = ListenResponse.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ListenRequest request = ListenRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -489,7 +489,7 @@ public void listenTest() throws Exception {
public void listenExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
- String formattedDatabase = FirestoreClient.formatDatabaseRootName("[PROJECT]", "[DATABASE]");
+ String formattedDatabase = DatabaseRootName.format("[PROJECT]", "[DATABASE]");
ListenRequest request = ListenRequest.newBuilder().setDatabase(formattedDatabase).build();
MockStreamObserver responseObserver = new MockStreamObserver<>();
@@ -523,7 +523,7 @@ public void listCollectionIdsTest() {
mockFirestore.addResponse(expectedResponse);
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
ListCollectionIdsPagedResponse pagedListResponse = client.listCollectionIds(formattedParent);
@@ -550,7 +550,7 @@ public void listCollectionIdsExceptionTest() throws Exception {
try {
String formattedParent =
- FirestoreClient.formatAnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
+ AnyPathName.format("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]");
client.listCollectionIds(formattedParent);
Assert.fail("No exception raised");