Search in sources :

Example 31 with PathElementExpression

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;
}
Also used : PathTargetResolvingExpressionVisitor(com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor) PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression)

Example 32 with PathElementExpression

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");
    }
}
Also used : PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) ArrayExpression(com.blazebit.persistence.parser.expression.ArrayExpression) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression)

Aggregations

PathElementExpression (com.blazebit.persistence.parser.expression.PathElementExpression)32 PropertyExpression (com.blazebit.persistence.parser.expression.PropertyExpression)28 PathExpression (com.blazebit.persistence.parser.expression.PathExpression)23 ArrayList (java.util.ArrayList)15 Expression (com.blazebit.persistence.parser.expression.Expression)13 ArrayExpression (com.blazebit.persistence.parser.expression.ArrayExpression)12 FunctionExpression (com.blazebit.persistence.parser.expression.FunctionExpression)10 MapKeyExpression (com.blazebit.persistence.parser.expression.MapKeyExpression)9 SubqueryExpression (com.blazebit.persistence.parser.expression.SubqueryExpression)9 TreatExpression (com.blazebit.persistence.parser.expression.TreatExpression)8 ListIndexExpression (com.blazebit.persistence.parser.expression.ListIndexExpression)7 MapValueExpression (com.blazebit.persistence.parser.expression.MapValueExpression)7 MapEntryExpression (com.blazebit.persistence.parser.expression.MapEntryExpression)6 ParameterExpression (com.blazebit.persistence.parser.expression.ParameterExpression)6 EntityType (javax.persistence.metamodel.EntityType)6 GeneralCaseExpression (com.blazebit.persistence.parser.expression.GeneralCaseExpression)5 QualifiedExpression (com.blazebit.persistence.parser.expression.QualifiedExpression)5 ExtendedManagedType (com.blazebit.persistence.spi.ExtendedManagedType)5 LinkedHashSet (java.util.LinkedHashSet)4 ManagedType (javax.persistence.metamodel.ManagedType)4