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;
}
Aggregations