use of org.hibernate.mapping.DependantBasicValue in project hibernate-orm by hibernate.
the class MapBinder method createFormulatedValue.
protected Value createFormulatedValue(Value value, Collection collection, String targetPropertyName, PersistentClass associatedClass, PersistentClass targetPropertyPersistentClass, MetadataBuildingContext buildingContext) {
final Table mapKeyTable;
// HHH-11005 - only if we are OneToMany and location of map key property is at a different level, need to add a select
if (!associatedClass.equals(targetPropertyPersistentClass)) {
mapKeyTable = targetPropertyPersistentClass.getTable();
} else {
mapKeyTable = associatedClass.getTable();
}
if (value instanceof Component) {
Component component = (Component) value;
Component indexComponent = new Component(getBuildingContext(), collection);
indexComponent.setComponentClassName(component.getComponentClassName());
for (Property current : component.getProperties()) {
Property newProperty = new Property();
newProperty.setCascade(current.getCascade());
newProperty.setValueGenerationStrategy(current.getValueGenerationStrategy());
newProperty.setInsertable(false);
newProperty.setUpdateable(false);
newProperty.setMetaAttributes(current.getMetaAttributes());
newProperty.setName(current.getName());
newProperty.setNaturalIdentifier(false);
// newProperty.setOptimisticLocked( false );
newProperty.setOptional(false);
newProperty.setPersistentClass(current.getPersistentClass());
newProperty.setPropertyAccessorName(current.getPropertyAccessorName());
newProperty.setSelectable(current.isSelectable());
newProperty.setValue(createFormulatedValue(current.getValue(), collection, targetPropertyName, associatedClass, associatedClass, buildingContext));
indexComponent.addProperty(newProperty);
}
return indexComponent;
} else if (value instanceof BasicValue) {
final BasicValue sourceValue = (BasicValue) value;
final DependantBasicValue dependantBasicValue = new DependantBasicValue(getBuildingContext(), mapKeyTable, sourceValue, false, false);
final Selectable sourceValueColumn = sourceValue.getColumn();
if (sourceValueColumn instanceof Column) {
dependantBasicValue.addColumn(((Column) sourceValueColumn).clone());
} else if (sourceValueColumn instanceof Formula) {
dependantBasicValue.addFormula(new Formula(((Formula) sourceValueColumn).getFormula()));
} else {
throw new AssertionFailure("Unknown element column type : " + sourceValueColumn.getClass());
}
return dependantBasicValue;
} else if (value instanceof SimpleValue) {
SimpleValue sourceValue = (SimpleValue) value;
SimpleValue targetValue;
if (value instanceof ManyToOne) {
ManyToOne sourceManyToOne = (ManyToOne) sourceValue;
ManyToOne targetManyToOne = new ManyToOne(getBuildingContext(), mapKeyTable);
targetManyToOne.setFetchMode(FetchMode.DEFAULT);
targetManyToOne.setLazy(true);
// targetValue.setIgnoreNotFound( ); does not make sense for a map key
targetManyToOne.setReferencedEntityName(sourceManyToOne.getReferencedEntityName());
targetValue = targetManyToOne;
} else {
targetValue = new BasicValue(getBuildingContext(), mapKeyTable);
targetValue.copyTypeFrom(sourceValue);
}
for (Selectable current : sourceValue.getSelectables()) {
if (current instanceof Column) {
targetValue.addColumn(((Column) current).clone());
} else if (current instanceof Formula) {
targetValue.addFormula(new Formula(((Formula) current).getFormula()));
} else {
throw new AssertionFailure("Unknown element in column iterator: " + current.getClass());
}
}
return targetValue;
} else {
throw new AssertionFailure("Unknown type encountered for map key: " + value.getClass());
}
}
Aggregations