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