Search in sources :

Example 6 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class QuerySpaceHelper method makeEntityQuerySpace.

public ExpandingEntityQuerySpace makeEntityQuerySpace(ExpandingQuerySpace lhsQuerySpace, AssociationAttributeDefinition attribute, String querySpaceUid, FetchStrategy fetchStrategy) {
    final EntityType fetchedType = (EntityType) attribute.getType();
    final EntityPersister fetchedPersister = attribute.toEntityDefinition().getEntityPersister();
    if (fetchedPersister == null) {
        throw new WalkingException(String.format("Unable to locate EntityPersister [%s] for fetch [%s]", fetchedType.getAssociatedEntityName(), attribute.getName()));
    }
    // TODO: Queryable.isMultiTable() may be more broad than it needs to be...
    final boolean isMultiTable = Queryable.class.cast(fetchedPersister).isMultiTable();
    final boolean required = lhsQuerySpace.canJoinsBeRequired() && !isMultiTable && !attribute.isNullable();
    return makeEntityQuerySpace(lhsQuerySpace, fetchedPersister, attribute.getName(), (EntityType) attribute.getType(), querySpaceUid, required, shouldIncludeJoin(fetchStrategy));
}
Also used : EntityType(org.hibernate.type.EntityType) EntityPersister(org.hibernate.persister.entity.EntityPersister) Queryable(org.hibernate.persister.entity.Queryable) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 7 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException 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)

Example 8 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method startingComposite.

@Override
public void startingComposite(CompositionDefinition compositionDefinition) {
    log.tracef("%s Starting composite : %s", StringHelper.repeat(">>", fetchSourceStack.size()), compositionDefinition.getName());
    if (fetchSourceStack.isEmpty() && collectionReferenceStack.isEmpty()) {
        throw new HibernateException("A component cannot be the root of a walk nor a graph");
    }
    // No need to push anything here; it should have been pushed by
    // #startingAttribute, #startingCollectionElements, #startingCollectionIndex, or #startingEntityIdentifier
    final FetchSource currentSource = currentSource();
    if (!CompositeFetch.class.isInstance(currentSource) && !CollectionFetchableElement.class.isInstance(currentSource) && !CollectionFetchableIndex.class.isInstance(currentSource) && !ExpandingEntityIdentifierDescription.class.isInstance(currentSource)) {
        throw new WalkingException("Mismatched FetchSource from stack on pop");
    }
}
Also used : FetchSource(org.hibernate.loader.plan.spi.FetchSource) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) HibernateException(org.hibernate.HibernateException) CollectionFetchableIndex(org.hibernate.loader.plan.spi.CollectionFetchableIndex) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 9 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method startingEntityIdentifier.

// entity identifiers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public void startingEntityIdentifier(EntityIdentifierDefinition entityIdentifierDefinition) {
    log.tracef("%s Starting entity identifier : %s", StringHelper.repeat(">>", fetchSourceStack.size()), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName());
    final EntityReference entityReference = (EntityReference) currentSource();
    // perform some stack validation
    if (!entityReference.getEntityPersister().equals(entityIdentifierDefinition.getEntityDefinition().getEntityPersister())) {
        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()));
    }
    if (ExpandingEntityIdentifierDescription.class.isInstance(entityReference.getIdentifierDescription())) {
        pushToStack((ExpandingEntityIdentifierDescription) entityReference.getIdentifierDescription());
    }
}
Also used : EntityReference(org.hibernate.loader.plan.spi.EntityReference) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 10 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingCollectionIndex.

@Override
public void finishingCollectionIndex(CollectionIndexDefinition indexDefinition) {
    final Type indexType = indexDefinition.getType();
    if (indexType.isAnyType()) {
    // nothing to do because the index graph was not pushed in #startingCollectionIndex.
    } else if (indexType.isEntityType() || indexType.isComponentType()) {
        // todo : validate the stack?
        final ExpandingFetchSource fetchSource = popFromStack();
        if (!CollectionFetchableIndex.class.isInstance(fetchSource)) {
            throw new WalkingException("CollectionReference did not return an expected index graph : " + indexDefinition.getCollectionDefinition().getCollectionPersister().getRole());
        }
    }
    log.tracef("%s Finished collection index graph : %s", StringHelper.repeat("<<", fetchSourceStack.size()), indexDefinition.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)

Aggregations

WalkingException (org.hibernate.persister.walking.spi.WalkingException)11 ExpandingFetchSource (org.hibernate.loader.plan.build.spi.ExpandingFetchSource)5 Type (org.hibernate.type.Type)5 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 CollectionFetchableIndex (org.hibernate.loader.plan.spi.CollectionFetchableIndex)2 CollectionReference (org.hibernate.loader.plan.spi.CollectionReference)2 EntityReference (org.hibernate.loader.plan.spi.EntityReference)2 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)2 EntityType (org.hibernate.type.EntityType)2 Iterator (java.util.Iterator)1 HibernateException (org.hibernate.HibernateException)1 FetchStrategy (org.hibernate.engine.FetchStrategy)1 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)1 PropertyPath (org.hibernate.loader.PropertyPath)1 ExpandingCollectionQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCollectionQuerySpace)1 ExpandingEntityIdentifierDescription (org.hibernate.loader.plan.build.spi.ExpandingEntityIdentifierDescription)1 AttributeFetch (org.hibernate.loader.plan.spi.AttributeFetch)1 BidirectionalEntityReference (org.hibernate.loader.plan.spi.BidirectionalEntityReference)1 CollectionAttributeFetch (org.hibernate.loader.plan.spi.CollectionAttributeFetch)1 CompositeAttributeFetch (org.hibernate.loader.plan.spi.CompositeAttributeFetch)1