use of com.blazebit.persistence.parser.expression.PathElementExpression in project blaze-persistence by Blazebit.
the class JoinManager method findCorrelatedAttributeIndex.
private int findCorrelatedAttributeIndex(JoinNode correlationParent, List<PathElementExpression> pathElements, int start, int end) {
PathTargetResolvingExpressionVisitor pathResolvingVisitor = new PathTargetResolvingExpressionVisitor(metamodel, correlationParent.getNodeType(), correlationParent.getAlias());
for (int i = start; i < end; i++) {
PathElementExpression expression = pathElements.get(i);
expression.accept(pathResolvingVisitor);
Attribute<?, ?> attribute = pathResolvingVisitor.getPossibleTargets().entrySet().iterator().next().getKey();
if (attribute != null) {
if (mainQuery.jpaProvider.getJpaMetamodelAccessor().isJoinable(attribute)) {
return i;
}
}
}
return -1;
}
use of com.blazebit.persistence.parser.expression.PathElementExpression in project blaze-persistence by Blazebit.
the class JoinManager method isExternal.
private boolean isExternal(PathExpression path) {
PathElementExpression firstElem = ExpressionUtils.getLeftMostPathExpression(path).getExpressions().get(0);
String startAlias;
if (firstElem instanceof ArrayExpression) {
startAlias = ((ArrayExpression) firstElem).getBase().toString();
} else if (firstElem instanceof PropertyExpression) {
startAlias = ((PropertyExpression) firstElem).getProperty();
} else {
throw new IllegalArgumentException("Unexpected expression type[" + firstElem.getClass().getSimpleName() + "] in expression: " + path);
}
AliasInfo aliasInfo = aliasManager.getAliasInfo(startAlias);
if (aliasInfo == null) {
return false;
}
if (parent != null && aliasInfo.getAliasOwner() != aliasManager) {
// an external select alias must not be de-referenced
if (path.getExpressions().size() > 1) {
// But if check if the expression really is just an alias reference or the
if (aliasInfo instanceof SelectInfo) {
throw new ExternalAliasDereferencingException("Start alias [" + startAlias + "] of path [" + path.toString() + "] is external and must not be dereferenced");
}
}
// the alias is external so we do not have to treat it
return true;
} else if (aliasInfo.getAliasOwner() == aliasManager) {
// the alias originates from the current query builder and is therefore not external
return false;
} else {
throw new IllegalStateException("Alias [" + aliasInfo.getAlias() + "] originates from an unknown query");
}
}
Aggregations