Class JpqlLeftJoinSupport.Rewrite

java.lang.Object
io.jmix.aitools.dataload.execution.JpqlLeftJoinSupport.Rewrite
Enclosing class:
JpqlLeftJoinSupport

public static class JpqlLeftJoinSupport.Rewrite extends Object
Changes to one query, applied to its syntax tree in the order they are made.
  • Field Details

    • VARIABLE_PREFIX

      protected static final String VARIABLE_PREFIX
      See Also:
    • tree

      protected final QueryTree tree
    • usedVariables

      protected final Set<String> usedVariables
    • variableCounter

      protected int variableCounter
  • Constructor Details

    • Rewrite

      protected Rewrite(QueryTree tree)
  • Method Details

    • lowerCase

      protected static String lowerCase(String name)
    • newVariable

      public String newVariable()
      Returns a variable name the query does not declare and this rewrite has not returned before.
      Returns:
      the variable name
    • addWhereCondition

      public void addWhereCondition(String condition)
      Adds a condition to the main query's where, in conjunction with its own condition if any.
      Parameters:
      condition - JPQL condition
      Throws:
      IllegalStateException - if the condition cannot be parsed
    • addOnCondition

      public void addOnCondition(String variable, String condition)
      Adds a condition to the on clause of the join declaring the variable, in conjunction with the clause's own condition if any.
      Parameters:
      variable - variable declared by a join of the query
      condition - JPQL condition
      Throws:
      IllegalStateException - if no join declares the variable, or the condition cannot be parsed
    • joinReference

      public JpqlLeftJoinSupport.Rewrite.JoinedReference joinReference(String referencePath, String primaryKey)
      Joins the entity a to-one reference path leads to under a new variable, and points every read of the reference at that variable instead: <ref>.<pk> becomes the variable's key, and the reference itself becomes the variable's key in a null test, a group by or an order by item, and the variable elsewhere. A path in the on clause of the inner join declaring the path's variable is left as it is, since the new join has to follow that declaration.
      Parameters:
      referencePath - path from a variable of the main query to a to-one reference, such as d.parent
      primaryKey - name of the referenced entity's primary key attribute
      Returns:
      the new variable, if any, whether some paths were left in an inner join's on, and whether the main query selects the key through the reference
      Throws:
      IllegalArgumentException - if the path is not a variable followed by one attribute
      IllegalStateException - if the path's variable is not declared in the main query's from, or the query does not read the reference
      JpqlAccessConstraintException - if the reference is read in the on clause of the left join declaring its variable: the new join cannot precede that join, and the path left as it is would read a hidden record. The query is left unchanged.
    • getResult

      public String getResult()
      Returns the query text with every change applied.
      Returns:
      query text
    • findJoin

      protected JoinVariableNode findJoin(String variable)
    • referenceReads

      protected List<PathNode> referenceReads(org.antlr.runtime.tree.Tree root, String owner, String reference, String primaryKey)
    • isJoinedPath

      protected boolean isJoinedPath(PathNode path)
    • readsKeyOfReference

      protected boolean readsKeyOfReference(PathNode path)
    • isInMainSelect

      protected boolean isInMainSelect(PathNode path)
    • declarationOf

      protected JpqlLeftJoinSupport.Rewrite.DeclarationSite declarationOf(String variable)
    • onConditionText

      protected String onConditionText(JoinVariableNode join)
    • toQuery

      protected String toQuery(org.antlr.runtime.tree.Tree node)
    • parseCondition

      protected org.antlr.runtime.tree.CommonTree parseCondition(String condition)
    • parseJoin

      protected JoinVariableNode parseJoin(String join)