Class SqlUtils
java.lang.Object
com.blazebit.persistence.impl.util.SqlUtils
Utility class to extract information from SQL queries.
- Since:
- 1.2.0
- Author:
- Christian Beikov
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final Stringstatic final PatternFinderstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinderstatic final Stringstatic final PatternFinder -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyTableNameRemapping(StringBuilder sb, ExtendedQuerySupport.SqlFromInfo sqlFromInfo, String newCteName, String aliasExtension, String newSqlAlias, boolean useApply) static voidapplyTableNameRemapping(StringBuilder sb, String sqlAlias, String newCteName, String aliasExtension, String newSqlAlias, boolean useApply) static voidbuildAliasMappingForTopLevelSelects(CharSequence sql, String alias, Map<String, String> aliasMapping) static StringextractAlias(CharSequence sb, int index) Extracts the next alias from the given expression starting the given index.static StringExtracts the alias part of a select item expression.static intfindEndOfOnClause(CharSequence sqlSb, int predicateStartIndex, int whereIndex) static intfindJoinStartIndex(CharSequence sqlSb, int aliasIndex) static intfindJoinStartIndex(CharSequence sqlSb, int tokenEnd, Set<com.blazebit.persistence.impl.util.SqlUtils.JoinToken> allowedTokens) getExpressionItems(CharSequence sql, int i, int end) getExpressionItems(CharSequence sql, int i, int end, SqlUtils.SelectItemExtractor extractor) static String[]getSelectItemAliases(CharSequence sql, int start) Extracts the select item aliases of an arbitrary SELECT query.static String[]getSelectItemColumns(CharSequence sql, int start) static String[]getSelectItemExpressions(CharSequence sql, int start) static String[]getSelectItems(CharSequence sql, int start, SqlUtils.SelectItemExtractor extractor) static intindexOfFetchFirst(CharSequence sql, int start) static int[]indexOfFinalTableSubquery(CharSequence sql, int selectIndex) Finds the final table clause in an arbitrary SELECT query.static intindexOfFrom(CharSequence sql) static intindexOfFrom(CharSequence sql, int start) static int[]indexOfFullJoin(CharSequence sql, String tableAlias) static int[]indexOfFullJoin(CharSequence sql, String tableAlias, int whereIndex) static int[]indexOfFullJoin(CharSequence sql, String tableAlias, int aliasIndex, int whereIndex) static intindexOfGroupBy(CharSequence sql, int start) static intindexOfHaving(CharSequence sql, int start) static intindexOfJoinTableAlias(CharSequence sql, String tableAlias) static intindexOfLimit(CharSequence sql) Finds the toplevel LIMIT keyword in an arbitrary query.static intindexOfLimit(CharSequence sql, int start) static intindexOfOn(CharSequence sql, int start) static intFinds the toplevel ORDER BY keyword in an arbitrary query.static intindexOfOrderBy(CharSequence sql, int start) static intFinds the toplevel SELECT keyword in an arbitrary SELECT query.static intindexOfSet(CharSequence sql) static intindexOfTableName(CharSequence sql, String tableName) Finds the table name within a FROM clause of an arbitrary SELECT query.static intindexOfWhere(CharSequence sql) Finds the toplevel WHERE keyword in an arbitrary query.static intindexOfWhere(CharSequence sql, int start) static booleanisIdentifier(char c) static booleanisIdentifierStart(char c) static voidremapColumnExpressions(StringBuilder sqlSb, Map<String, String> columnExpressionRemappings) static intremapColumnExpressions(StringBuilder sqlSb, Map<String, String> columnExpressionRemappings, int startIndex, int endIndex) static int[]rtrimBackwardsToFirstWhitespace(CharSequence sb, int startIndex)
-
Field Details
-
SELECT
- See Also:
-
UPDATE
- See Also:
-
SET
- See Also:
-
FROM
- See Also:
-
JOIN
- See Also:
-
ON
- See Also:
-
WITH
- See Also:
-
WHERE
- See Also:
-
GROUP_BY
- See Also:
-
HAVING
- See Also:
-
ORDER_BY
- See Also:
-
LIMIT
- See Also:
-
FETCH_FIRST
- See Also:
-
AS
- See Also:
-
FROM_FINAL_TABLE
- See Also:
-
NEXT_VALUE_FOR
- See Also:
-
INTO
- See Also:
-
SELECT_FINDER
-
UPDATE_FINDER
-
SET_FINDER
-
FROM_FINDER
-
JOIN_FINDER
-
ON_FINDER
-
WITH_FINDER
-
WHERE_FINDER
-
GROUP_BY_FINDER
-
HAVING_FINDER
-
ORDER_BY_FINDER
-
LIMIT_FINDER
-
FETCH_FIRST_FINDER
-
AS_FINDER
-
FROM_FINAL_TABLE_FINDER
-
NEXT_VALUE_FOR_FINDER
-
INTO_FINDER
-
-
Method Details
-
applyTableNameRemapping
public static void applyTableNameRemapping(StringBuilder sb, ExtendedQuerySupport.SqlFromInfo sqlFromInfo, String newCteName, String aliasExtension, String newSqlAlias, boolean useApply) -
applyTableNameRemapping
public static void applyTableNameRemapping(StringBuilder sb, String sqlAlias, String newCteName, String aliasExtension, String newSqlAlias, boolean useApply) -
remapColumnExpressions
public static void remapColumnExpressions(StringBuilder sqlSb, Map<String, String> columnExpressionRemappings) -
remapColumnExpressions
public static int remapColumnExpressions(StringBuilder sqlSb, Map<String, String> columnExpressionRemappings, int startIndex, int endIndex) -
rtrimBackwardsToFirstWhitespace
-
isIdentifierStart
public static boolean isIdentifierStart(char c) -
isIdentifier
public static boolean isIdentifier(char c) -
getSelectItemAliases
Extracts the select item aliases of an arbitrary SELECT query.- Parameters:
sql- The SQL querystart- The start index from which to look for select items- Returns:
- The select item aliases
-
getSelectItemExpressions
-
getSelectItemColumns
-
getSelectItems
public static String[] getSelectItems(CharSequence sql, int start, SqlUtils.SelectItemExtractor extractor) -
getExpressionItems
-
getExpressionItems
-
getExpressionItems
public static List<String> getExpressionItems(CharSequence sql, int i, int end, SqlUtils.SelectItemExtractor extractor) -
buildAliasMappingForTopLevelSelects
public static void buildAliasMappingForTopLevelSelects(CharSequence sql, String alias, Map<String, String> aliasMapping) -
indexOfSelect
Finds the toplevel SELECT keyword in an arbitrary SELECT query.- Parameters:
sql- The SQL query- Returns:
- The index of the SELECT keyword if found, or -1
-
indexOfSet
-
indexOfFrom
-
indexOfFrom
-
indexOfWhere
Finds the toplevel WHERE keyword in an arbitrary query.- Parameters:
sql- The SQL query- Returns:
- The index of the SELECT keyword if found, or -1
-
indexOfWhere
-
indexOfGroupBy
-
indexOfHaving
-
indexOfOrderBy
Finds the toplevel ORDER BY keyword in an arbitrary query.- Parameters:
sql- The SQL query- Returns:
- The index of the ORDER BY keyword if found, or -1
-
indexOfOrderBy
-
indexOfLimit
Finds the toplevel LIMIT keyword in an arbitrary query.- Parameters:
sql- The SQL query- Returns:
- The index of the LIMIT keyword if found, or -1
-
indexOfLimit
-
indexOfFetchFirst
-
indexOfOn
-
indexOfFinalTableSubquery
Finds the final table clause in an arbitrary SELECT query.- Parameters:
sql- The SQL queryselectIndex- The start index or the index of the toplevel SELECT keyword in the query- Returns:
- The start and end index of the final table subquery if found, or 0 and the length of the query
-
indexOfTableName
Finds the table name within a FROM clause of an arbitrary SELECT query.- Parameters:
sql- The SQL querytableName- The table name to look for- Returns:
- The index of the table name or -1 if it couldn't be found
-
indexOfJoinTableAlias
-
indexOfFullJoin
-
indexOfFullJoin
-
indexOfFullJoin
public static int[] indexOfFullJoin(CharSequence sql, String tableAlias, int aliasIndex, int whereIndex) -
findJoinStartIndex
-
findJoinStartIndex
public static int findJoinStartIndex(CharSequence sqlSb, int tokenEnd, Set<com.blazebit.persistence.impl.util.SqlUtils.JoinToken> allowedTokens) -
findEndOfOnClause
-
extractAlias
Extracts the alias part of a select item expression.- Parameters:
sb- The string builder containing the select item expression- Returns:
- The alias of the select item expression
-
extractAlias
Extracts the next alias from the given expression starting the given index.- Parameters:
sb- The char sequence containing the aliasindex- The start index- Returns:
- The next alias of the char sequence
-