Class JpqlValidatorSupport
java.lang.Object
io.jmix.aitools.dataload.validation.validator.JpqlValidatorSupport
Shared helpers for JPQL validators.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsFunctionCall(String text, String functionName) Returns whether the text contains a call to the given function (its name followed by'(').static booleancontainsWord(String text, String word) Returns whether the text contains the given word as a whole word.extractAliases(String jpql) Extracts the alias names declared withASat the top level of the query — that is, identification variables (entity and join aliases) and select result variables.static @Nullable QueryParsergetQueryParser(@Nullable QueryTransformerFactory queryTransformerFactory, @Nullable String jpql) Parses the given JPQL into aQueryParser.static StringstripStringLiterals(String jpql) Replaces every single-quoted string literal with an empty literal (''), so the literal's content (e.g.
-
Method Details
-
containsWord
Returns whether the text contains the given word as a whole word.- Parameters:
text- text to searchword- word to look for- Returns:
trueif the word is present
-
containsFunctionCall
Returns whether the text contains a call to the given function (its name followed by'(').- Parameters:
text- text to searchfunctionName- function name to look for- Returns:
trueif such a function call is present
-
stripStringLiterals
Replaces every single-quoted string literal with an empty literal (''), so the literal's content (e.g. a:-prefixed word or an uppercase token) is not mistaken for a JPQL parameter, keyword or constant.- Parameters:
jpql- JPQL text- Returns:
- the text with all string literals emptied
-
extractAliases
Extracts the alias names declared withASat the top level of the query — that is, identification variables (entity and join aliases) and select result variables. AnASinside parentheses (such as the target type ofCAST(... AS ...)orTREAT(... AS ...)) is not an alias declaration and is skipped. String literals are ignored.- Parameters:
jpql- JPQL text- Returns:
- the declared alias names in order of appearance; empty if there are none
-
getQueryParser
public static @Nullable QueryParser getQueryParser(@Nullable QueryTransformerFactory queryTransformerFactory, @Nullable String jpql) Parses the given JPQL into aQueryParser.- Parameters:
queryTransformerFactory- factory used to create the parser, may benullif unavailablejpql- JPQL text to parse- Returns:
- the parser, or
nullif the factory is missing, the text is blank, or parsing fails
-