public class QueryInfo extends Object
| Modifier and Type | Field and Description |
|---|---|
private static String |
AS_CLAUSE |
private QueryInfo |
baseQueryInfo |
private int |
batchCount |
private static String |
CLOSING_MARKERS |
private boolean |
containsOnDuplicateKeyUpdate |
private String |
encoding |
private static String |
INSERT_STATEMENT |
private boolean |
isRewritableWithMultiValuesClause |
private static String |
LAST_INSERT_ID_FUNC |
private int |
numberOfPlaceholders |
private int |
numberOfQueries |
private static String[] |
ODKU_CLAUSE |
private static String |
OPENING_MARKERS |
private static String |
OVERRIDING_MARKERS |
private int |
queryLength |
private QueryReturnType |
queryReturnType |
private int |
queryStartPos |
private static String |
REPLACE_STATEMENT |
private String |
sql |
private char |
statementFirstChar |
private byte[][] |
staticSqlParts |
private static String |
VALUE_CLAUSE |
private int |
valuesClauseLength |
private ArrayList<Integer> |
valuesEndpoints |
| Modifier | Constructor and Description |
|---|---|
private |
QueryInfo(QueryInfo baseQueryInfo,
int batchCount)
Constructs a
QueryInfo object with a multi-value clause for the specified batch count, that stems from the specified baseQueryInfo. |
|
QueryInfo(String sql,
Session session,
String encoding)
Constructs a
QueryInfo object for the given query or multi-query. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsOnDuplicateKeyUpdate()
Does this query info represent a query that contains an ON DUPLICATE KEY UPDATE clause? This operation does not take into consideration the multiplicity
of queries in the original SQL.
|
static boolean |
containsOnDuplicateKeyUpdateClause(String sql,
boolean noBackslashEscapes)
Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause.
|
static char |
firstCharOfStatementUc(String sql,
boolean noBackslashEscapes)
Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
private static String |
getContextForWithStatement(String sql,
boolean noBackslashEscapes)
Returns the context of the WITH statement.
|
char |
getFirstStmtChar()
Returns the first character of the statement from the query used to build this
QueryInfo. |
int |
getNumberOfQueries()
Returns the number of queries identified in the original SQL string.
|
QueryInfo |
getQueryInfoForBatch(int count)
Returns a
QueryInfo for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing. |
QueryReturnType |
getQueryReturnType()
Returns the return type of the parsed query.
|
static QueryReturnType |
getQueryReturnType(String sql,
boolean noBackslashEscapes)
Returns the type of return that can be expected from executing the given query.
|
String |
getSqlForBatch()
Returns a preparable query for the batch count of this
QueryInfo. |
String |
getSqlForBatch(int count)
Returns a preparable query for the specified batch count.
|
byte[][] |
getStaticSqlParts()
Returns the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located.
|
int |
getValuesClauseLength()
If this object represents a query that is re-writable as a multi-values statement and if rewriting batched statements is enabled, then returns the
length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1.
|
static int |
indexOfStatementKeyword(String sql,
boolean noBackslashEscapes)
Finds and returns the position of the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
static boolean |
isReadOnlySafeQuery(String sql,
boolean noBackslashEscapes)
Checks whether the given query is safe to run in a read-only session.
|
boolean |
isRewritableWithMultiValuesClause()
Can this query be rewritten as a multi-values clause?
|
private static final String OPENING_MARKERS
private static final String CLOSING_MARKERS
private static final String OVERRIDING_MARKERS
private static final String INSERT_STATEMENT
private static final String REPLACE_STATEMENT
private static final String VALUE_CLAUSE
private static final String AS_CLAUSE
private static final String[] ODKU_CLAUSE
private static final String LAST_INSERT_ID_FUNC
private QueryInfo baseQueryInfo
private String sql
private String encoding
private QueryReturnType queryReturnType
private int queryLength
private int queryStartPos
private char statementFirstChar
private int batchCount
private int numberOfPlaceholders
private int numberOfQueries
private boolean containsOnDuplicateKeyUpdate
private boolean isRewritableWithMultiValuesClause
private int valuesClauseLength
private byte[][] staticSqlParts
public QueryInfo(String sql, Session session, String encoding)
QueryInfo object for the given query or multi-query. The parsed result of this query allows to determine the location of the
placeholders, the query static parts and whether this query can be rewritten as a multi-values clause query.sql - the query SQL string to parse and analyzesession - the Session under which the query analysis must be done.encoding - the characters encoding to use when extracting the query static parts as byte arrays.private QueryInfo(QueryInfo baseQueryInfo, int batchCount)
QueryInfo object with a multi-value clause for the specified batch count, that stems from the specified baseQueryInfo.baseQueryInfo - the QueryInfo instance that provides the query static parts used to create the new instance now augmented to accommodate the extra
number of parametersbatchCount - the number of batches, i.e., the number of times the VALUES clause needs to be repeated inside the new querypublic int getNumberOfQueries()
public QueryReturnType getQueryReturnType()
public char getFirstStmtChar()
QueryInfo.public int getValuesClauseLength()
public boolean containsOnDuplicateKeyUpdate()
true if the query or any of the original queries contain an ON DUPLICATE KEY UPDATE clause.public byte[][] getStaticSqlParts()
public boolean isRewritableWithMultiValuesClause()
true if the query can be rewritten as a multi-values query.public QueryInfo getQueryInfoForBatch(int count)
QueryInfo for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.count - the number of parameter batchesQueryInfopublic String getSqlForBatch()
QueryInfo.public String getSqlForBatch(int count)
count - number of parameter batchespublic static int indexOfStatementKeyword(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static char firstCharOfStatementUc(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static boolean isReadOnlySafeQuery(String sql, boolean noBackslashEscapes)
sql - the query to checknoBackslashEscapes - whether backslash escapes are disabled or nottrue if the query is read-only safe, false otherwise.public static QueryReturnType getQueryReturnType(String sql, boolean noBackslashEscapes)
sql - the query to checknoBackslashEscapes - whether backslash escapes are disabled or notQueryReturnType.private static String getContextForWithStatement(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static boolean containsOnDuplicateKeyUpdateClause(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or not.true if the query contains an ON DUPLICATE KEY UPDATE clause, false otherwise