Class AbstractStatementParser (6.58.0)

public abstract class AbstractStatementParser

Internal class for the Spanner Connection API.

Parses ClientSideStatements and normal SQL statements. The parser is able to recognize the type of statement, allowing the connection API to know which method on Spanner should be called. The parser does not validate the validity of statements, except for ClientSideStatements. This means that an invalid DML statement could be accepted by the AbstractStatementParser and sent to Spanner, and Spanner will then reject it with some error message.

Inheritance

java.lang.Object > AbstractStatementParser

Static Fields

DEFAULT_MAX_STATEMENT_CACHE_SIZE_MB

public static final int DEFAULT_MAX_STATEMENT_CACHE_SIZE_MB

The default maximum size of the statement cache in Mb.

Field Value
TypeDescription
int

Static Methods

getInstance(Dialect dialect)

public static AbstractStatementParser getInstance(Dialect dialect)

Get an instance of AbstractStatementParser for the specified dialect.

Parameter
NameDescription
dialectDialect
Returns
TypeDescription
AbstractStatementParser

Methods

checkReturningClause(String sql)

public boolean checkReturningClause(String sql)

Checks if the given SQL string contains a Returning clause. This method is used only in case of a DML statement.

Parameter
NameDescription
sqlString

The sql string without comments that has to be evaluated.

Returns
TypeDescription
boolean

A boolean indicating whether the sql string has a Returning clause or not.

checkReturningClauseInternal(String sql)

protected abstract boolean checkReturningClauseInternal(String sql)

Checks if the given SQL string contains a Returning clause. This method is used only in case of a DML statement.

Parameter
NameDescription
sqlString

The sql string without comments that has to be evaluated.

Returns
TypeDescription
boolean

A boolean indicating whether the sql string has a Returning clause or not.

convertPositionalParametersToNamedParameters(char paramChar, String sql)

public AbstractStatementParser.ParametersInfo convertPositionalParametersToNamedParameters(char paramChar, String sql)

Converts all positional parameters (?) in the given sql string into named parameters. The parameters are named @p1, @p2, etc. This method is used when converting a JDBC statement that uses positional parameters to a Cloud Spanner Statement instance that requires named parameters. The input SQL string may not contain any comments. There is an exception case if the statement starts with a GSQL comment which forces it to be interpreted as a GoogleSql statement.

Parameters
NameDescription
paramCharchar
sqlString

The sql string without comments that should be converted

Returns
TypeDescription
AbstractStatementParser.ParametersInfo

A ParametersInfo object containing a string with named parameters instead of positional parameters and the number of parameters.

isDdlStatement(String sql)

public boolean isDdlStatement(String sql)

Checks whether the given statement is (probably) a DDL statement. The method does not check the validity of the statement, only if it is a DDL statement based on the first word in the statement.

Parameter
NameDescription
sqlString

The statement to check (without any comments).

Returns
TypeDescription
boolean

true if the statement is a DDL statement (i.e. starts with 'CREATE', 'ALTER' or 'DROP').

isQuery(String sql)

public boolean isQuery(String sql)

Checks whether the given statement is (probably) a SELECT query. The method does not check the validity of the statement, only if it is a SELECT statement based on the first word in the statement.

Parameter
NameDescription
sqlString

The statement to check (without any comments).

Returns
TypeDescription
boolean

true if the statement is a SELECT statement (i.e. starts with 'SELECT').

isUpdateStatement(String sql)

public boolean isUpdateStatement(String sql)

Checks whether the given statement is (probably) an update statement. The method does not check the validity of the statement, only if it is an update statement based on the first word in the statement.

Parameter
NameDescription
sqlString

The statement to check (without any comments).

Returns
TypeDescription
boolean

true if the statement is a DML update statement (i.e. starts with 'INSERT', 'UPDATE' or 'DELETE').

parse(Statement statement)

public AbstractStatementParser.ParsedStatement parse(Statement statement)

Parses the given statement and categorizes it as one of the possible StatementTypes. The validity of the statement is not checked, unless it is a client-side statement.

Parameter
NameDescription
statementStatement

The statement to parse.

Returns
TypeDescription
AbstractStatementParser.ParsedStatement

the parsed and categorized statement.

removeCommentsAndTrim(String sql)

public String removeCommentsAndTrim(String sql)

Removes comments from and trims the given sql statement using the dialect of this parser.

Parameter
NameDescription
sqlString

The sql statement to remove comments from and to trim.

Returns
TypeDescription
String

the sql statement without the comments and leading and trailing spaces.

supportsExplain()

protected abstract boolean supportsExplain()
Returns
TypeDescription
boolean