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());
}
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());
}
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());
}
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;
}
}
}
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();
}
Aggregations