@@ -43,11 +43,9 @@ public abstract class ConsistencyRequest {
4343 @ Nullable
4444 public abstract String getConsistencyToken ();
4545
46- protected abstract boolean isFullyQualified ();
47-
4846 public static ConsistencyRequest forReplication (String tableId ) {
4947 return new AutoValue_ConsistencyRequest (
50- tableId , CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES , null , false );
48+ tableId , CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES , null );
5149 }
5250
5351 /**
@@ -61,127 +59,37 @@ public static ConsistencyRequest forReplication(String tableId, String consisten
6159 Preconditions .checkNotNull (consistencyToken , "consistencyToken must not be null" );
6260
6361 return new AutoValue_ConsistencyRequest (
64- tableId ,
65- CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES ,
66- consistencyToken ,
67- false );
62+ tableId , CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES , consistencyToken );
6863 }
6964
7065 public static ConsistencyRequest forDataBoost (String tableId ) {
7166 return new AutoValue_ConsistencyRequest (
72- tableId , CheckConsistencyRequest .ModeCase .DATA_BOOST_READ_LOCAL_WRITES , null , false );
73- }
74-
75- @ InternalApi
76- public static ConsistencyRequest forReplicationFromTableName (String tableName ) {
77- Preconditions .checkArgument (
78- TableName .isParsableFrom (tableName ), "tableName must be a fully qualified table name" );
79- return new AutoValue_ConsistencyRequest (
80- tableName , CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES , null , true );
67+ tableId , CheckConsistencyRequest .ModeCase .DATA_BOOST_READ_LOCAL_WRITES , null );
8168 }
8269
83- @ InternalApi
84- public static ConsistencyRequest forReplicationFromTableName (
85- String tableName , String consistencyToken ) {
86- Preconditions .checkArgument (
87- TableName .isParsableFrom (tableName ), "tableName must be a fully qualified table name" );
88- Preconditions .checkNotNull (consistencyToken , "consistencyToken must not be null" );
89-
90- return new AutoValue_ConsistencyRequest (
91- tableName ,
92- CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES ,
93- consistencyToken ,
94- true );
95- }
96-
97- private CheckConsistencyRequest .Builder buildBaseRequest (String name , String token ) {
98- CheckConsistencyRequest .Builder builder = CheckConsistencyRequest .newBuilder ();
99-
100- if (getMode ().equals (CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES )) {
101- builder .setStandardReadRemoteWrites (StandardReadRemoteWrites .newBuilder ().build ());
102- } else {
103- builder .setDataBoostReadLocalWrites (DataBoostReadLocalWrites .newBuilder ().build ());
104- }
105-
106- return builder .setName (name ).setConsistencyToken (token );
107- }
108-
109- /**
110- * Creates a CheckConsistencyRequest proto. This variant is used when the ConsistencyRequest was
111- * initialized with a short table ID, relying on the TableAdminRequestContext to construct the
112- * fully qualified table name.
113- */
11470 @ InternalApi
11571 public CheckConsistencyRequest toCheckConsistencyProto (
11672 TableAdminRequestContext requestContext , String token ) {
117- Preconditions .checkState (
118- !isFullyQualified (),
119- "Use toCheckConsistencyProto(String token) for fully qualified table names." );
73+ CheckConsistencyRequest .Builder builder = CheckConsistencyRequest .newBuilder ();
12074 TableName tableName =
12175 TableName .of (requestContext .getProjectId (), requestContext .getInstanceId (), getTableId ());
12276
123- return buildBaseRequest (tableName .toString (), token ).build ();
124- }
125-
126- /**
127- * Creates a CheckConsistencyRequest proto. This variant is used when the ConsistencyRequest was
128- * initialized with a fully qualified table name, eliminating the need for a request context.
129- */
130- @ InternalApi
131- public CheckConsistencyRequest toCheckConsistencyProto (String token ) {
132- Preconditions .checkState (
133- isFullyQualified (),
134- "Use toCheckConsistencyProto(TableAdminRequestContext, String) for non-qualified table"
135- + " names." );
136-
137- return buildBaseRequest (getTableId (), token ).build ();
138- }
139-
140- /**
141- * Creates a GenerateConsistencyTokenRequest proto. This variant is used when the
142- * ConsistencyRequest was initialized with a short table ID, relying on the
143- * TableAdminRequestContext to construct the fully qualified table name.
144- */
145- @ InternalApi
146- public CheckConsistencyRequest toCheckConsistencyProto (String token ) {
147- Preconditions .checkState (
148- isFullyQualified (),
149- "Use toCheckConsistencyProto(TableAdminRequestContext, String) for non-qualified table"
150- + " names." );
151- CheckConsistencyRequest .Builder builder = CheckConsistencyRequest .newBuilder ();
152-
15377 if (getMode ().equals (CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES )) {
15478 builder .setStandardReadRemoteWrites (StandardReadRemoteWrites .newBuilder ().build ());
15579 } else {
15680 builder .setDataBoostReadLocalWrites (DataBoostReadLocalWrites .newBuilder ().build ());
15781 }
15882
159- return builder .setName (getTableId ()).setConsistencyToken (token ).build ();
83+ return builder .setName (tableName . toString ()).setConsistencyToken (token ).build ();
16084 }
16185
16286 @ InternalApi
16387 public GenerateConsistencyTokenRequest toGenerateTokenProto (
16488 TableAdminRequestContext requestContext ) {
165- Preconditions .checkState (
166- !isFullyQualified (), "Use toGenerateTokenProto() for fully qualified table names." );
16789 GenerateConsistencyTokenRequest .Builder builder = GenerateConsistencyTokenRequest .newBuilder ();
16890 TableName tableName =
16991 TableName .of (requestContext .getProjectId (), requestContext .getInstanceId (), getTableId ());
17092
17193 return builder .setName (tableName .toString ()).build ();
17294 }
173-
174- /**
175- * Creates a GenerateConsistencyTokenRequest proto. This variant is used when the
176- * ConsistencyRequest was initialized with a fully qualified table name, eliminating the need for
177- * a request context.
178- */
179- @ InternalApi
180- public GenerateConsistencyTokenRequest toGenerateTokenProto () {
181- Preconditions .checkState (
182- isFullyQualified (),
183- "Use toGenerateTokenProto(TableAdminRequestContext) for non-qualified table names." );
184- GenerateConsistencyTokenRequest .Builder builder = GenerateConsistencyTokenRequest .newBuilder ();
185- return builder .setName (getTableId ()).build ();
186- }
18795}
0 commit comments