FromElement createCollection( QueryableCollection queryableCollection, String role, int joinType, boolean fetchFlag, boolean indexed) throws SemanticException { if (!collection) { throw new IllegalStateException("FromElementFactory not initialized for collections!"); } this.inElementsFunction = indexed; FromElement elem; this.queryableCollection = queryableCollection; collectionType = queryableCollection.getCollectionType(); String roleAlias = fromClause.getAliasGenerator().createName(role); // Correlated subqueries create 'special' implied from nodes // because correlated subselects can't use an ANSI-style join boolean explicitSubqueryFromElement = fromClause.isSubQuery() && !implied; if (explicitSubqueryFromElement) { String pathRoot = StringHelper.root(path); FromElement origin = fromClause.getFromElement(pathRoot); if (origin == null || origin.getFromClause() != fromClause) { implied = true; } } // super-duper-classic-parser-regression-testing-mojo-magic... if (explicitSubqueryFromElement && DotNode.useThetaStyleImplicitJoins) { implied = true; } Type elementType = queryableCollection.getElementType(); if (elementType.isEntityType()) { // A collection of entities... elem = createEntityAssociation(role, roleAlias, joinType); } else if (elementType.isComponentType()) { // A collection of components... JoinSequence joinSequence = createJoinSequence(roleAlias, joinType); elem = createCollectionJoin(joinSequence, roleAlias); } else { // A collection of scalar elements... JoinSequence joinSequence = createJoinSequence(roleAlias, joinType); elem = createCollectionJoin(joinSequence, roleAlias); } elem.setRole(role); elem.setQueryableCollection(queryableCollection); // Don't include sub-classes for implied collection joins or subquery joins. if (implied) { elem.setIncludeSubclasses(false); } if (explicitSubqueryFromElement) { elem.setInProjectionList(true); // Treat explict from elements in sub-queries properly. } if (fetchFlag) { elem.setFetch(true); } return elem; }
public FromElement createEntityJoin( String entityClass, String tableAlias, JoinSequence joinSequence, boolean fetchFlag, boolean inFrom, EntityType type, String role, String joinPath) throws SemanticException { FromElement elem = createJoin(entityClass, tableAlias, joinSequence, type, false); elem.setFetch(fetchFlag); if (joinPath != null) { elem.applyTreatAsDeclarations(fromClause.getWalker().getTreatAsDeclarationsByPath(joinPath)); } EntityPersister entityPersister = elem.getEntityPersister(); int numberOfTables = entityPersister.getQuerySpaces().length; if (numberOfTables > 1 && implied && !elem.useFromFragment()) { LOG.debug("createEntityJoin() : Implied multi-table entity join"); elem.setUseFromFragment(true); } // If this is an implied join in a FROM clause, then use ANSI-style joining, and set the // flag on the FromElement that indicates that it was implied in the FROM clause itself. if (implied && inFrom) { joinSequence.setUseThetaStyle(false); elem.setUseFromFragment(true); elem.setImpliedInFromClause(true); } if (elem.getWalker().isSubQuery()) { // two conditions where we need to transform this to a theta-join syntax: // 1) 'elem' is the "root from-element" in correlated subqueries // 2) The DotNode.useThetaStyleImplicitJoins has been set to true // and 'elem' represents an implicit join if (elem.getFromClause() != elem.getOrigin().getFromClause() || // ( implied && DotNode.useThetaStyleImplicitJoins ) ) { PathSeparatorNode.useThetaStyleImplicitJoins) { // the "root from-element" in correlated subqueries do need this piece elem.setType(FROM_FRAGMENT); joinSequence.setUseThetaStyle(true); elem.setUseFromFragment(false); } } elem.setRole(role); return elem; }