Search in sources :

Example 1 with Joinable

use of org.hibernate.persister.entity.Joinable 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 2 with Joinable

use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method foundCircularAssociation.

@Override
public void foundCircularAssociation(AssociationAttributeDefinition attributeDefinition) {
    final FetchStrategy fetchStrategy = determineFetchStrategy(attributeDefinition);
    if (fetchStrategy.getStyle() != FetchStyle.JOIN) {
        // nothing to do
        return;
    }
    final AssociationKey associationKey = attributeDefinition.getAssociationKey();
    // go ahead and build the bidirectional fetch
    if (attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY) {
        final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister();
        final AssociationKey currentEntityReferenceAssociationKey = new AssociationKey(currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames());
        // if associationKey is equal to currentEntityReferenceAssociationKey
        // that means that the current EntityPersister has a single primary key attribute
        // (i.e., derived attribute) which is mapped by attributeDefinition.
        // This is not a bidirectional association.
        // TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
        // it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
        // deal with this???
        final FetchSource registeredFetchSource = registeredFetchSource(associationKey);
        if (registeredFetchSource != null && !associationKey.equals(currentEntityReferenceAssociationKey)) {
            currentSource().buildBidirectionalEntityReference(attributeDefinition, fetchStrategy, registeredFetchSource(associationKey).resolveEntityReference());
        }
    } else {
    // Do nothing for collection
    }
}
Also used : AssociationKey(org.hibernate.persister.walking.spi.AssociationKey) FetchSource(org.hibernate.loader.plan.spi.FetchSource) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) FetchStrategy(org.hibernate.engine.FetchStrategy) Joinable(org.hibernate.persister.entity.Joinable)

Example 3 with Joinable

use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method startingCollection.

@Override
public void startingCollection(CollectionDefinition collectionDefinition) {
    // see if the EntityDefinition is a root...
    final boolean isRoot = fetchSourceStack.isEmpty();
    if (!isRoot) {
        // if not, this call should represent a fetch which should have been handled in #startingAttribute
        return;
    }
    log.tracef("%s Starting root collection : %s", StringHelper.repeat(">>", fetchSourceStack.size()), collectionDefinition.getCollectionPersister().getRole());
    // if we get here, it is a root
    if (!supportsRootCollectionReturns()) {
        throw new HibernateException("This strategy does not support root collection returns");
    }
    final CollectionReturn collectionReturn = new CollectionReturnImpl(collectionDefinition, querySpaces);
    pushToCollectionStack(collectionReturn);
    addRootReturn(collectionReturn);
    associationKeyRegistered(new AssociationKey(((Joinable) collectionDefinition.getCollectionPersister()).getTableName(), ((Joinable) collectionDefinition.getCollectionPersister()).getKeyColumnNames()));
}
Also used : AssociationKey(org.hibernate.persister.walking.spi.AssociationKey) HibernateException(org.hibernate.HibernateException) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) Joinable(org.hibernate.persister.entity.Joinable) CollectionReturnImpl(org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl)

Example 4 with Joinable

use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.

the class EntityLoadQueryDetails method applyRootReturnWhereJoinRestrictions.

protected void applyRootReturnWhereJoinRestrictions(SelectStatementBuilder selectStatementBuilder) {
    final Joinable joinable = (OuterJoinLoadable) getRootEntityReturn().getEntityPersister();
    selectStatementBuilder.appendRestrictions(joinable.whereJoinFragment(entityReferenceAliases.getTableAlias(), true, true));
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) Joinable(org.hibernate.persister.entity.Joinable)

Example 5 with Joinable

use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.

the class JoinWalker method addAssociationToJoinTree.

/**
 * Add on association (one-to-one, many-to-one, or a collection) to a list
 * of associations to be fetched by outerjoin
 */
private void addAssociationToJoinTree(final AssociationType type, final String[] aliasedLhsColumns, final String alias, final PropertyPath path, final int currentDepth, final JoinType joinType) throws MappingException {
    Joinable joinable = type.getAssociatedJoinable(getFactory());
    // important to generate alias based on size of association collection
    // *before* adding this join to that collection
    String subalias = generateTableAlias(associations.size() + 1, path, joinable);
    // NOTE : it should be fine to continue to pass only filters below
    // (instead of LoadQueryInfluencers) since "from that point on" we
    // only need to worry about restrictions (and not say adding more
    // joins)
    OuterJoinableAssociation assoc = new OuterJoinableAssociation(path, type, alias, aliasedLhsColumns, subalias, joinType, joinable.consumesEntityAlias() ? getWithClause(path) : "", hasRestriction(path), getFactory(), loadQueryInfluencers.getEnabledFilters());
    assoc.validateJoin(path.getFullPath());
    associations.add(assoc);
    int nextDepth = currentDepth + 1;
    // path = "";
    if (!joinable.isCollection()) {
        if (joinable instanceof OuterJoinLoadable) {
            walkEntityTree((OuterJoinLoadable) joinable, subalias, path, nextDepth);
        }
    } else {
        if (joinable instanceof QueryableCollection) {
            walkCollectionTree((QueryableCollection) joinable, subalias, path, nextDepth);
        }
    }
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) Joinable(org.hibernate.persister.entity.Joinable) QueryableCollection(org.hibernate.persister.collection.QueryableCollection)

Aggregations

Joinable (org.hibernate.persister.entity.Joinable)19 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)6 OuterJoinLoadable (org.hibernate.persister.entity.OuterJoinLoadable)6 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)5 AssociationType (org.hibernate.type.AssociationType)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 HibernateException (org.hibernate.HibernateException)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 EntityReferenceInitializerImpl (org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl)2 EntityReferenceAliases (org.hibernate.loader.plan.exec.spi.EntityReferenceAliases)2 FetchSource (org.hibernate.loader.plan.spi.FetchSource)2 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 CollectionType (org.hibernate.type.CollectionType)2 SetType (org.hibernate.type.SetType)2 AST (antlr.collections.AST)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1