16
16
17
17
package com .google .cloud .spanner ;
18
18
19
+ import com .google .cloud .FieldSelector ;
19
20
import com .google .cloud .Timestamp ;
20
21
import com .google .cloud .spanner .encryption .CustomerManagedEncryption ;
21
22
import com .google .common .base .Preconditions ;
23
+ import com .google .protobuf .FieldMask ;
24
+ import com .google .spanner .admin .database .v1 .Database .State ;
22
25
import java .util .Objects ;
23
26
import javax .annotation .Nullable ;
24
27
25
28
/** Represents a Cloud Spanner database. */
26
29
public class DatabaseInfo {
27
30
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
+
28
55
public abstract static class Builder {
29
56
abstract Builder setState (State state );
30
57
@@ -58,6 +85,18 @@ public Builder setDialect(Dialect dialect) {
58
85
throw new UnsupportedOperationException ("Unimplemented" );
59
86
}
60
87
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
+
61
100
abstract Builder setProto (com .google .spanner .admin .database .v1 .Database proto );
62
101
63
102
/** Builds the database from this builder. */
@@ -74,6 +113,8 @@ abstract static class BuilderImpl extends Builder {
74
113
private CustomerManagedEncryption encryptionConfig ;
75
114
private String defaultLeader ;
76
115
private Dialect dialect = Dialect .GOOGLE_STANDARD_SQL ;
116
+ private boolean dropProtectionEnabled ;
117
+ private boolean reconciling ;
77
118
private com .google .spanner .admin .database .v1 .Database proto ;
78
119
79
120
BuilderImpl (DatabaseId id ) {
@@ -141,6 +182,24 @@ public Builder setDialect(Dialect dialect) {
141
182
return this ;
142
183
}
143
184
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
+
144
203
@ Override
145
204
Builder setProto (@ Nullable com .google .spanner .admin .database .v1 .Database proto ) {
146
205
this .proto = proto ;
@@ -151,13 +210,35 @@ Builder setProto(@Nullable com.google.spanner.admin.database.v1.Database proto)
151
210
/** State of the database. */
152
211
public enum State {
153
212
// 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
+ },
155
219
// 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
+ },
157
226
// 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
+ },
159
233
// 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 ();
161
242
}
162
243
163
244
private final DatabaseId id ;
@@ -169,6 +250,8 @@ public enum State {
169
250
private final CustomerManagedEncryption encryptionConfig ;
170
251
private final String defaultLeader ;
171
252
private final Dialect dialect ;
253
+ private final boolean dropProtectionEnabled ;
254
+ private final boolean reconciling ;
172
255
private final com .google .spanner .admin .database .v1 .Database proto ;
173
256
174
257
public DatabaseInfo (DatabaseId id , State state ) {
@@ -181,6 +264,8 @@ public DatabaseInfo(DatabaseId id, State state) {
181
264
this .encryptionConfig = null ;
182
265
this .defaultLeader = null ;
183
266
this .dialect = null ;
267
+ this .dropProtectionEnabled = false ;
268
+ this .reconciling = false ;
184
269
this .proto = null ;
185
270
}
186
271
@@ -194,6 +279,8 @@ public DatabaseInfo(DatabaseId id, State state) {
194
279
this .encryptionConfig = builder .encryptionConfig ;
195
280
this .defaultLeader = builder .defaultLeader ;
196
281
this .dialect = builder .dialect ;
282
+ this .dropProtectionEnabled = builder .dropProtectionEnabled ;
283
+ this .reconciling = builder .reconciling ;
197
284
this .proto = builder .proto ;
198
285
}
199
286
@@ -262,6 +349,14 @@ public Timestamp getEarliestVersionTime() {
262
349
return dialect ;
263
350
}
264
351
352
+ public boolean isDropProtectionEnabled () {
353
+ return dropProtectionEnabled ;
354
+ }
355
+
356
+ public boolean getReconciling () {
357
+ return reconciling ;
358
+ }
359
+
265
360
/** Returns the raw proto instance that was used to construct this {@link Database}. */
266
361
public @ Nullable com .google .spanner .admin .database .v1 .Database getProto () {
267
362
return proto ;
@@ -284,7 +379,9 @@ public boolean equals(Object o) {
284
379
&& Objects .equals (earliestVersionTime , that .earliestVersionTime )
285
380
&& Objects .equals (encryptionConfig , that .encryptionConfig )
286
381
&& 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 );
288
385
}
289
386
290
387
@ Override
@@ -298,13 +395,15 @@ public int hashCode() {
298
395
earliestVersionTime ,
299
396
encryptionConfig ,
300
397
defaultLeader ,
301
- dialect );
398
+ dialect ,
399
+ dropProtectionEnabled ,
400
+ reconciling );
302
401
}
303
402
304
403
@ Override
305
404
public String toString () {
306
405
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 ]" ,
308
407
id .getName (),
309
408
state ,
310
409
createTime ,
@@ -313,6 +412,8 @@ public String toString() {
313
412
earliestVersionTime ,
314
413
encryptionConfig ,
315
414
defaultLeader ,
316
- dialect );
415
+ dialect ,
416
+ dropProtectionEnabled ,
417
+ reconciling );
317
418
}
318
419
}
0 commit comments