use of org.hibernate.loader.PropertyPath in project hibernate-orm by hibernate.
the class MetamodelGraphWalker method visitAttributeDefinition.
private void visitAttributeDefinition(AttributeDefinition attributeDefinition) {
final PropertyPath subPath = currentPropertyPath.append(attributeDefinition.getName());
log.debug("Visiting attribute path : " + subPath.getFullPath());
if (attributeDefinition.getType().isAssociationType()) {
final AssociationAttributeDefinition associationAttributeDefinition = (AssociationAttributeDefinition) attributeDefinition;
final AssociationKey associationKey = associationAttributeDefinition.getAssociationKey();
if (isDuplicateAssociationKey(associationKey)) {
log.debug("Property path deemed to be circular : " + subPath.getFullPath());
strategy.foundCircularAssociation(associationAttributeDefinition);
// EARLY EXIT!!!
return;
}
}
boolean continueWalk = strategy.startingAttribute(attributeDefinition);
if (continueWalk) {
final PropertyPath old = currentPropertyPath;
currentPropertyPath = subPath;
try {
final Type attributeType = attributeDefinition.getType();
if (attributeType.isAssociationType()) {
visitAssociation((AssociationAttributeDefinition) attributeDefinition);
} else if (attributeType.isComponentType()) {
visitCompositeDefinition((CompositionDefinition) attributeDefinition);
}
} finally {
currentPropertyPath = old;
}
}
strategy.finishingAttribute(attributeDefinition);
}
use of org.hibernate.loader.PropertyPath in project hibernate-orm by hibernate.
the class CompositionSingularSubAttributesHelper method getSingularSubAttributes.
private static Iterable<AttributeDefinition> getSingularSubAttributes(final AttributeSource source, final OuterJoinLoadable ownerEntityPersister, final CompositeType compositeType, final String lhsTableName, final String[] lhsColumns) {
return new Iterable<AttributeDefinition>() {
@Override
public Iterator<AttributeDefinition> iterator() {
return new Iterator<AttributeDefinition>() {
private final int numberOfAttributes = compositeType.getSubtypes().length;
private int currentSubAttributeNumber;
private int currentColumnPosition;
@Override
public boolean hasNext() {
return currentSubAttributeNumber < numberOfAttributes;
}
@Override
public AttributeDefinition next() {
final int subAttributeNumber = currentSubAttributeNumber;
currentSubAttributeNumber++;
final String name = compositeType.getPropertyNames()[subAttributeNumber];
final Type type = compositeType.getSubtypes()[subAttributeNumber];
final int columnPosition = currentColumnPosition;
final int columnSpan = type.getColumnSpan(ownerEntityPersister.getFactory());
final String[] subAttributeLhsColumns = ArrayHelper.slice(lhsColumns, columnPosition, columnSpan);
final boolean[] propertyNullability = compositeType.getPropertyNullability();
final boolean nullable = propertyNullability == null || propertyNullability[subAttributeNumber];
currentColumnPosition += columnSpan;
if (type.isAssociationType()) {
final AssociationType aType = (AssociationType) type;
return new AssociationAttributeDefinition() {
@Override
public AssociationKey getAssociationKey() {
return new AssociationKey(lhsTableName, subAttributeLhsColumns);
}
@Override
public AssociationNature getAssociationNature() {
if (type.isAnyType()) {
return AssociationNature.ANY;
} else {
// cannot be a collection
return AssociationNature.ENTITY;
}
}
@Override
public EntityDefinition toEntityDefinition() {
if (getAssociationNature() != AssociationNature.ENTITY) {
throw new WalkingException("Cannot build EntityDefinition from non-entity-typed attribute");
}
return (EntityPersister) aType.getAssociatedJoinable(ownerEntityPersister.getFactory());
}
@Override
public AnyMappingDefinition toAnyDefinition() {
if (getAssociationNature() != AssociationNature.ANY) {
throw new WalkingException("Cannot build AnyMappingDefinition from non-any-typed attribute");
}
// todo : not sure how lazy is propogated into the component for a subattribute of type any
return new StandardAnyTypeDefinition((AnyType) aType, false);
}
@Override
public CollectionDefinition toCollectionDefinition() {
throw new WalkingException("A collection cannot be mapped to a composite ID sub-attribute.");
}
@Override
public FetchStrategy determineFetchPlan(LoadQueryInfluencers loadQueryInfluencers, PropertyPath propertyPath) {
return new FetchStrategy(FetchTiming.IMMEDIATE, FetchStyle.JOIN);
}
@Override
public CascadeStyle determineCascadeStyle() {
return CascadeStyles.NONE;
}
@Override
public HydratedCompoundValueHandler getHydratedCompoundValueExtractor() {
return null;
}
@Override
public String getName() {
return name;
}
@Override
public AssociationType getType() {
return aType;
}
@Override
public boolean isNullable() {
return nullable;
}
@Override
public AttributeSource getSource() {
return source;
}
};
} else if (type.isComponentType()) {
return new CompositionDefinition() {
@Override
public String getName() {
return name;
}
@Override
public CompositeType getType() {
return (CompositeType) type;
}
@Override
public boolean isNullable() {
return nullable;
}
@Override
public AttributeSource getSource() {
return source;
}
@Override
public Iterable<AttributeDefinition> getAttributes() {
return CompositionSingularSubAttributesHelper.getSingularSubAttributes(this, ownerEntityPersister, (CompositeType) type, lhsTableName, subAttributeLhsColumns);
}
};
} else {
return new AttributeDefinition() {
@Override
public String getName() {
return name;
}
@Override
public Type getType() {
return type;
}
@Override
public boolean isNullable() {
return nullable;
}
@Override
public AttributeSource getSource() {
return source;
}
};
}
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove operation not supported here");
}
};
}
};
}
use of org.hibernate.loader.PropertyPath in project hibernate-orm by hibernate.
the class MetamodelGraphWalker method visitAttributeDefinition.
private void visitAttributeDefinition(AttributeDefinition attributeDefinition, AbstractEntityPersister sourcePersister) {
final PropertyPath subPath = currentPropertyPath.append(attributeDefinition.getName());
log.debug("Visiting attribute path : " + subPath.getFullPath());
if (attributeDefinition.getType().isAssociationType()) {
final AssociationAttributeDefinition associationAttributeDefinition = (AssociationAttributeDefinition) attributeDefinition;
final AssociationKey associationKey = associationAttributeDefinition.getAssociationKey();
if (isDuplicateAssociationKey(associationKey)) {
log.debug("Property path deemed to be circular : " + subPath.getFullPath());
strategy.foundCircularAssociation(associationAttributeDefinition);
// EARLY EXIT!!!
return;
}
if (sourcePersister != null) {
String[] columns = sourcePersister.toColumns(attributeDefinition.getName());
// Empty columns means that the attribute is not resolvable on this persister
if (columns.length == 0) {
return;
}
}
}
boolean continueWalk = strategy.startingAttribute(attributeDefinition);
if (continueWalk) {
final PropertyPath old = currentPropertyPath;
currentPropertyPath = subPath;
try {
final Type attributeType = attributeDefinition.getType();
if (attributeType.isAssociationType()) {
visitAssociation((AssociationAttributeDefinition) attributeDefinition);
} else if (attributeType.isComponentType()) {
visitCompositeDefinition((CompositionDefinition) attributeDefinition);
}
} finally {
currentPropertyPath = old;
}
}
strategy.finishingAttribute(attributeDefinition);
}
Aggregations