Class JpqlValidatorSupport

java.lang.Object
io.jmix.aitools.dataload.validation.validator.JpqlValidatorSupport

public final class JpqlValidatorSupport extends Object
Shared helpers for JPQL validators.
  • Method Details

    • containsWord

      public static boolean containsWord(String text, String word)
      Returns whether the text contains the given word as a whole word.
      Parameters:
      text - text to search
      word - word to look for
      Returns:
      true if the word is present
    • containsFunctionCall

      public static boolean containsFunctionCall(String text, String functionName)
      Returns whether the text contains a call to the given function (its name followed by '(').
      Parameters:
      text - text to search
      functionName - function name to look for
      Returns:
      true if such a function call is present
    • stripStringLiterals

      public static String stripStringLiterals(String jpql)
      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

      public static List<String> extractAliases(String jpql)
      Extracts the alias names declared with AS at the top level of the query — that is, identification variables (entity and join aliases) and select result variables. An AS inside parentheses (such as the target type of CAST(... AS ...) or TREAT(... 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 a QueryParser.
      Parameters:
      queryTransformerFactory - factory used to create the parser, may be null if unavailable
      jpql - JPQL text to parse
      Returns:
      the parser, or null if the factory is missing, the text is blank, or parsing fails