1616
1717package com .google .cloud .spanner ;
1818
19+ import com .google .cloud .FieldSelector ;
1920import com .google .cloud .Timestamp ;
2021import com .google .cloud .spanner .encryption .CustomerManagedEncryption ;
2122import com .google .common .base .Preconditions ;
23+ import com .google .protobuf .FieldMask ;
24+ import com .google .spanner .admin .database .v1 .Database .State ;
2225import java .util .Objects ;
2326import javax .annotation .Nullable ;
2427
2528/** Represents a Cloud Spanner database. */
2629public class DatabaseInfo {
2730
31+ /** Represent an updatable field in a Cloud Spanner database. */
32+ public enum DatabaseField implements FieldSelector {
33+ DROP_PROTECTION ("enable_drop_protection" );
34+
35+ private final String selector ;
36+
37+ DatabaseField (String selector ) {
38+ this .selector = selector ;
39+ }
40+
41+ @ Override
42+ public String getSelector () {
43+ return selector ;
44+ }
45+
46+ static FieldMask toFieldMask (DatabaseInfo .DatabaseField ... fields ) {
47+ FieldMask .Builder builder = FieldMask .newBuilder ();
48+ for (DatabaseInfo .DatabaseField field : fields ) {
49+ builder .addPaths (field .getSelector ());
50+ }
51+ return builder .build ();
52+ }
53+ }
54+
2855 public abstract static class Builder {
2956 abstract Builder setState (State state );
3057
@@ -58,6 +85,18 @@ public Builder setDialect(Dialect dialect) {
5885 throw new UnsupportedOperationException ("Unimplemented" );
5986 }
6087
88+ public Builder enableDropProtection () {
89+ throw new UnsupportedOperationException ("Unimplemented" );
90+ }
91+
92+ public Builder disableDropProtection () {
93+ throw new UnsupportedOperationException ("Unimplemented" );
94+ }
95+
96+ protected Builder setReconciling (boolean reconciling ) {
97+ throw new UnsupportedOperationException ("Unimplemented" );
98+ }
99+
61100 abstract Builder setProto (com .google .spanner .admin .database .v1 .Database proto );
62101
63102 /** Builds the database from this builder. */
@@ -74,6 +113,8 @@ abstract static class BuilderImpl extends Builder {
74113 private CustomerManagedEncryption encryptionConfig ;
75114 private String defaultLeader ;
76115 private Dialect dialect = Dialect .GOOGLE_STANDARD_SQL ;
116+ private boolean dropProtectionEnabled ;
117+ private boolean reconciling ;
77118 private com .google .spanner .admin .database .v1 .Database proto ;
78119
79120 BuilderImpl (DatabaseId id ) {
@@ -141,6 +182,24 @@ public Builder setDialect(Dialect dialect) {
141182 return this ;
142183 }
143184
185+ @ Override
186+ public Builder enableDropProtection () {
187+ this .dropProtectionEnabled = true ;
188+ return this ;
189+ }
190+
191+ @ Override
192+ public Builder disableDropProtection () {
193+ this .dropProtectionEnabled = false ;
194+ return this ;
195+ }
196+
197+ @ Override
198+ protected Builder setReconciling (boolean reconciling ) {
199+ this .reconciling = reconciling ;
200+ return this ;
201+ }
202+
144203 @ Override
145204 Builder setProto (@ Nullable com .google .spanner .admin .database .v1 .Database proto ) {
146205 this .proto = proto ;
@@ -151,13 +210,35 @@ Builder setProto(@Nullable com.google.spanner.admin.database.v1.Database proto)
151210 /** State of the database. */
152211 public enum State {
153212 // Not specified.
154- UNSPECIFIED ,
213+ UNSPECIFIED {
214+ @ Override
215+ public com .google .spanner .admin .database .v1 .Database .State toProto () {
216+ return com .google .spanner .admin .database .v1 .Database .State .STATE_UNSPECIFIED ;
217+ }
218+ },
155219 // The database is still being created and is not ready to use.
156- CREATING ,
220+ CREATING {
221+ @ Override
222+ public com .google .spanner .admin .database .v1 .Database .State toProto () {
223+ return com .google .spanner .admin .database .v1 .Database .State .CREATING ;
224+ }
225+ },
157226 // The database is fully created and ready to use.
158- READY ,
227+ READY {
228+ @ Override
229+ public com .google .spanner .admin .database .v1 .Database .State toProto () {
230+ return com .google .spanner .admin .database .v1 .Database .State .READY ;
231+ }
232+ },
159233 // The database has restored and is being optimized for use.
160- READY_OPTIMIZING
234+ READY_OPTIMIZING {
235+ @ Override
236+ public com .google .spanner .admin .database .v1 .Database .State toProto () {
237+ return com .google .spanner .admin .database .v1 .Database .State .READY_OPTIMIZING ;
238+ }
239+ };
240+
241+ public abstract com .google .spanner .admin .database .v1 .Database .State toProto ();
161242 }
162243
163244 private final DatabaseId id ;
@@ -169,6 +250,8 @@ public enum State {
169250 private final CustomerManagedEncryption encryptionConfig ;
170251 private final String defaultLeader ;
171252 private final Dialect dialect ;
253+ private final boolean dropProtectionEnabled ;
254+ private final boolean reconciling ;
172255 private final com .google .spanner .admin .database .v1 .Database proto ;
173256
174257 public DatabaseInfo (DatabaseId id , State state ) {
@@ -181,6 +264,8 @@ public DatabaseInfo(DatabaseId id, State state) {
181264 this .encryptionConfig = null ;
182265 this .defaultLeader = null ;
183266 this .dialect = null ;
267+ this .dropProtectionEnabled = false ;
268+ this .reconciling = false ;
184269 this .proto = null ;
185270 }
186271
@@ -194,6 +279,8 @@ public DatabaseInfo(DatabaseId id, State state) {
194279 this .encryptionConfig = builder .encryptionConfig ;
195280 this .defaultLeader = builder .defaultLeader ;
196281 this .dialect = builder .dialect ;
282+ this .dropProtectionEnabled = builder .dropProtectionEnabled ;
283+ this .reconciling = builder .reconciling ;
197284 this .proto = builder .proto ;
198285 }
199286
@@ -262,6 +349,14 @@ public Timestamp getEarliestVersionTime() {
262349 return dialect ;
263350 }
264351
352+ public boolean isDropProtectionEnabled () {
353+ return dropProtectionEnabled ;
354+ }
355+
356+ public boolean getReconciling () {
357+ return reconciling ;
358+ }
359+
265360 /** Returns the raw proto instance that was used to construct this {@link Database}. */
266361 public @ Nullable com .google .spanner .admin .database .v1 .Database getProto () {
267362 return proto ;
@@ -284,7 +379,9 @@ public boolean equals(Object o) {
284379 && Objects .equals (earliestVersionTime , that .earliestVersionTime )
285380 && Objects .equals (encryptionConfig , that .encryptionConfig )
286381 && Objects .equals (defaultLeader , that .defaultLeader )
287- && Objects .equals (dialect , that .dialect );
382+ && Objects .equals (dialect , that .dialect )
383+ && Objects .equals (dropProtectionEnabled , that .dropProtectionEnabled )
384+ && Objects .equals (reconciling , that .reconciling );
288385 }
289386
290387 @ Override
@@ -298,13 +395,15 @@ public int hashCode() {
298395 earliestVersionTime ,
299396 encryptionConfig ,
300397 defaultLeader ,
301- dialect );
398+ dialect ,
399+ dropProtectionEnabled ,
400+ reconciling );
302401 }
303402
304403 @ Override
305404 public String toString () {
306405 return String .format (
307- "Database[%s, %s, %s, %s, %s, %s, %s, %s, %s]" ,
406+ "Database[%s, %s, %s, %s, %s, %s, %s, %s, %s %s %s ]" ,
308407 id .getName (),
309408 state ,
310409 createTime ,
@@ -313,6 +412,8 @@ public String toString() {
313412 earliestVersionTime ,
314413 encryptionConfig ,
315414 defaultLeader ,
316- dialect );
415+ dialect ,
416+ dropProtectionEnabled ,
417+ reconciling );
317418 }
318419}
0 commit comments