Skip to content

Commit a0f05ad

Browse files
authored
chore: make statement parsing public (marked as InternalApi) (#1690)
Statement parsing is currently done internally in the Connection API do determine what RPC to execute on the backend. The parsing is however also very useful to some other applications, specifically PgAdapter, which can use this to determine what response to send to a PG client. This makes the parse method and related class and methods public, but marks them as InternalApi, so they can be used in PgAdapter. This follows the same pattern that was used to expose certain methods in the Connection API for the JDBC driver.
1 parent 4cfe74e commit a0f05ad

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
130130
.parse(Statement.of("RUN BATCH"));
131131

132132
/** The type of statement that has been recognized by the parser. */
133-
enum StatementType {
133+
@InternalApi
134+
public enum StatementType {
134135
CLIENT_SIDE,
135136
DDL,
136137
QUERY,
@@ -139,7 +140,8 @@ enum StatementType {
139140
}
140141

141142
/** A statement that has been parsed */
142-
static class ParsedStatement {
143+
@InternalApi
144+
public static class ParsedStatement {
143145
private final StatementType type;
144146
private final ClientSideStatementImpl clientSideStatement;
145147
private final Statement statement;
@@ -217,11 +219,18 @@ public boolean equals(Object other) {
217219
&& Objects.equals(this.sqlWithoutComments, o.sqlWithoutComments);
218220
}
219221

220-
StatementType getType() {
222+
/** Returns the type of statement that was recognized by the parser. */
223+
@InternalApi
224+
public StatementType getType() {
221225
return type;
222226
}
223227

224-
boolean isQuery() {
228+
/**
229+
* Returns true if the statement is a query that will return a {@link
230+
* com.google.cloud.spanner.ResultSet}.
231+
*/
232+
@InternalApi
233+
public boolean isQuery() {
225234
switch (type) {
226235
case CLIENT_SIDE:
227236
return getClientSideStatement().isQuery();
@@ -235,7 +244,12 @@ boolean isQuery() {
235244
return false;
236245
}
237246

238-
boolean isUpdate() {
247+
/**
248+
* Returns true if the statement is a DML statement or a client side statement that will return
249+
* an update count.
250+
*/
251+
@InternalApi
252+
public boolean isUpdate() {
239253
switch (type) {
240254
case CLIENT_SIDE:
241255
return getClientSideStatement().isUpdate();
@@ -249,7 +263,9 @@ boolean isUpdate() {
249263
return false;
250264
}
251265

252-
boolean isDdl() {
266+
/** Returns true if the statement is a DDL statement. */
267+
@InternalApi
268+
public boolean isDdl() {
253269
switch (type) {
254270
case DDL:
255271
return true;
@@ -286,7 +302,9 @@ Statement mergeQueryOptions(Statement statement, QueryOptions defaultQueryOption
286302
.build();
287303
}
288304

289-
String getSqlWithoutComments() {
305+
/** Returns the SQL statement with all comments removed from the SQL string. */
306+
@InternalApi
307+
public String getSqlWithoutComments() {
290308
return sqlWithoutComments;
291309
}
292310

@@ -321,7 +339,8 @@ ClientSideStatement getClientSideStatement() {
321339
* @param statement The statement to parse.
322340
* @return the parsed and categorized statement.
323341
*/
324-
ParsedStatement parse(Statement statement) {
342+
@InternalApi
343+
public ParsedStatement parse(Statement statement) {
325344
return parse(statement, null);
326345
}
327346

0 commit comments

Comments
 (0)