@Override public void visit(SimpleCaseExpression expression) { visit((GeneralCaseExpression) expression); }
@Override public void visit(ArithmeticFactor expression) { invalid(expression); }
PathTargetResolvingExpressionVisitor visitor = new PathTargetResolvingExpressionVisitor(context.getEntityMetamodel(), elementJpaType, null); for (String value : writableMappedByMappings.values()) { visitor.reset(elementJpaType); context.getTypeValidationExpressionFactory().createPathExpression(value).accept(visitor); Map<Attribute<?, ?>, javax.persistence.metamodel.Type<?>> possibleTargets = visitor.getPossibleTargets(); if (possibleTargets.size() > 1) { context.addError("Multiple possible target type for the mapping in the " + getLocation() + ": " + possibleTargets);
public static AttributeHolder getAttributeForJoining(EntityMetamodel metamodel, Type<?> baseNodeType, Expression joinExpression, String baseNodeAlias) { PathTargetResolvingExpressionVisitor visitor = new PathTargetResolvingExpressionVisitor(metamodel, baseNodeType, baseNodeAlias); joinExpression.accept(visitor); Map<Attribute<?, ?>, Type<?>> possibleTargets = visitor.getPossibleTargets(); if (possibleTargets.size() > 1) { throw new IllegalArgumentException("Multiple possible target types for expression: " + joinExpression); } Map.Entry<Attribute<?, ?>, Type<?>> entry = possibleTargets.entrySet().iterator().next(); return new AttributeHolder(entry.getKey(), entry.getValue()); } }
public PathTargetResolvingExpressionVisitor(EntityMetamodel metamodel, Type<?> startClass, String skipBaseNodeAlias) { this.metamodel = metamodel; this.pathPositions = new ArrayList<>(); this.skipBaseNodeAlias = skipBaseNodeAlias; reset(startClass); }
Type<?> type = getType(currentPosition.getCurrentType(), attribute); Type<?> valueType = null; Type<?> keyType = null;
public static boolean isIndexedList(EntityMetamodel metamodel, ExpressionFactory expressionFactory, Class<?> entityClass, String mapping) { if (mapping == null || mapping.isEmpty()) { return false; } PathTargetResolvingExpressionVisitor visitor = new PathTargetResolvingExpressionVisitor(metamodel, metamodel.managedType(entityClass), null); expressionFactory.createSimpleExpression(mapping, false).accept(visitor); Map<Attribute<?, ?>, javax.persistence.metamodel.Type<?>> possibleTargets = visitor.getPossibleTargets(); Iterator<Map.Entry<Attribute<?, ?>, javax.persistence.metamodel.Type<?>>> iter = possibleTargets.entrySet().iterator(); // It must have one, otherwise a parse error would have been thrown already Map.Entry<Attribute<?, ?>, ?> targetEntry = iter.next(); boolean indexed = isIndexedList(targetEntry.getKey()); while (iter.hasNext()) { targetEntry = iter.next(); if (indexed != isIndexedList(targetEntry.getKey())) { throw new IllegalArgumentException("Inconclusive result on checking whether the expression [" + mapping + "] resolves to an indexed list on class [" + entityClass.getName() + "]."); } } return indexed; }
public PathTargetResolvingExpressionVisitor(EntityMetamodel metamodel, Type<?> startClass, String skipBaseNodeAlias) { this.metamodel = metamodel; this.pathPositions = new ArrayList<>(); this.skipBaseNodeAlias = skipBaseNodeAlias; reset(startClass); }
Type<?> type = getType(currentPosition.getCurrentType(), attribute); Type<?> valueType = null; Type<?> keyType = null;
@Override public void visit(BooleanLiteral expression) { invalid(expression); }
private String findCorrelatedAttribute(JoinNode correlationParent, List<PathElementExpression> pathElements, int start, int end, List<PathElementExpression> fields) { 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)) { StringBuilder sb = new StringBuilder(); for (PathElementExpression field : fields) { sb.append(field.toString()); sb.append('.'); } sb.append(attribute.getName()); return sb.toString(); } else { fields.add(expression); } } } return null; }
@Override public void visit(SimpleCaseExpression expression) { visit((GeneralCaseExpression) expression); }
@Override public void visit(LePredicate predicate) { invalid(predicate); }
@Override public void visit(PropertyExpression expression) { if (updatable && (currentPosition.attribute != null)) { throw new IllegalArgumentException("Invalid dereferencing of collection property '" + expression.getProperty() + "' in updatable expression!"); } super.visit(expression); }
@Override public void visit(NullExpression expression) { invalid(expression); }
@Override public void visit(NumericLiteral expression) { invalid(expression); }
@Override public void visit(IsNullPredicate predicate) { invalid(predicate); }
@Override public void visit(StringLiteral expression) { invalid(expression); }
@Override public void visit(IsEmptyPredicate predicate) { invalid(predicate); }
@Override public void visit(LtPredicate predicate) { invalid(predicate); }