Class JpqlLeftJoinSupport.Rewrite
java.lang.Object
io.jmix.aitools.dataload.execution.JpqlLeftJoinSupport.Rewrite
- Enclosing class:
JpqlLeftJoinSupport
Changes to one query, applied to its syntax tree in the order they are made.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordA variable's declaration: the selection source holding it, its child index there and the node itself.static final recordWhatjoinReference(String, String)did to the reads of a reference. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOnCondition(String variable, String condition) Adds a condition to theonclause of the join declaring the variable, in conjunction with the clause's own condition if any.voidaddWhereCondition(String condition) Adds a condition to the main query'swhere, in conjunction with its own condition if any.declarationOf(String variable) protected JoinVariableNodeReturns the query text with every change applied.protected booleanisInMainSelect(PathNode path) protected booleanisJoinedPath(PathNode path) 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, agroup byor anorder byitem, and the variable elsewhere.protected static StringReturns a variable name the query does not declare and this rewrite has not returned before.protected Stringprotected org.antlr.runtime.tree.CommonTreeparseCondition(String condition) protected JoinVariableNodeprotected booleanreadsKeyOfReference(PathNode path) referenceReads(org.antlr.runtime.tree.Tree root, String owner, String reference, String primaryKey) protected StringtoQuery(org.antlr.runtime.tree.Tree node)
-
Field Details
-
VARIABLE_PREFIX
- See Also:
-
tree
-
usedVariables
-
variableCounter
protected int variableCounter
-
-
Constructor Details
-
Rewrite
-
-
Method Details
-
lowerCase
-
newVariable
Returns a variable name the query does not declare and this rewrite has not returned before.- Returns:
- the variable name
-
addWhereCondition
Adds a condition to the main query'swhere, in conjunction with its own condition if any.- Parameters:
condition- JPQL condition- Throws:
IllegalStateException- if the condition cannot be parsed
-
addOnCondition
Adds a condition to theonclause 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 querycondition- 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, agroup byor anorder byitem, and the variable elsewhere. A path in theonclause 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 asd.parentprimaryKey- 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 attributeIllegalStateException- if the path's variable is not declared in the main query'sfrom, or the query does not read the referenceJpqlAccessConstraintException- if the reference is read in theonclause 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
Returns the query text with every change applied.- Returns:
- query text
-
findJoin
-
referenceReads
-
isJoinedPath
-
readsKeyOfReference
-
isInMainSelect
-
declarationOf
-
onConditionText
-
toQuery
-
parseCondition
-
parseJoin
-