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 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; }
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; }
PathTargetResolvingExpressionVisitor visitor = new PathTargetResolvingExpressionVisitor(context.getEntityMetamodel(), elementJpaType, null); for (String value : writableMappedByMappings.values()) { visitor.reset(elementJpaType);