Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 2c21c56

Browse files
committed
update according to PR
1 parent d716247 commit 2c21c56

6 files changed

Lines changed: 45 additions & 39 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateSchemaBundleRequest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <pre>{@code
3737
* CreateSchemaBundleRequest request =
3838
* CreateSchemaBundleRequest.of("my-table", "my-new-schema-bundle")
39-
* .setProtoSchema("proto_file.pb");
39+
* .setProtoSchemaFile("proto_file.pb");
4040
* }</pre>
4141
*
4242
* @see SchemaBundle for more details.
@@ -59,19 +59,21 @@ private CreateSchemaBundleRequest(@Nonnull String tableId, @Nonnull String schem
5959
requestBuilder.setSchemaBundleId(schemaBundleId);
6060
}
6161

62-
/**
63-
* Sets the proto schema for this schema bundle.
64-
*
65-
* @see SchemaBundleType for details.
66-
*/
67-
public CreateSchemaBundleRequest setProtoSchema(@Nonnull String protoSchemaFile)
62+
/** Sets the proto schema for this schema bundle. */
63+
public CreateSchemaBundleRequest setProtoSchemaFile(@Nonnull String protoSchemaFile)
6864
throws IOException {
69-
Preconditions.checkNotNull(protoSchemaFile, "protoSchema must be set");
65+
Preconditions.checkNotNull(protoSchemaFile, "protoSchemaFile must be set");
7066
byte[] content = Files.readAllBytes(Paths.get(protoSchemaFile));
67+
return setProtoSchema(ByteString.copyFrom(content));
68+
}
69+
70+
/** Sets the proto schema for this schema bundle. */
71+
public CreateSchemaBundleRequest setProtoSchema(@Nonnull ByteString protoSchema)
72+
throws IOException {
73+
Preconditions.checkNotNull(protoSchema, "protoSchema must be set");
7174
requestBuilder.setSchemaBundle(
7275
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
73-
.setProtoSchema(
74-
ProtoSchema.newBuilder().setProtoDescriptors(ByteString.copyFrom(content))));
76+
.setProtoSchema(ProtoSchema.newBuilder().setProtoDescriptors(protoSchema)));
7577
return this;
7678
}
7779

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/SchemaBundle.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
public final class SchemaBundle {
2929
private final com.google.bigtable.admin.v2.SchemaBundle proto;
30+
private final SchemaBundleName schemaBundleName;
3031

3132
/**
3233
* Wraps the protobuf. This method is considered an internal implementation detail and not meant
@@ -43,22 +44,17 @@ private SchemaBundle(@Nonnull com.google.bigtable.admin.v2.SchemaBundle proto) {
4344
Preconditions.checkArgument(
4445
proto.hasProtoSchema(), "Schemabundle must have a proto_schema field");
4546
this.proto = proto;
47+
this.schemaBundleName = SchemaBundleName.parse(proto.getName());
4648
}
4749

4850
/** Gets the schema bundle's id. */
4951
public String getId() {
50-
// Constructor ensures that name is not null.
51-
SchemaBundleName fullName = SchemaBundleName.parse(proto.getName());
52-
5352
//noinspection ConstantConditions
5453
return fullName.getSchemaBundle();
5554
}
5655

5756
/** Gets the id of the table that owns this schema bundle. */
5857
public String getTableId() {
59-
// Constructor ensures that name is not null.
60-
SchemaBundleName fullName = SchemaBundleName.parse(proto.getName());
61-
6258
//noinspection ConstantConditions
6359
return fullName.getTable();
6460
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateSchemaBundleRequest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* <pre>{@code
3838
* SchemaBundle existingSchemaBundle = client.getSchemaBundle("my-table", "my-schema-bundle");
3939
* UpdateSchemaBundleRequest request =
40-
* UpdateSchemaBundleRequest.of(existingSchemaBundle).setProtoSchema("file.pb");
40+
* UpdateSchemaBundleRequest.of(existingSchemaBundle).setProtoSchemaFile("file.pb");
4141
* }</pre>
4242
*
4343
* @see SchemaBundle for more details.
@@ -78,13 +78,21 @@ private UpdateSchemaBundleRequest(
7878
this.requestBuilder = requestBuilder;
7979
}
8080

81-
/** Changes the deletion protection of an existing schema bundle. */
82-
public UpdateSchemaBundleRequest setProtoSchema(String protoSchemaFile) throws IOException {
81+
/** Sets the proto schema for this schema bundle. */
82+
public CreateSchemaBundleRequest setProtoSchemaFile(@Nonnull String protoSchemaFile)
83+
throws IOException {
84+
Preconditions.checkNotNull(protoSchemaFile, "protoSchemaFile must be set");
8385
byte[] content = Files.readAllBytes(Paths.get(protoSchemaFile));
86+
return setProtoSchema(ByteString.copyFrom(content));
87+
}
88+
89+
/** Sets the proto schema for this schema bundle. */
90+
public CreateSchemaBundleRequest setProtoSchema(@Nonnull ByteString protoSchema)
91+
throws IOException {
92+
Preconditions.checkNotNull(protoSchema, "protoSchema must be set");
8493
requestBuilder.setSchemaBundle(
8594
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
86-
.setProtoSchema(
87-
ProtoSchema.newBuilder().setProtoDescriptors(ByteString.copyFrom(content))));
95+
.setProtoSchema(ProtoSchema.newBuilder().setProtoDescriptors(protoSchema)));
8896
updateFieldMask(com.google.bigtable.admin.v2.SchemaBundle.PROTO_SCHEMA_FIELD_NUMBER);
8997
return this;
9098
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableSchemaBundleIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void createSchemaBundleAndGetSchemaBundleTest() throws IOException, URISy
102102

103103
CreateSchemaBundleRequest request =
104104
CreateSchemaBundleRequest.of(testTable.getId(), SchemaBundleId)
105-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
105+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
106106
try {
107107
SchemaBundle response = tableAdmin.createSchemaBundle(request);
108108
assertWithMessage("Got wrong schema bundle Id in createSchemaBundle")
@@ -157,7 +157,7 @@ public void updateSchemaBundleAndDeleteSchemaBundleTest()
157157
Files.readAllBytes(Paths.get(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE)));
158158
UpdateSchemaBundleRequest updateRequest =
159159
UpdateSchemaBundleRequest.of(testTable.getId(), SchemaBundleId)
160-
.setProtoSchema(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE));
160+
.setProtoSchemaFile(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE));
161161
response = tableAdmin.updateSchemaBundle(updateRequest);
162162
assertWithMessage("Got wrong deletion protection in UpdateSchemaBundle")
163163
.that(response.getProtoSchema())
@@ -187,7 +187,7 @@ public void updateSchemaBundleAndDeleteSchemaBundleTest()
187187
private CreateSchemaBundleRequest createSchemaBundleRequest(String SchemaBundleId)
188188
throws IOException, URISyntaxException {
189189
return CreateSchemaBundleRequest.of(testTable.getId(), SchemaBundleId)
190-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
190+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
191191
}
192192

193193
private static Table createAndPopulateTestTable(

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateSchemaBundleRequestTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class CreateSchemaBundleRequestTest {
4444
public void testToProto() throws IOException, URISyntaxException {
4545
CreateSchemaBundleRequest request =
4646
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
47-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
47+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
4848

4949
byte[] content = Files.readAllBytes(Paths.get(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE)));
5050

@@ -67,35 +67,35 @@ public void testToProto() throws IOException, URISyntaxException {
6767
public void testEquality() throws IOException, URISyntaxException {
6868
CreateSchemaBundleRequest request =
6969
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
70-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
70+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
7171

7272
assertThat(request)
7373
.isEqualTo(
7474
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
75-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE)));
75+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE)));
7676

7777
assertThat(request)
7878
.isNotEqualTo(
7979
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
80-
.setProtoSchema(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE)));
80+
.setProtoSchemaFile(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE)));
8181
}
8282

8383
@Test
8484
public void testHashCode() throws IOException, URISyntaxException {
8585
CreateSchemaBundleRequest request =
8686
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
87-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
87+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
8888

8989
assertThat(request.hashCode())
9090
.isEqualTo(
9191
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
92-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE))
92+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE))
9393
.hashCode());
9494

9595
assertThat(request.hashCode())
9696
.isNotEqualTo(
9797
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
98-
.setProtoSchema(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE))
98+
.setProtoSchemaFile(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE))
9999
.hashCode());
100100
}
101101

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateSchemaBundleRequestTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class UpdateSchemaBundleRequestTest {
4646
public void testToProto() throws IOException, URISyntaxException {
4747
UpdateSchemaBundleRequest request =
4848
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
49-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE))
49+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE))
5050
.setIgnoreWarnings(true);
5151
byte[] content = Files.readAllBytes(Paths.get(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE)));
5252

@@ -87,7 +87,7 @@ public void testUpdateProtoSchema() throws IOException, URISyntaxException {
8787

8888
UpdateSchemaBundleRequest request =
8989
UpdateSchemaBundleRequest.of(SchemaBundle.fromProto(existingSchemaBundle))
90-
.setProtoSchema(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE));
90+
.setProtoSchemaFile(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE));
9191

9292
com.google.bigtable.admin.v2.UpdateSchemaBundleRequest requestProto =
9393
com.google.bigtable.admin.v2.UpdateSchemaBundleRequest.newBuilder()
@@ -105,35 +105,35 @@ public void testUpdateProtoSchema() throws IOException, URISyntaxException {
105105
public void testEquality() throws IOException, URISyntaxException {
106106
UpdateSchemaBundleRequest request =
107107
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
108-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
108+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
109109

110110
assertThat(request)
111111
.isEqualTo(
112112
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
113-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE)));
113+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE)));
114114

115115
assertThat(request)
116116
.isNotEqualTo(
117117
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
118-
.setProtoSchema(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE)));
118+
.setProtoSchemaFile(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE)));
119119
}
120120

121121
@Test
122122
public void testHashCode() throws IOException, URISyntaxException {
123123
UpdateSchemaBundleRequest request =
124124
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
125-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
125+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE));
126126

127127
assertThat(request.hashCode())
128128
.isEqualTo(
129129
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
130-
.setProtoSchema(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE))
130+
.setProtoSchemaFile(getResourceFilePath(TEST_PROTO_SCHEMA_BUNDLE))
131131
.hashCode());
132132

133133
assertThat(request.hashCode())
134134
.isNotEqualTo(
135135
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
136-
.setProtoSchema(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE))
136+
.setProtoSchemaFile(getResourceFilePath(TEST_UPDATED_PROTO_SCHEMA_BUNDLE))
137137
.hashCode());
138138
}
139139

0 commit comments

Comments
 (0)