@Override public void visit(PathExpression expression) { joinNodes.add((JoinNode) expression.getBaseNode()); } }
private boolean renderAbsolutePath(PathExpression expression) { JoinNode baseNode = (JoinNode) expression.getBaseNode(); return renderedJoinNodes != null && !renderedJoinNodes.contains(baseNode); }
@Override public void visit(PathExpression pathExpr) { // prevent loop dependencies to the same join node if (pathExpr.getBaseNode() != joinNode) { joinNode.getDependencies().add((JoinNode) pathExpr.getBaseNode()); } }
@Override public void visit(PathExpression pathExpr) { // prevent loop dependencies to the same join node and dependencies to qualified join nodes JoinNode baseNode = (JoinNode) pathExpr.getBaseNode(); if (baseNode != null && baseNode != JoinNode.this && (baseNode.getQualificationExpression() == null || baseNode.parent != JoinNode.this)) { dependencies.add(baseNode); } } });
private boolean requiresBlacklistedNode(PathExpression sizeArg) { JoinNode sizeArgBaseNode = (JoinNode) sizeArg.getBaseNode(); if (joinNodeBlacklist.contains(sizeArgBaseNode)) { return sizeArgBaseNode.getNodes().keySet().contains(sizeArg.getField()); } else { return false; } }
@Override public void visit(PathExpression expression) { BaseNode baseNode = expression.getBaseNode(); if (!(baseNode instanceof JoinNode)) { throw new IllegalArgumentException("Unexpected base node type: " + baseNode); } if (aliasManager == ((JoinNode) baseNode).getAliasInfo().getAliasOwner()) { expressions.add(expression); } }
public JoinNode getFromByPath(String path) { if (path == null || path.isEmpty()) { JoinNode node = joinManager.getRootNodeOrFail("No or multiple query roots, can't find single root!"); return node; } PathExpression pathExpression = expressionFactory.createPathExpression(path); joinManager.implicitJoin(pathExpression, true, true, null, null, new HashSet<String>(), false, false, true, false); return (JoinNode) pathExpression.getBaseNode(); }
private boolean isArrayExpressionCondition() { if (onPredicate == null || onPredicate.getChildren().size() != 1) { return false; } Predicate predicate = onPredicate.getChildren().get(0); if (!(predicate instanceof EqPredicate)) { return false; } EqPredicate eqPredicate = (EqPredicate) predicate; Expression left = eqPredicate.getLeft(); if (left instanceof MapKeyExpression) { return this.equals(((MapKeyExpression) left).getPath().getBaseNode()); } if (left instanceof ListIndexExpression) { return this.equals(((ListIndexExpression) left).getPath().getBaseNode()); } return false; }
@Override public Boolean visit(PathExpression expression) { if (orderBySelectClause) { LateJoinEntry lateJoinEntry = lateJoins.get(getJoinLookupKey(expression)); if (lateJoinEntry != null) { lateJoinEntry.getClauseDependencies().add(ClauseType.ORDER_BY); } } if (clause == ClauseType.SELECT) { // for the select clause we blacklist all the join nodes that are required by other select items JoinNode current = (JoinNode) expression.getBaseNode(); while (current != null) { joinNodeBlacklist.add(current); current = current.getParent(); } } return super.visit(expression); }
@Override public void visit(PathExpression expression) { if (expression.getBaseNode() == null) { ((SelectInfo) aliasManager.getAliasInfo(expression.toString())).getExpression().accept(this); } else { expressions.add(expression); } }
private String getJoinLookupKey(PathExpression pathExpression) { JoinNode originalNode = (JoinNode) pathExpression.getBaseNode(); return originalNode.getAliasInfo().getAbsolutePath() + "." + pathExpression.getField(); }
@Override public void visit(PathExpression expr) { JoinNode node = (JoinNode) expr.getBaseNode(); if (node == null) { // This can only be a select alias ((SelectInfo) aliasManager.getAliasInfo(expr.toString())).getExpression().accept(this); } else { node.updateClauseDependencies(ClauseType.GROUP_BY); } }
@Override public Boolean visit(PathExpression expression) { if (expression.getBaseNode() == null) { return ((SelectInfo) aliasManager.getAliasInfo(expression.toString())).getExpression().accept(this); } else { return baseExpression(expression); } }
@Override public Expression visit(MapKeyExpression expression) { if (expression == expressionToSplit) { List<PathElementExpression> expressions = new ArrayList<>(2); expressions.add(expression); for (String subAttributePart : subAttribute.split("\\.")) { expressions.add(new PropertyExpression(subAttributePart)); } JoinNode node = ((JoinNode) expression.getPath().getBaseNode()).getKeyJoinNode(); String field = subAttribute; Class<?> fieldClass = jpaProvider.getJpaMetamodelAccessor().getAttributePath(metamodel, node.getManagedType(), field).getAttributeClass(); Type<?> fieldType = metamodel.type(fieldClass); return new PathExpression( expressions, new SimplePathReference(node, field, fieldType), false, false ); } return expression; }
private void visitKeyOrIndexExpression(PathExpression pathExpression) { JoinNode node = (JoinNode) pathExpression.getBaseNode(); Attribute<?, ?> attribute = node.getParentTreeNode().getAttribute(); // Exclude element collections as they are not problematic if (!jpaProvider.getJpaMetamodelAccessor().isElementCollection(attribute)) { // There are weird mappings possible, we have to check if the attribute is a join table if (jpaProvider.getJoinTable(node.getParent().getEntityType(), attribute.getName()) != null) { keyRestrictedLeftJoins.add(node); } } } }
private boolean renderAssociationIdIfPossible(Expression expression) { expression.accept(this); if (expression instanceof PathExpression) { PathExpression pathExpression = (PathExpression) expression; // Before Hibernate 5.1 there was a "broken" possibility to use multiple join nodes in the WITH clause // That involves only suffixing association paths so that predicates look like "p = other.relation.id" if (!jpaProvider.needsBrokenAssociationToIdRewriteInOnClause() || pathExpression.getBaseNode() != null && pathExpression.getField() != null) { Type<?> pathType = pathExpression.getPathReference().getType(); if (pathType instanceof ManagedType<?> && JpaMetamodelUtils.isIdentifiable((ManagedType<?>) pathType)) { String idName = JpaMetamodelUtils.getSingleIdAttribute((IdentifiableType<?>) pathType).getName(); sb.append('.'); sb.append(idName); return true; } } } return false; }
private JoinNode joinMapEntry(MapEntryExpression mapEntryExpression, String alias, ClauseType fromClause, Set<String> currentlyResolvingAliases, boolean fromSubquery, boolean fromSelectAlias, boolean joinRequired, boolean fetch, boolean implicit, boolean defaultJoin) { implicitJoin(mapEntryExpression.getPath(), true, true, null, fromClause, null, currentlyResolvingAliases, fromSubquery, fromSelectAlias, joinRequired, false, fetch, false); JoinNode current = (JoinNode) mapEntryExpression.getPath().getBaseNode(); String joinRelationName = "ENTRY(" + current.getParentTreeNode().getRelationName() + ")"; MapAttribute<?, ?, ?> mapAttribute = (MapAttribute<?, ?, ?>) current.getParentTreeNode().getAttribute(); Attribute<?, ?> entryAttribute = new MapEntryAttribute<>(mapAttribute); String aliasToUse = alias == null ? current.getParentTreeNode().getRelationName().replaceAll("\\.", "_") + "_entry" : alias; Type<?> joinRelationType = metamodel.type(Map.Entry.class); current = getOrCreate(current, joinRelationName, joinRelationType, null, aliasToUse, JoinType.LEFT, "Ambiguous implicit join", implicit, true, entryAttribute); return current; }
private JoinNode joinListIndex(ListIndexExpression listIndexExpression, String alias, ClauseType fromClause, Set<String> currentlyResolvingAliases, boolean fromSubquery, boolean fromSelectAlias, boolean joinRequired, boolean fetch, boolean implicit, boolean defaultJoin) { implicitJoin(listIndexExpression.getPath(), true, true, null, fromClause, null, currentlyResolvingAliases, fromSubquery, fromSelectAlias, joinRequired, false, fetch, false); JoinNode current = (JoinNode) listIndexExpression.getPath().getBaseNode(); String joinRelationName = "INDEX(" + current.getParentTreeNode().getRelationName() + ")"; ListAttribute<?, ?> listAttribute = (ListAttribute<?, ?>) current.getParentTreeNode().getAttribute(); Attribute<?, ?> indexAttribute = new ListIndexAttribute<>(listAttribute); String aliasToUse = alias == null ? current.getParentTreeNode().getRelationName().replaceAll("\\.", "_") + "_index" : alias; Type<?> joinRelationType = metamodel.type(Integer.class); current = getOrCreate(current, joinRelationName, joinRelationType, null, aliasToUse, JoinType.LEFT, "Ambiguous implicit join", implicit, true, indexAttribute); return current; }
private JoinNode joinMapKey(MapKeyExpression mapKeyExpression, String alias, ClauseType fromClause, Set<String> currentlyResolvingAliases, boolean fromSubquery, boolean fromSelectAlias, boolean joinRequired, boolean fetch, boolean implicit, boolean defaultJoin) { implicitJoin(mapKeyExpression.getPath(), true, true, null, fromClause, null, currentlyResolvingAliases, fromSubquery, fromSelectAlias, joinRequired, false, fetch, false); JoinNode current = (JoinNode) mapKeyExpression.getPath().getBaseNode(); String joinRelationName = "KEY(" + current.getParentTreeNode().getRelationName() + ")"; MapAttribute<?, ?, ?> mapAttribute = (MapAttribute<?, ?, ?>) current.getParentTreeNode().getAttribute(); Attribute<?, ?> keyAttribute = new MapKeyAttribute<>(mapAttribute); String aliasToUse = alias == null ? current.getParentTreeNode().getRelationName().replaceAll("\\.", "_") + "_key" : alias; Type<?> joinRelationType = metamodel.type(mapAttribute.getKeyJavaType()); current = getOrCreate(current, joinRelationName, joinRelationType, null, aliasToUse, JoinType.LEFT, "Ambiguous implicit join", implicit, true, keyAttribute); return current; }
@Override public void visit(PathExpression expression) { AliasInfo aliasInfo = aliasManager.getAliasInfo(expression.toString()); if (aliasInfo != null && aliasInfo instanceof SelectInfo) { ((SelectInfo) aliasInfo).getExpression().accept(this); } else if (inSubquery) { JoinNode joinNode = (JoinNode) expression.getBaseNode(); if (joinNode != null && joinNode.getAliasInfo().getAliasOwner() == aliasManager) { // we have an external path in the subquery while (joinNode != null && joinNode.getParentTreeNode() != null) { if (joinNode.getParentTreeNode().isCollection()) { throw new IllegalStateException("Unsupported external collection access [" + joinNode.getAliasInfo().getAbsolutePath() + "]"); } joinNode = joinNode.getParent(); } } } }