Skip to content

Commit 09f20bd

Browse files
gcf-owl-bot[bot]renovate-botrajatbhatta
authored
feat: Add support for UpdateDatabase in Cloud Spanner (#2429)
* feat: Add support for UpdateDatabase in Cloud Spanner PiperOrigin-RevId: 531423380 Source-Link: googleapis/googleapis@3e054d1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/e347738483743e8e866cac722db0e9425356fc80 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTM0NzczODQ4Mzc0M2U4ZTg2NmNhYzcyMmRiMGU5NDI1MzU2ZmM4MCJ9 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Mend Renovate <[email protected]> Co-authored-by: Rajat Bhatta <[email protected]>
1 parent a33ea90 commit 09f20bd

File tree

19 files changed

+4107
-263
lines changed

19 files changed

+4107
-263
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
7575
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
7676
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
77+
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
78+
import com.google.spanner.admin.database.v1.UpdateDatabaseRequest;
7779
import java.io.IOException;
7880
import java.util.List;
7981
import java.util.concurrent.TimeUnit;
@@ -725,6 +727,235 @@ public final UnaryCallable<GetDatabaseRequest, Database> getDatabaseCallable() {
725727
return stub.getDatabaseCallable();
726728
}
727729

730+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
731+
/**
732+
* Updates a Cloud Spanner database. The returned [long-running
733+
* operation][google.longrunning.Operation] can be used to track the progress of updating the
734+
* database. If the named database does not exist, returns `NOT_FOUND`.
735+
*
736+
* <p>While the operation is pending:
737+
*
738+
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
739+
* field is set to true. &#42; Cancelling the operation is best-effort. If the cancellation
740+
* succeeds, the operation metadata's
741+
* [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] is set, the
742+
* updates are reverted, and the operation terminates with a `CANCELLED` status. &#42; New
743+
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
744+
* is done (returns successfully or with error). &#42; Reading the database via the API continues
745+
* to give the pre-request values.
746+
*
747+
* <p>Upon completion of the returned operation:
748+
*
749+
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
750+
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
751+
*
752+
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
753+
* format
754+
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
755+
* and can be used to track the database modification. The
756+
* [metadata][google.longrunning.Operation.metadata] field type is
757+
* [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. The
758+
* [response][google.longrunning.Operation.response] field type is
759+
* [Database][google.spanner.admin.database.v1.Database], if successful.
760+
*
761+
* <p>Sample code:
762+
*
763+
* <pre>{@code
764+
* // This snippet has been automatically generated and should be regarded as a code template only.
765+
* // It will require modifications to work:
766+
* // - It may require correct/in-range values for request initialization.
767+
* // - It may require specifying regional endpoints when creating the service client as shown in
768+
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
769+
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
770+
* Database database = Database.newBuilder().build();
771+
* FieldMask updateMask = FieldMask.newBuilder().build();
772+
* Database response = databaseAdminClient.updateDatabaseAsync(database, updateMask).get();
773+
* }
774+
* }</pre>
775+
*
776+
* @param database Required. The database to update. The `name` field of the database is of the
777+
* form `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;`.
778+
* @param updateMask Required. The list of fields to update. Currently, only
779+
* `enable_drop_protection` field can be updated.
780+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
781+
*/
782+
public final OperationFuture<Database, UpdateDatabaseMetadata> updateDatabaseAsync(
783+
Database database, FieldMask updateMask) {
784+
UpdateDatabaseRequest request =
785+
UpdateDatabaseRequest.newBuilder().setDatabase(database).setUpdateMask(updateMask).build();
786+
return updateDatabaseAsync(request);
787+
}
788+
789+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
790+
/**
791+
* Updates a Cloud Spanner database. The returned [long-running
792+
* operation][google.longrunning.Operation] can be used to track the progress of updating the
793+
* database. If the named database does not exist, returns `NOT_FOUND`.
794+
*
795+
* <p>While the operation is pending:
796+
*
797+
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
798+
* field is set to true. &#42; Cancelling the operation is best-effort. If the cancellation
799+
* succeeds, the operation metadata's
800+
* [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] is set, the
801+
* updates are reverted, and the operation terminates with a `CANCELLED` status. &#42; New
802+
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
803+
* is done (returns successfully or with error). &#42; Reading the database via the API continues
804+
* to give the pre-request values.
805+
*
806+
* <p>Upon completion of the returned operation:
807+
*
808+
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
809+
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
810+
*
811+
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
812+
* format
813+
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
814+
* and can be used to track the database modification. The
815+
* [metadata][google.longrunning.Operation.metadata] field type is
816+
* [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. The
817+
* [response][google.longrunning.Operation.response] field type is
818+
* [Database][google.spanner.admin.database.v1.Database], if successful.
819+
*
820+
* <p>Sample code:
821+
*
822+
* <pre>{@code
823+
* // This snippet has been automatically generated and should be regarded as a code template only.
824+
* // It will require modifications to work:
825+
* // - It may require correct/in-range values for request initialization.
826+
* // - It may require specifying regional endpoints when creating the service client as shown in
827+
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
828+
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
829+
* UpdateDatabaseRequest request =
830+
* UpdateDatabaseRequest.newBuilder()
831+
* .setDatabase(Database.newBuilder().build())
832+
* .setUpdateMask(FieldMask.newBuilder().build())
833+
* .build();
834+
* Database response = databaseAdminClient.updateDatabaseAsync(request).get();
835+
* }
836+
* }</pre>
837+
*
838+
* @param request The request object containing all of the parameters for the API call.
839+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
840+
*/
841+
public final OperationFuture<Database, UpdateDatabaseMetadata> updateDatabaseAsync(
842+
UpdateDatabaseRequest request) {
843+
return updateDatabaseOperationCallable().futureCall(request);
844+
}
845+
846+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
847+
/**
848+
* Updates a Cloud Spanner database. The returned [long-running
849+
* operation][google.longrunning.Operation] can be used to track the progress of updating the
850+
* database. If the named database does not exist, returns `NOT_FOUND`.
851+
*
852+
* <p>While the operation is pending:
853+
*
854+
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
855+
* field is set to true. &#42; Cancelling the operation is best-effort. If the cancellation
856+
* succeeds, the operation metadata's
857+
* [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] is set, the
858+
* updates are reverted, and the operation terminates with a `CANCELLED` status. &#42; New
859+
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
860+
* is done (returns successfully or with error). &#42; Reading the database via the API continues
861+
* to give the pre-request values.
862+
*
863+
* <p>Upon completion of the returned operation:
864+
*
865+
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
866+
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
867+
*
868+
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
869+
* format
870+
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
871+
* and can be used to track the database modification. The
872+
* [metadata][google.longrunning.Operation.metadata] field type is
873+
* [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. The
874+
* [response][google.longrunning.Operation.response] field type is
875+
* [Database][google.spanner.admin.database.v1.Database], if successful.
876+
*
877+
* <p>Sample code:
878+
*
879+
* <pre>{@code
880+
* // This snippet has been automatically generated and should be regarded as a code template only.
881+
* // It will require modifications to work:
882+
* // - It may require correct/in-range values for request initialization.
883+
* // - It may require specifying regional endpoints when creating the service client as shown in
884+
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
885+
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
886+
* UpdateDatabaseRequest request =
887+
* UpdateDatabaseRequest.newBuilder()
888+
* .setDatabase(Database.newBuilder().build())
889+
* .setUpdateMask(FieldMask.newBuilder().build())
890+
* .build();
891+
* OperationFuture<Database, UpdateDatabaseMetadata> future =
892+
* databaseAdminClient.updateDatabaseOperationCallable().futureCall(request);
893+
* // Do something.
894+
* Database response = future.get();
895+
* }
896+
* }</pre>
897+
*/
898+
public final OperationCallable<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
899+
updateDatabaseOperationCallable() {
900+
return stub.updateDatabaseOperationCallable();
901+
}
902+
903+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
904+
/**
905+
* Updates a Cloud Spanner database. The returned [long-running
906+
* operation][google.longrunning.Operation] can be used to track the progress of updating the
907+
* database. If the named database does not exist, returns `NOT_FOUND`.
908+
*
909+
* <p>While the operation is pending:
910+
*
911+
* <p>&#42; The database's [reconciling][google.spanner.admin.database.v1.Database.reconciling]
912+
* field is set to true. &#42; Cancelling the operation is best-effort. If the cancellation
913+
* succeeds, the operation metadata's
914+
* [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] is set, the
915+
* updates are reverted, and the operation terminates with a `CANCELLED` status. &#42; New
916+
* UpdateDatabase requests will return a `FAILED_PRECONDITION` error until the pending operation
917+
* is done (returns successfully or with error). &#42; Reading the database via the API continues
918+
* to give the pre-request values.
919+
*
920+
* <p>Upon completion of the returned operation:
921+
*
922+
* <p>&#42; The new values are in effect and readable via the API. &#42; The database's
923+
* [reconciling][google.spanner.admin.database.v1.Database.reconciling] field becomes false.
924+
*
925+
* <p>The returned [long-running operation][google.longrunning.Operation] will have a name of the
926+
* format
927+
* `projects/&lt;project&gt;/instances/&lt;instance&gt;/databases/&lt;database&gt;/operations/&lt;operation_id&gt;`
928+
* and can be used to track the database modification. The
929+
* [metadata][google.longrunning.Operation.metadata] field type is
930+
* [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. The
931+
* [response][google.longrunning.Operation.response] field type is
932+
* [Database][google.spanner.admin.database.v1.Database], if successful.
933+
*
934+
* <p>Sample code:
935+
*
936+
* <pre>{@code
937+
* // This snippet has been automatically generated and should be regarded as a code template only.
938+
* // It will require modifications to work:
939+
* // - It may require correct/in-range values for request initialization.
940+
* // - It may require specifying regional endpoints when creating the service client as shown in
941+
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
942+
* try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
943+
* UpdateDatabaseRequest request =
944+
* UpdateDatabaseRequest.newBuilder()
945+
* .setDatabase(Database.newBuilder().build())
946+
* .setUpdateMask(FieldMask.newBuilder().build())
947+
* .build();
948+
* ApiFuture<Operation> future =
949+
* databaseAdminClient.updateDatabaseCallable().futureCall(request);
950+
* // Do something.
951+
* Operation response = future.get();
952+
* }
953+
* }</pre>
954+
*/
955+
public final UnaryCallable<UpdateDatabaseRequest, Operation> updateDatabaseCallable() {
956+
return stub.updateDatabaseCallable();
957+
}
958+
728959
// AUTO-GENERATED DOCUMENTATION AND METHOD.
729960
/**
730961
* Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,

google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
7373
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
7474
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
75+
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
76+
import com.google.spanner.admin.database.v1.UpdateDatabaseRequest;
7577
import java.io.IOException;
7678
import java.util.List;
7779
import javax.annotation.Generated;
@@ -137,6 +139,17 @@ public UnaryCallSettings<GetDatabaseRequest, Database> getDatabaseSettings() {
137139
return ((DatabaseAdminStubSettings) getStubSettings()).getDatabaseSettings();
138140
}
139141

142+
/** Returns the object with the settings used for calls to updateDatabase. */
143+
public UnaryCallSettings<UpdateDatabaseRequest, Operation> updateDatabaseSettings() {
144+
return ((DatabaseAdminStubSettings) getStubSettings()).updateDatabaseSettings();
145+
}
146+
147+
/** Returns the object with the settings used for calls to updateDatabase. */
148+
public OperationCallSettings<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
149+
updateDatabaseOperationSettings() {
150+
return ((DatabaseAdminStubSettings) getStubSettings()).updateDatabaseOperationSettings();
151+
}
152+
140153
/** Returns the object with the settings used for calls to updateDatabaseDdl. */
141154
public UnaryCallSettings<UpdateDatabaseDdlRequest, Operation> updateDatabaseDdlSettings() {
142155
return ((DatabaseAdminStubSettings) getStubSettings()).updateDatabaseDdlSettings();
@@ -391,6 +404,17 @@ public UnaryCallSettings.Builder<GetDatabaseRequest, Database> getDatabaseSettin
391404
return getStubSettingsBuilder().getDatabaseSettings();
392405
}
393406

407+
/** Returns the builder for the settings used for calls to updateDatabase. */
408+
public UnaryCallSettings.Builder<UpdateDatabaseRequest, Operation> updateDatabaseSettings() {
409+
return getStubSettingsBuilder().updateDatabaseSettings();
410+
}
411+
412+
/** Returns the builder for the settings used for calls to updateDatabase. */
413+
public OperationCallSettings.Builder<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
414+
updateDatabaseOperationSettings() {
415+
return getStubSettingsBuilder().updateDatabaseOperationSettings();
416+
}
417+
394418
/** Returns the builder for the settings used for calls to updateDatabaseDdl. */
395419
public UnaryCallSettings.Builder<UpdateDatabaseDdlRequest, Operation>
396420
updateDatabaseDdlSettings() {

google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/gapic_metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
"UpdateBackup": {
6565
"methods": ["updateBackup", "updateBackup", "updateBackupCallable"]
6666
},
67+
"UpdateDatabase": {
68+
"methods": ["updateDatabaseAsync", "updateDatabaseAsync", "updateDatabaseOperationCallable", "updateDatabaseCallable"]
69+
},
6770
"UpdateDatabaseDdl": {
6871
"methods": ["updateDatabaseDdlAsync", "updateDatabaseDdlAsync", "updateDatabaseDdlAsync", "updateDatabaseDdlOperationCallable", "updateDatabaseDdlCallable"]
6972
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStub.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
6363
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
6464
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
65+
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
66+
import com.google.spanner.admin.database.v1.UpdateDatabaseRequest;
6567
import javax.annotation.Generated;
6668

6769
// AUTO-GENERATED DOCUMENTATION AND CLASS.
@@ -103,6 +105,15 @@ public UnaryCallable<GetDatabaseRequest, Database> getDatabaseCallable() {
103105
throw new UnsupportedOperationException("Not implemented: getDatabaseCallable()");
104106
}
105107

108+
public OperationCallable<UpdateDatabaseRequest, Database, UpdateDatabaseMetadata>
109+
updateDatabaseOperationCallable() {
110+
throw new UnsupportedOperationException("Not implemented: updateDatabaseOperationCallable()");
111+
}
112+
113+
public UnaryCallable<UpdateDatabaseRequest, Operation> updateDatabaseCallable() {
114+
throw new UnsupportedOperationException("Not implemented: updateDatabaseCallable()");
115+
}
116+
106117
public OperationCallable<UpdateDatabaseDdlRequest, Empty, UpdateDatabaseDdlMetadata>
107118
updateDatabaseDdlOperationCallable() {
108119
throw new UnsupportedOperationException(

0 commit comments

Comments
 (0)