Search in sources :

Example 1 with CompositeAttributeFetch

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

the class AbstractExpandingFetchSource method buildCompositeAttributeFetch.

@Override
public CompositeAttributeFetch buildCompositeAttributeFetch(AttributeDefinition attributeDefinition) {
    final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(expandingQuerySpace(), attributeDefinition, getQuerySpaces().generateImplicitUid(), true);
    final CompositeAttributeFetch fetch = createCompositeAttributeFetch(attributeDefinition, compositeQuerySpace);
    addFetch(fetch);
    return fetch;
}
Also used : ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) CompositeAttributeFetch(org.hibernate.loader.plan.spi.CompositeAttributeFetch)

Example 2 with CompositeAttributeFetch

use of org.hibernate.loader.plan.spi.CompositeAttributeFetch 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

CompositeAttributeFetch (org.hibernate.loader.plan.spi.CompositeAttributeFetch)2 ExpandingCompositeQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace)1 ExpandingFetchSource (org.hibernate.loader.plan.build.spi.ExpandingFetchSource)1 AttributeFetch (org.hibernate.loader.plan.spi.AttributeFetch)1 CollectionAttributeFetch (org.hibernate.loader.plan.spi.CollectionAttributeFetch)1 CollectionReference (org.hibernate.loader.plan.spi.CollectionReference)1 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)1 WalkingException (org.hibernate.persister.walking.spi.WalkingException)1 Type (org.hibernate.type.Type)1