2424import com .google .bigtable .admin .v2 .DeleteTableRequest ;
2525import com .google .bigtable .admin .v2 .DropRowRangeRequest ;
2626import com .google .bigtable .admin .v2 .GetTableRequest ;
27- import com .google .bigtable .admin .v2 .InstanceName ;
2827import com .google .bigtable .admin .v2 .ListTablesRequest ;
29- import com .google .bigtable .admin .v2 .TableName ;
3028import com .google .cloud .bigtable .admin .v2 .BaseBigtableTableAdminClient .ListTablesPage ;
3129import com .google .cloud .bigtable .admin .v2 .BaseBigtableTableAdminClient .ListTablesPagedResponse ;
30+ import com .google .cloud .bigtable .admin .v2 .internal .NameUtil ;
3231import com .google .cloud .bigtable .admin .v2 .models .CreateTableRequest ;
3332import com .google .cloud .bigtable .admin .v2 .models .ModifyColumnFamiliesRequest ;
3433import com .google .cloud .bigtable .admin .v2 .models .Table ;
5251 * <p>Sample code to get started:
5352 *
5453 * <pre>{@code
55- * try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of( "[PROJECT]", "[INSTANCE]") )) {
54+ * try(BigtableTableAdminClient client = BigtableTableAdminClient.create("[PROJECT]", "[INSTANCE]")) {
5655 * CreateTable request =
5756 * CreateTableRequest.of("my-table")
5857 * .addFamily("cf1")
7372 *
7473 * <pre>{@code
7574 * BigtableTableAdminSettings tableAdminSettings = BigtableTableAdminSettings.newBuilder()
76- * .setInstanceName(InstanceName.of("[PROJECT]", "[INSTANCE]"))
75+ * .setProjectId("[PROJECT]")
76+ * .setInstanceId("[INSTANCE]")
7777 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
7878 * .build();
7979 *
8585 *
8686 * <pre>{@code
8787 * BigtableTableAdminSettings tableAdminSettings = BigtableTableAdminSettings.newBuilder()
88- * .setInstanceName(InstanceName.of("[PROJECT]", "[INSTANCE]"))
88+ * .setProjectId("[PROJECT]")
89+ * .setInstanceId("[INSTANCE]")
8990 * .setEndpoint(myEndpoint).build();
9091 *
9192 * BigtableTableAdminClient client = BigtableTableAdminClient.create(tableAdminSettings);
9293 * }</pre>
9394 */
9495public final class BigtableTableAdminClient implements AutoCloseable {
96+
9597 private final EnhancedBigtableTableAdminStub stub ;
96- private final InstanceName instanceName ;
98+ private final String projectId ;
99+ private final String instanceId ;
97100
98- /** Constructs an instance of BigtableTableAdminClient with the given instanceName. */
99- public static BigtableTableAdminClient create (@ Nonnull InstanceName instanceName )
100- throws IOException {
101- return create (BigtableTableAdminSettings .newBuilder ().setInstanceName (instanceName ).build ());
101+ /** Constructs an instance of BigtableTableAdminClient with the given project and instance ids. */
102+ public static BigtableTableAdminClient create (
103+ @ Nonnull String projectId , @ Nonnull String instanceId ) throws IOException {
104+ return create (
105+ BigtableTableAdminSettings .newBuilder ()
106+ .setProjectId (projectId )
107+ .setInstanceId (instanceId )
108+ .build ());
109+ }
110+
111+ /**
112+ * Constructs an instance of BigtableTableAdminClient with the given instanceName.
113+ *
114+ * @deprecated Please {@link #create(String, String)}.
115+ */
116+ @ Deprecated
117+ public static BigtableTableAdminClient create (
118+ @ Nonnull com .google .bigtable .admin .v2 .InstanceName instanceName ) throws IOException {
119+ return create (instanceName .getProject (), instanceName .getInstance ());
102120 }
103121
104122 /** Constructs an instance of BigtableTableAdminClient with the given settings. */
105123 public static BigtableTableAdminClient create (@ Nonnull BigtableTableAdminSettings settings )
106124 throws IOException {
107125 EnhancedBigtableTableAdminStub stub =
108126 EnhancedBigtableTableAdminStub .createEnhanced (settings .getStubSettings ());
109- return create (settings .getInstanceName (), stub );
127+ return create (settings .getProjectId (), settings . getInstanceId (), stub );
110128 }
111129
112130 /** Constructs an instance of BigtableTableAdminClient with the given instanceName and stub. */
113131 public static BigtableTableAdminClient create (
114- @ Nonnull InstanceName instanceName , @ Nonnull EnhancedBigtableTableAdminStub stub ) {
115- return new BigtableTableAdminClient (instanceName , stub );
132+ @ Nonnull String projectId ,
133+ @ Nonnull String instanceId ,
134+ @ Nonnull EnhancedBigtableTableAdminStub stub ) {
135+ return new BigtableTableAdminClient (projectId , instanceId , stub );
116136 }
117137
118138 private BigtableTableAdminClient (
119- @ Nonnull InstanceName instanceName , @ Nonnull EnhancedBigtableTableAdminStub stub ) {
120- Preconditions .checkNotNull (instanceName );
139+ @ Nonnull String projectId ,
140+ @ Nonnull String instanceId ,
141+ @ Nonnull EnhancedBigtableTableAdminStub stub ) {
142+ Preconditions .checkNotNull (projectId );
143+ Preconditions .checkNotNull (instanceId );
121144 Preconditions .checkNotNull (stub );
122- this .instanceName = instanceName ;
145+ this .projectId = projectId ;
146+ this .instanceId = instanceId ;
123147 this .stub = stub ;
124148 }
125149
126- /** Gets the instanceName this client is associated with. */
127- public InstanceName getInstanceName () {
128- return instanceName ;
150+ /** Gets the project id of the instance whose tables this client manages. */
151+ public String getProjectId () {
152+ return projectId ;
153+ }
154+
155+ /** Gets the id of the instance whose tables this client manages. */
156+ public String getInstanceId () {
157+ return instanceId ;
158+ }
159+
160+ /**
161+ * Gets the instanceName this client is associated with.
162+ *
163+ * @deprecated Please use {@link #getProjectId()} and {@link #getInstanceId()}.
164+ */
165+ @ Deprecated
166+ public com .google .bigtable .admin .v2 .InstanceName getInstanceName () {
167+ return com .google .bigtable .admin .v2 .InstanceName .of (projectId , instanceId );
129168 }
130169
131170 @ Override
@@ -183,7 +222,7 @@ public Table createTable(CreateTableRequest request) {
183222 @ SuppressWarnings ("WeakerAccess" )
184223 public ApiFuture <Table > createTableAsync (CreateTableRequest request ) {
185224 return transformToTableResponse (
186- this .stub .createTableCallable ().futureCall (request .toProto (instanceName )));
225+ this .stub .createTableCallable ().futureCall (request .toProto (projectId , instanceId )));
187226 }
188227
189228 /**
@@ -275,7 +314,9 @@ public Table modifyFamilies(ModifyColumnFamiliesRequest request) {
275314 @ SuppressWarnings ("WeakerAccess" )
276315 public ApiFuture <Table > modifyFamiliesAsync (ModifyColumnFamiliesRequest request ) {
277316 return transformToTableResponse (
278- this .stub .modifyColumnFamiliesCallable ().futureCall (request .toProto (instanceName )));
317+ this .stub
318+ .modifyColumnFamiliesCallable ()
319+ .futureCall (request .toProto (projectId , instanceId )));
279320 }
280321
281322 /**
@@ -500,7 +541,9 @@ public List<String> listTables() {
500541 @ SuppressWarnings ("WeakerAccess" )
501542 public ApiFuture <List <String >> listTablesAsync () {
502543 ListTablesRequest request =
503- ListTablesRequest .newBuilder ().setParent (instanceName .toString ()).build ();
544+ ListTablesRequest .newBuilder ()
545+ .setParent (NameUtil .formatInstanceName (projectId , instanceId ))
546+ .build ();
504547
505548 // TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the
506549 // paginated responses while maintaining the wrapper facade.
@@ -550,7 +593,7 @@ public ApiFuture<List<com.google.bigtable.admin.v2.Table>> apply(
550593 public List <String > apply (List <com .google .bigtable .admin .v2 .Table > protos ) {
551594 List <String > results = Lists .newArrayListWithCapacity (protos .size ());
552595 for (com .google .bigtable .admin .v2 .Table proto : protos ) {
553- results .add (TableName . parse (proto .getName ()). getTable ( ));
596+ results .add (NameUtil . extractTableIdFromTableName (proto .getName ()));
554597 }
555598 return results ;
556599 }
@@ -718,8 +761,10 @@ public ApiFuture<Void> dropAllRowsAsync(String tableId) {
718761 */
719762 @ SuppressWarnings ("WeakerAccess" )
720763 public void awaitReplication (String tableId ) {
721- TableName tableName =
722- TableName .of (instanceName .getProject (), instanceName .getInstance (), tableId );
764+ // TODO(igorbernstein2): remove usage of typesafe names
765+ com .google .bigtable .admin .v2 .TableName tableName =
766+ com .google .bigtable .admin .v2 .TableName .of (projectId , instanceId , tableId );
767+
723768 ApiExceptions .callAndTranslateApiException (
724769 stub .awaitReplicationCallable ().futureCall (tableName ));
725770 }
@@ -752,8 +797,9 @@ public void awaitReplication(String tableId) {
752797 */
753798 @ SuppressWarnings ("WeakerAccess" )
754799 public ApiFuture <Void > awaitReplicationAsync (final String tableId ) {
755- TableName tableName =
756- TableName .of (instanceName .getProject (), instanceName .getInstance (), tableId );
800+ // TODO(igorbernstein2): remove usage of trypesafe names
801+ com .google .bigtable .admin .v2 .TableName tableName =
802+ com .google .bigtable .admin .v2 .TableName .of (projectId , instanceId , tableId );
757803 return stub .awaitReplicationCallable ().futureCall (tableName );
758804 }
759805
@@ -762,7 +808,7 @@ public ApiFuture<Void> awaitReplicationAsync(final String tableId) {
762808 * projects/{project}/instances/{instance}/tables/{tableId}
763809 */
764810 private String getTableName (String tableId ) {
765- return TableName . of ( instanceName . getProject (), instanceName . getInstance () , tableId ). toString ( );
811+ return NameUtil . formatTableName ( projectId , instanceId , tableId );
766812 }
767813
768814 // TODO(igorbernstein): rename methods to make clear that they deal with futures.
0 commit comments