@@ -90,42 +90,49 @@ public static ConsistencyRequest forReplicationFromTableName(
9090 true );
9191 }
9292
93- @ InternalApi
94- public CheckConsistencyRequest toCheckConsistencyProto (
95- TableAdminRequestContext requestContext , String token ) {
96- Preconditions .checkState (
97- !isFullyQualified (),
98- "Use toCheckConsistencyProto(String token) for fully qualified table names." );
93+ private CheckConsistencyRequest .Builder buildBaseRequest (String name , String token ) {
9994 CheckConsistencyRequest .Builder builder = CheckConsistencyRequest .newBuilder ();
100- TableName tableName =
101- TableName .of (requestContext .getProjectId (), requestContext .getInstanceId (), getTableId ());
10295
10396 if (getMode ().equals (CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES )) {
10497 builder .setStandardReadRemoteWrites (StandardReadRemoteWrites .newBuilder ().build ());
10598 } else {
10699 builder .setDataBoostReadLocalWrites (DataBoostReadLocalWrites .newBuilder ().build ());
107100 }
108101
109- return builder .setName (tableName . toString ()) .setConsistencyToken (token ). build ( );
102+ return builder .setName (name ) .setConsistencyToken (token );
110103 }
111104
105+ /**
106+ * Creates a CheckConsistencyRequest proto. This variant is used when the ConsistencyRequest
107+ * was initialized with a short table ID, relying on the TableAdminRequestContext to construct
108+ * the fully qualified table name.
109+ */
112110 @ InternalApi
113- public CheckConsistencyRequest toCheckConsistencyProto (String token ) {
114- Preconditions .checkState (
115- isFullyQualified (),
116- "Use toCheckConsistencyProto(TableAdminRequestContext, String) for non-qualified table"
117- + " names." );
118- CheckConsistencyRequest .Builder builder = CheckConsistencyRequest .newBuilder ();
111+ public CheckConsistencyRequest toCheckConsistencyProto (
112+ TableAdminRequestContext requestContext , String token ) {
113+ Preconditions .checkState (!isFullyQualified (), "Use toCheckConsistencyProto(String token) for fully qualified table names." );
114+ TableName tableName =
115+ TableName .of (requestContext .getProjectId (), requestContext .getInstanceId (), getTableId ());
119116
120- if (getMode ().equals (CheckConsistencyRequest .ModeCase .STANDARD_READ_REMOTE_WRITES )) {
121- builder .setStandardReadRemoteWrites (StandardReadRemoteWrites .newBuilder ().build ());
122- } else {
123- builder .setDataBoostReadLocalWrites (DataBoostReadLocalWrites .newBuilder ().build ());
124- }
117+ return buildBaseRequest (tableName .toString (), token ).build ();
118+ }
125119
126- return builder .setName (getTableId ()).setConsistencyToken (token ).build ();
120+ /**
121+ * Creates a CheckConsistencyRequest proto. This variant is used when the ConsistencyRequest
122+ * was initialized with a fully qualified table name, eliminating the need for a request context.
123+ */
124+ @ InternalApi
125+ public CheckConsistencyRequest toCheckConsistencyProto (String token ) {
126+ Preconditions .checkState (isFullyQualified (), "Use toCheckConsistencyProto(TableAdminRequestContext, String) for non-qualified table names." );
127+
128+ return buildBaseRequest (getTableId (), token ).build ();
127129 }
128130
131+ /**
132+ * Creates a GenerateConsistencyTokenRequest proto. This variant is used when the ConsistencyRequest
133+ * was initialized with a short table ID, relying on the TableAdminRequestContext to construct
134+ * the fully qualified table name.
135+ */
129136 @ InternalApi
130137 public GenerateConsistencyTokenRequest toGenerateTokenProto (
131138 TableAdminRequestContext requestContext ) {
@@ -138,6 +145,10 @@ public GenerateConsistencyTokenRequest toGenerateTokenProto(
138145 return builder .setName (tableName .toString ()).build ();
139146 }
140147
148+ /**
149+ * Creates a GenerateConsistencyTokenRequest proto. This variant is used when the ConsistencyRequest
150+ * was initialized with a fully qualified table name, eliminating the need for a request context.
151+ */
141152 @ InternalApi
142153 public GenerateConsistencyTokenRequest toGenerateTokenProto () {
143154 Preconditions .checkState (
0 commit comments