Search in sources :

Example 6 with ScalarTargetResolvingExpressionVisitor

use of com.blazebit.persistence.view.impl.ScalarTargetResolvingExpressionVisitor in project blaze-persistence by Blazebit.

the class ViewTypeObjectBuilderTemplate method getCorrelationBasisType.

private Class<?> getCorrelationBasisType(Expression correlationBasisExpression, String correlationBasis, Map<String, javax.persistence.metamodel.Type<?>> rootTypes) {
    if (correlationBasis.isEmpty()) {
        return managedTypeClass;
    }
    EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel();
    ScalarTargetResolvingExpressionVisitor visitor = new ScalarTargetResolvingExpressionVisitor(managedTypeClass, entityMetamodel, evm.getCriteriaBuilderFactory().getRegisteredFunctions(), rootTypes);
    correlationBasisExpression.accept(visitor);
    Collection<ScalarTargetResolvingExpressionVisitor.TargetType> possibleTypes = visitor.getPossibleTargetTypes();
    if (possibleTypes.size() > 1) {
        throw new IllegalArgumentException("The correlation basis '" + correlationBasis + "' is ambiguous in the context of the managed type '" + managedTypeClass.getName() + "'!");
    }
    // It must have one, otherwise a parse error would have been thrown already
    Class<?> entityClazz = possibleTypes.iterator().next().getLeafBaseValueClass();
    if (entityClazz == null) {
        throw new IllegalArgumentException("Could not resolve the correlation basis '" + correlationBasis + "' in the context of the managed type '" + managedTypeClass.getName() + "'!");
    }
    return entityClazz;
}
Also used : EntityMetamodel(com.blazebit.persistence.parser.EntityMetamodel) ScalarTargetResolvingExpressionVisitor(com.blazebit.persistence.view.impl.ScalarTargetResolvingExpressionVisitor)

Aggregations

ScalarTargetResolvingExpressionVisitor (com.blazebit.persistence.view.impl.ScalarTargetResolvingExpressionVisitor)6 Expression (com.blazebit.persistence.parser.expression.Expression)3 SyntaxErrorException (com.blazebit.persistence.parser.expression.SyntaxErrorException)3 CorrelationProviderFactory (com.blazebit.persistence.view.CorrelationProviderFactory)3 OrderByItem (com.blazebit.persistence.view.metamodel.OrderByItem)3 AliasReplacementVisitor (com.blazebit.persistence.parser.AliasReplacementVisitor)2 NullExpression (com.blazebit.persistence.parser.expression.NullExpression)2 NumericLiteral (com.blazebit.persistence.parser.expression.NumericLiteral)2 ParameterExpression (com.blazebit.persistence.parser.expression.ParameterExpression)2 Predicate (com.blazebit.persistence.parser.predicate.Predicate)2 ExtendedManagedType (com.blazebit.persistence.spi.ExtendedManagedType)2 StaticCorrelationProvider (com.blazebit.persistence.view.impl.StaticCorrelationProvider)2 StaticPathCorrelationProvider (com.blazebit.persistence.view.impl.StaticPathCorrelationProvider)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ManagedType (javax.persistence.metamodel.ManagedType)2 EntityMetamodel (com.blazebit.persistence.parser.EntityMetamodel)1 EntityLiteral (com.blazebit.persistence.parser.expression.EntityLiteral)1 ExpressionFactory (com.blazebit.persistence.parser.expression.ExpressionFactory)1 ListIndexExpression (com.blazebit.persistence.parser.expression.ListIndexExpression)1