use of org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne in project hibernate-orm by hibernate.
the class ModelBinder method bindAllEntityAttributes.
private void bindAllEntityAttributes(MappingDocument mappingDocument, EntitySource entitySource, PersistentClass entityDescriptor) {
final EntityTableXref entityTableXref = mappingDocument.getMetadataCollector().getEntityTableXref(entityDescriptor.getEntityName());
if (entityTableXref == null) {
throw new AssertionFailure(String.format(Locale.ENGLISH, "Unable to locate EntityTableXref for entity [%s] : %s", entityDescriptor.getEntityName(), mappingDocument.getOrigin()));
}
// make sure we bind secondary tables first!
for (SecondaryTableSource secondaryTableSource : entitySource.getSecondaryTableMap().values()) {
final Join secondaryTableJoin = new Join();
secondaryTableJoin.setPersistentClass(entityDescriptor);
bindSecondaryTable(mappingDocument, secondaryTableSource, secondaryTableJoin, entityTableXref);
entityDescriptor.addJoin(secondaryTableJoin);
}
for (AttributeSource attributeSource : entitySource.attributeSources()) {
if (PluralAttributeSource.class.isInstance(attributeSource)) {
// plural attribute
final Property attribute = createPluralAttribute(mappingDocument, (PluralAttributeSource) attributeSource, entityDescriptor);
entityDescriptor.addProperty(attribute);
} else {
// singular attribute
if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
final SingularAttributeSourceBasic basicAttributeSource = (SingularAttributeSourceBasic) attributeSource;
final Identifier tableName = determineTable(mappingDocument, basicAttributeSource.getName(), basicAttributeSource);
final AttributeContainer attributeContainer;
final Table table;
final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
if (secondaryTableJoin == null) {
table = entityDescriptor.getTable();
attributeContainer = entityDescriptor;
} else {
table = secondaryTableJoin.getTable();
attributeContainer = secondaryTableJoin;
}
final Property attribute = createBasicAttribute(mappingDocument, basicAttributeSource, new SimpleValue(mappingDocument, table), entityDescriptor.getClassName());
if (secondaryTableJoin != null) {
attribute.setOptional(secondaryTableJoin.isOptional());
}
attributeContainer.addProperty(attribute);
handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, basicAttributeSource.getNaturalIdMutability());
} else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
final SingularAttributeSourceEmbedded embeddedAttributeSource = (SingularAttributeSourceEmbedded) attributeSource;
final Identifier tableName = determineTable(mappingDocument, embeddedAttributeSource);
final AttributeContainer attributeContainer;
final Table table;
final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
if (secondaryTableJoin == null) {
table = entityDescriptor.getTable();
attributeContainer = entityDescriptor;
} else {
table = secondaryTableJoin.getTable();
attributeContainer = secondaryTableJoin;
}
final Property attribute = createEmbeddedAttribute(mappingDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(mappingDocument, table, entityDescriptor), entityDescriptor.getClassName());
if (secondaryTableJoin != null) {
attribute.setOptional(secondaryTableJoin.isOptional());
}
attributeContainer.addProperty(attribute);
handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, embeddedAttributeSource.getNaturalIdMutability());
} else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
final SingularAttributeSourceManyToOne manyToOneAttributeSource = (SingularAttributeSourceManyToOne) attributeSource;
final Identifier tableName = determineTable(mappingDocument, manyToOneAttributeSource.getName(), manyToOneAttributeSource);
final AttributeContainer attributeContainer;
final Table table;
final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
if (secondaryTableJoin == null) {
table = entityDescriptor.getTable();
attributeContainer = entityDescriptor;
} else {
table = secondaryTableJoin.getTable();
attributeContainer = secondaryTableJoin;
}
final Property attribute = createManyToOneAttribute(mappingDocument, manyToOneAttributeSource, new ManyToOne(mappingDocument, table), entityDescriptor.getClassName());
if (secondaryTableJoin != null) {
attribute.setOptional(secondaryTableJoin.isOptional());
}
attributeContainer.addProperty(attribute);
handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, manyToOneAttributeSource.getNaturalIdMutability());
} else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
final SingularAttributeSourceOneToOne oneToOneAttributeSource = (SingularAttributeSourceOneToOne) attributeSource;
final Table table = entityDescriptor.getTable();
final Property attribute = createOneToOneAttribute(mappingDocument, oneToOneAttributeSource, new OneToOne(mappingDocument, table, entityDescriptor), entityDescriptor.getClassName());
entityDescriptor.addProperty(attribute);
handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, oneToOneAttributeSource.getNaturalIdMutability());
} else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
final SingularAttributeSourceAny anyAttributeSource = (SingularAttributeSourceAny) attributeSource;
final Identifier tableName = determineTable(mappingDocument, anyAttributeSource.getName(), anyAttributeSource.getKeySource().getRelationalValueSources());
final AttributeContainer attributeContainer;
final Table table;
final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
if (secondaryTableJoin == null) {
table = entityDescriptor.getTable();
attributeContainer = entityDescriptor;
} else {
table = secondaryTableJoin.getTable();
attributeContainer = secondaryTableJoin;
}
final Property attribute = createAnyAssociationAttribute(mappingDocument, anyAttributeSource, new Any(mappingDocument, table), entityDescriptor.getEntityName());
if (secondaryTableJoin != null) {
attribute.setOptional(secondaryTableJoin.isOptional());
}
attributeContainer.addProperty(attribute);
handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, anyAttributeSource.getNaturalIdMutability());
}
}
}
}
use of org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne in project hibernate-orm by hibernate.
the class ModelBinder method bindAllCompositeAttributes.
private void bindAllCompositeAttributes(MappingDocument sourceDocument, EmbeddableSource embeddableSource, Component component) {
for (AttributeSource attributeSource : embeddableSource.attributeSources()) {
Property attribute = null;
if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
attribute = createBasicAttribute(sourceDocument, (SingularAttributeSourceBasic) attributeSource, new SimpleValue(sourceDocument, component.getTable()), component.getComponentClassName());
} else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
attribute = createEmbeddedAttribute(sourceDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(sourceDocument, component), component.getComponentClassName());
} else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
attribute = createManyToOneAttribute(sourceDocument, (SingularAttributeSourceManyToOne) attributeSource, new ManyToOne(sourceDocument, component.getTable()), component.getComponentClassName());
} else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
attribute = createOneToOneAttribute(sourceDocument, (SingularAttributeSourceOneToOne) attributeSource, new OneToOne(sourceDocument, component.getTable(), component.getOwner()), component.getComponentClassName());
} else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
attribute = createAnyAssociationAttribute(sourceDocument, (SingularAttributeSourceAny) attributeSource, new Any(sourceDocument, component.getTable()), component.getComponentClassName());
} else if (PluralAttributeSource.class.isInstance(attributeSource)) {
attribute = createPluralAttribute(sourceDocument, (PluralAttributeSource) attributeSource, component.getOwner());
} else {
throw new AssertionFailure(String.format(Locale.ENGLISH, "Unexpected AttributeSource sub-type [%s] as part of composite [%s]", attributeSource.getClass().getName(), attributeSource.getAttributeRole().getFullPath()));
}
component.addProperty(attribute);
}
}
Aggregations