Search in sources :

Example 1 with ExpandingFetchSource

use of org.hibernate.loader.plan.build.spi.ExpandingFetchSource in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingEntityIdentifier.

@Override
public void finishingEntityIdentifier(EntityIdentifierDefinition entityIdentifierDefinition) {
    // only pop from stack if the current source is ExpandingEntityIdentifierDescription..
    final ExpandingFetchSource currentSource = currentSource();
    if (!ExpandingEntityIdentifierDescription.class.isInstance(currentSource)) {
        // in this case, the current source should be the entity that owns entityIdentifierDefinition
        if (!EntityReference.class.isInstance(currentSource)) {
            throw new WalkingException("Unexpected state in FetchSource stack");
        }
        final EntityReference entityReference = (EntityReference) currentSource;
        if (entityReference.getEntityPersister().getEntityKeyDefinition() != entityIdentifierDefinition) {
            throw new WalkingException(String.format("Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName()));
        }
        return;
    }
    // the current source is ExpandingEntityIdentifierDescription...
    final ExpandingEntityIdentifierDescription identifierDescription = (ExpandingEntityIdentifierDescription) popFromStack();
    // and then on the node beforeQuery it (which should be the entity that owns the identifier being described)
    final ExpandingFetchSource entitySource = currentSource();
    if (!EntityReference.class.isInstance(entitySource)) {
        throw new WalkingException("Unexpected state in FetchSource stack");
    }
    final EntityReference entityReference = (EntityReference) entitySource;
    if (entityReference.getIdentifierDescription() != identifierDescription) {
        throw new WalkingException(String.format("Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName()));
    }
    log.tracef("%s Finished entity identifier : %s", StringHelper.repeat("<<", fetchSourceStack.size()), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName());
}
Also used : ExpandingEntityIdentifierDescription(org.hibernate.loader.plan.build.spi.ExpandingEntityIdentifierDescription) EntityReference(org.hibernate.loader.plan.spi.EntityReference) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 2 with ExpandingFetchSource

use of org.hibernate.loader.plan.build.spi.ExpandingFetchSource in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingEntity.

@Override
public void finishingEntity(EntityDefinition entityDefinition) {
    // Only process the entityDefinition if it is for the root return.
    final FetchSource currentSource = currentSource();
    final boolean isRoot = EntityReturn.class.isInstance(currentSource) && entityDefinition.getEntityPersister().equals(EntityReturn.class.cast(currentSource).getEntityPersister());
    if (!isRoot) {
        // if not, this call should represent a fetch which will be handled in #finishingAttribute
        return;
    }
    // if we get here, it is a root
    final ExpandingFetchSource popped = popFromStack();
    checkPoppedEntity(popped, entityDefinition);
    log.tracef("%s Finished root entity : %s", StringHelper.repeat("<<", fetchSourceStack.size()), entityDefinition.getEntityPersister().getEntityName());
}
Also used : FetchSource(org.hibernate.loader.plan.spi.FetchSource) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn)

Example 3 with ExpandingFetchSource

use of org.hibernate.loader.plan.build.spi.ExpandingFetchSource in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingCollectionElements.

@Override
public void finishingCollectionElements(CollectionElementDefinition elementDefinition) {
    final Type elementType = elementDefinition.getType();
    if (elementType.isAnyType()) {
    // nothing to do because the element graph was not pushed in #startingCollectionElement..
    } else if (elementType.isComponentType() || elementType.isAssociationType()) {
        // pop it from the stack
        final ExpandingFetchSource popped = popFromStack();
        // validation
        if (!CollectionFetchableElement.class.isInstance(popped)) {
            throw new WalkingException("Mismatched FetchSource from stack on pop");
        }
    }
    log.tracef("%s Finished collection element graph : %s", StringHelper.repeat("<<", fetchSourceStack.size()), elementDefinition.getCollectionDefinition().getCollectionPersister().getRole());
}
Also used : Type(org.hibernate.type.Type) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 4 with ExpandingFetchSource

use of org.hibernate.loader.plan.build.spi.ExpandingFetchSource in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method handleAssociationAttribute.

protected boolean handleAssociationAttribute(AssociationAttributeDefinition attributeDefinition) {
    // todo : this seems to not be correct for one-to-one
    final FetchStrategy fetchStrategy = determineFetchStrategy(attributeDefinition);
    final ExpandingFetchSource currentSource = currentSource();
    currentSource.validateFetchPlan(fetchStrategy, attributeDefinition);
    final AssociationAttributeDefinition.AssociationNature nature = attributeDefinition.getAssociationNature();
    if (nature == AssociationAttributeDefinition.AssociationNature.ANY) {
        // for ANY mappings we need to build a Fetch:
        //		1) fetch type is SELECT
        //		2) (because the fetch cannot be a JOIN...) do not push it to the stack
        // regardless of the fetch style, build the fetch
        currentSource.buildAnyAttributeFetch(attributeDefinition, fetchStrategy);
        return false;
    } else if (nature == AssociationAttributeDefinition.AssociationNature.ENTITY) {
        // regardless of the fetch style, build the fetch
        EntityFetch fetch = currentSource.buildEntityAttributeFetch(attributeDefinition, fetchStrategy);
        if (FetchStrategyHelper.isJoinFetched(fetchStrategy)) {
            // only push to the stack if join fetched
            pushToStack((ExpandingFetchSource) fetch);
            return true;
        } else {
            return false;
        }
    } else {
        // Collection
        // regardless of the fetch style, build the fetch
        CollectionAttributeFetch fetch = currentSource.buildCollectionAttributeFetch(attributeDefinition, fetchStrategy);
        if (FetchStrategyHelper.isJoinFetched(fetchStrategy)) {
            // only push to the stack if join fetched
            pushToCollectionStack(fetch);
            return true;
        } else {
            return false;
        }
    }
}
Also used : EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) CollectionAttributeFetch(org.hibernate.loader.plan.spi.CollectionAttributeFetch) FetchStrategy(org.hibernate.engine.FetchStrategy) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) AssociationAttributeDefinition(org.hibernate.persister.walking.spi.AssociationAttributeDefinition)

Example 5 with ExpandingFetchSource

use of org.hibernate.loader.plan.build.spi.ExpandingFetchSource in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingAttribute.

@Override
public void finishingAttribute(AttributeDefinition attributeDefinition) {
    final Type attributeType = attributeDefinition.getType();
    if (attributeType.isAssociationType()) {
        final AssociationAttributeDefinition associationAttributeDefinition = (AssociationAttributeDefinition) attributeDefinition;
        if (attributeType.isAnyType()) {
        // Nothing to do because AnyFetch does not implement ExpandingFetchSource (i.e., it cannot be pushed/popped).
        } else if (attributeType.isEntityType()) {
            final ExpandingFetchSource source = currentSource();
            // associationAttributeDefinition.
            if (AttributeFetch.class.isInstance(source) && associationAttributeDefinition.equals(AttributeFetch.class.cast(source).getFetchedAttributeDefinition())) {
                final ExpandingFetchSource popped = popFromStack();
                checkPoppedEntity(popped, associationAttributeDefinition.toEntityDefinition());
            }
        } else if (attributeType.isCollectionType()) {
            final CollectionReference currentCollection = currentCollection();
            // associationAttributeDefinition.
            if (AttributeFetch.class.isInstance(currentCollection) && associationAttributeDefinition.equals(AttributeFetch.class.cast(currentCollection).getFetchedAttributeDefinition())) {
                final CollectionReference popped = popFromCollectionStack();
                checkedPoppedCollection(popped, associationAttributeDefinition.toCollectionDefinition());
            }
        }
    } else if (attributeType.isComponentType()) {
        // CompositeFetch is always pushed, during #startingAttribute(),
        // so pop the current fetch owner, and make sure what we just popped represents this composition
        final ExpandingFetchSource popped = popFromStack();
        if (!CompositeAttributeFetch.class.isInstance(popped)) {
            throw new WalkingException(String.format("Mismatched FetchSource from stack on pop; expected: CompositeAttributeFetch; actual: [%s]", popped));
        }
        final CompositeAttributeFetch poppedAsCompositeAttributeFetch = (CompositeAttributeFetch) popped;
        if (!attributeDefinition.equals(poppedAsCompositeAttributeFetch.getFetchedAttributeDefinition())) {
            throw new WalkingException(String.format("Mismatched CompositeAttributeFetch from stack on pop; expected fetch for attribute: [%s]; actual: [%s]", attributeDefinition, poppedAsCompositeAttributeFetch.getFetchedAttributeDefinition()));
        }
    }
    log.tracef("%s Finishing up attribute : %s", StringHelper.repeat("<<", fetchSourceStack.size()), attributeDefinition);
    currentPropertyPath = currentPropertyPath.getParent();
}
Also used : Type(org.hibernate.type.Type) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) CompositeAttributeFetch(org.hibernate.loader.plan.spi.CompositeAttributeFetch) AttributeFetch(org.hibernate.loader.plan.spi.AttributeFetch) CollectionAttributeFetch(org.hibernate.loader.plan.spi.CollectionAttributeFetch) WalkingException(org.hibernate.persister.walking.spi.WalkingException) AssociationAttributeDefinition(org.hibernate.persister.walking.spi.AssociationAttributeDefinition) CollectionReference(org.hibernate.loader.plan.spi.CollectionReference) CompositeAttributeFetch(org.hibernate.loader.plan.spi.CompositeAttributeFetch)

Aggregations

ExpandingFetchSource (org.hibernate.loader.plan.build.spi.ExpandingFetchSource)7 WalkingException (org.hibernate.persister.walking.spi.WalkingException)4 Type (org.hibernate.type.Type)3 CollectionAttributeFetch (org.hibernate.loader.plan.spi.CollectionAttributeFetch)2 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)2 FetchStrategy (org.hibernate.engine.FetchStrategy)1 ExpandingEntityIdentifierDescription (org.hibernate.loader.plan.build.spi.ExpandingEntityIdentifierDescription)1 AttributeFetch (org.hibernate.loader.plan.spi.AttributeFetch)1 CollectionReference (org.hibernate.loader.plan.spi.CollectionReference)1 CompositeAttributeFetch (org.hibernate.loader.plan.spi.CompositeAttributeFetch)1 EntityFetch (org.hibernate.loader.plan.spi.EntityFetch)1 EntityReference (org.hibernate.loader.plan.spi.EntityReference)1 EntityReturn (org.hibernate.loader.plan.spi.EntityReturn)1 FetchSource (org.hibernate.loader.plan.spi.FetchSource)1