Search in sources :

Example 1 with JoinSequence

use of org.hibernate.engine.internal.JoinSequence in project hibernate-orm by hibernate.

the class FromElementFactory method createCollectionElementsJoin.

FromElement createCollectionElementsJoin(QueryableCollection queryableCollection, String collectionName) throws SemanticException {
    JoinSequence collectionJoinSequence = fromClause.getSessionFactoryHelper().createCollectionJoinSequence(queryableCollection, collectionName);
    this.queryableCollection = queryableCollection;
    return createCollectionJoin(collectionJoinSequence, null);
}
Also used : JoinSequence(org.hibernate.engine.internal.JoinSequence)

Example 2 with JoinSequence

use of org.hibernate.engine.internal.JoinSequence in project hibernate-orm by hibernate.

the class FromElementFactory method createManyToMany.

private FromElement createManyToMany(String role, String associatedEntityName, String roleAlias, Queryable entityPersister, EntityType type, JoinType joinType) throws SemanticException {
    FromElement elem;
    SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
    if (inElementsFunction) /*implied*/
    {
        // For implied many-to-many, just add the end join.
        JoinSequence joinSequence = createJoinSequence(roleAlias, joinType);
        elem = createJoin(associatedEntityName, roleAlias, joinSequence, type, true);
    } else {
        // For an explicit many-to-many relationship, add a second join from the intermediate
        // (many-to-many) table to the destination table.  Also, make sure that the from element's
        // idea of the destination is the destination table.
        String tableAlias = fromClause.getAliasGenerator().createName(entityPersister.getEntityName());
        String[] secondJoinColumns = sfh.getCollectionElementColumns(role, roleAlias);
        // Add the second join, the one that ends in the destination table.
        JoinSequence joinSequence = createJoinSequence(roleAlias, joinType);
        joinSequence.addJoin(sfh.getElementAssociationType(collectionType), tableAlias, joinType, secondJoinColumns);
        elem = createJoin(associatedEntityName, tableAlias, joinSequence, type, false);
        elem.setUseFromFragment(true);
    }
    return elem;
}
Also used : SessionFactoryHelper(org.hibernate.hql.internal.ast.util.SessionFactoryHelper) JoinSequence(org.hibernate.engine.internal.JoinSequence)

Example 3 with JoinSequence

use of org.hibernate.engine.internal.JoinSequence in project hibernate-orm by hibernate.

the class FromElementType method getJoinSequence.

public JoinSequence getJoinSequence() {
    if (joinSequence != null) {
        return joinSequence;
    }
    // Class names in the FROM clause result in a JoinSequence (the old FromParser does this).
    if (persister instanceof Joinable) {
        Joinable joinable = (Joinable) persister;
        final JoinSequence joinSequence = fromElement.getSessionFactoryHelper().createJoinSequence().setRoot(joinable, getTableAlias());
        joinSequence.applyTreatAsDeclarations(treatAsDeclarations);
        return joinSequence;
    } else {
        // TODO: Should this really return null?  If not, figure out something better to do here.
        return null;
    }
}
Also used : Joinable(org.hibernate.persister.entity.Joinable) JoinSequence(org.hibernate.engine.internal.JoinSequence)

Example 4 with JoinSequence

use of org.hibernate.engine.internal.JoinSequence in project hibernate-orm by hibernate.

the class SessionFactoryHelper method createJoinSequence.

/**
 * Generate a join sequence representing the given association type.
 *
 * @param implicit Should implicit joins (theta-style) or explicit joins (ANSI-style) be rendered
 * @param associationType The type representing the thing to be joined into.
 * @param tableAlias The table alias to use in qualifying the join conditions
 * @param joinType The type of join to render (inner, outer, etc);  see {@link org.hibernate.sql.JoinFragment}
 * @param columns The columns making up the condition of the join.
 *
 * @return The generated join sequence.
 */
public JoinSequence createJoinSequence(boolean implicit, AssociationType associationType, String tableAlias, JoinType joinType, String[] columns) {
    JoinSequence joinSequence = createJoinSequence();
    // Implicit joins use theta style (WHERE pk = fk), explicit joins use JOIN (after from)
    joinSequence.setUseThetaStyle(implicit);
    joinSequence.addJoin(associationType, tableAlias, joinType, columns);
    return joinSequence;
}
Also used : JoinSequence(org.hibernate.engine.internal.JoinSequence)

Example 5 with JoinSequence

use of org.hibernate.engine.internal.JoinSequence in project hibernate-orm by hibernate.

the class SessionFactoryHelper method createCollectionJoinSequence.

/**
 * Create a join sequence rooted at the given collection.
 *
 * @param collPersister The persister for the collection at which the join should be rooted.
 * @param collectionName The alias to use for qualifying column references.
 *
 * @return The generated join sequence.
 */
public JoinSequence createCollectionJoinSequence(QueryableCollection collPersister, String collectionName) {
    JoinSequence joinSequence = createJoinSequence();
    joinSequence.setRoot(collPersister, collectionName);
    // TODO: figure out how this should be set.
    joinSequence.setUseThetaStyle(true);
    // joinSequence = joinSequence.getFromPart();	// Emulate the old addFromOnly behavior.
    return joinSequence;
}
Also used : JoinSequence(org.hibernate.engine.internal.JoinSequence)

Aggregations

JoinSequence (org.hibernate.engine.internal.JoinSequence)20 EntityType (org.hibernate.type.EntityType)7 Type (org.hibernate.type.Type)7 QueryException (org.hibernate.QueryException)6 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)6 JoinType (org.hibernate.sql.JoinType)6 CollectionType (org.hibernate.type.CollectionType)5 SessionFactoryHelper (org.hibernate.hql.internal.ast.util.SessionFactoryHelper)4 AssociationType (org.hibernate.type.AssociationType)4 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 MappingException (org.hibernate.MappingException)2 FromClause (org.hibernate.hql.internal.ast.tree.FromClause)2 ImpliedFromElement (org.hibernate.hql.internal.ast.tree.ImpliedFromElement)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 CompositeType (org.hibernate.type.CompositeType)2 RecognitionException (antlr.RecognitionException)1 SemanticException (antlr.SemanticException)1 AST (antlr.collections.AST)1