use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method bindMapKey.
private void bindMapKey(final MappingDocument mappingDocument, final IndexedPluralAttributeSource pluralAttributeSource, final org.hibernate.mapping.Map collectionBinding) {
if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceBasic) {
final PluralAttributeMapKeySourceBasic mapKeySource = (PluralAttributeMapKeySourceBasic) pluralAttributeSource.getIndexSource();
final SimpleValue value = new SimpleValue(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
bindSimpleValueType(mappingDocument, mapKeySource.getTypeInformation(), value);
if (!value.isTypeSpecified()) {
throw new MappingException("map index element must specify a type: " + pluralAttributeSource.getAttributeRole().getFullPath(), mappingDocument.getOrigin());
}
relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), value, true, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
return database.toIdentifier(IndexedCollection.DEFAULT_INDEX_COLUMN_NAME);
}
});
collectionBinding.setIndex(value);
} else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceEmbedded) {
final PluralAttributeMapKeySourceEmbedded mapKeySource = (PluralAttributeMapKeySourceEmbedded) pluralAttributeSource.getIndexSource();
final Component componentBinding = new Component(mappingDocument.getMetadataCollector(), collectionBinding);
bindComponent(mappingDocument, mapKeySource.getEmbeddableSource(), componentBinding, null, pluralAttributeSource.getName(), mapKeySource.getXmlNodeName(), false);
collectionBinding.setIndex(componentBinding);
} else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToManySource) {
final PluralAttributeMapKeyManyToManySource mapKeySource = (PluralAttributeMapKeyManyToManySource) pluralAttributeSource.getIndexSource();
final ManyToOne mapKeyBinding = new ManyToOne(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
mapKeyBinding.setReferencedEntityName(mapKeySource.getReferencedEntityName());
relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), mapKeyBinding, true, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
return implicitNamingStrategy.determineMapKeyColumnName(new ImplicitMapKeyColumnNameSource() {
@Override
public AttributePath getPluralAttributePath() {
return pluralAttributeSource.getAttributePath();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
});
}
});
collectionBinding.setIndex(mapKeyBinding);
} else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToAnySource) {
final PluralAttributeMapKeyManyToAnySource mapKeySource = (PluralAttributeMapKeyManyToAnySource) pluralAttributeSource.getIndexSource();
final Any mapKeyBinding = new Any(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
bindAny(mappingDocument, mapKeySource, mapKeyBinding, pluralAttributeSource.getAttributeRole().append("key"), pluralAttributeSource.getAttributePath().append("key"));
collectionBinding.setIndex(mapKeyBinding);
}
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method bindEntityVersion.
private void bindEntityVersion(MappingDocument sourceDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource();
final SimpleValue versionValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
versionValue.makeVersion();
bindSimpleValueType(sourceDocument, versionAttributeSource.getTypeInformation(), versionValue);
relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, versionAttributeSource.getRelationalValueSources(), versionValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
return implicitNamingStrategy.determineBasicColumnName(versionAttributeSource);
}
});
Property prop = new Property();
prop.setValue(versionValue);
bindProperty(sourceDocument, versionAttributeSource, prop);
// but just to make sure...
if (prop.getValueGenerationStrategy() != null) {
if (prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT) {
throw new MappingException("'generated' attribute cannot be 'insert' for version/timestamp property", sourceDocument.getOrigin());
}
}
if (versionAttributeSource.getUnsavedValue() != null) {
versionValue.setNullValue(versionAttributeSource.getUnsavedValue());
} else {
versionValue.setNullValue("undefined");
}
rootEntityDescriptor.setVersion(prop);
rootEntityDescriptor.setDeclaredVersion(prop);
rootEntityDescriptor.addProperty(prop);
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method bindJoinedSubclassEntity.
private void bindJoinedSubclassEntity(JoinedSubclassEntitySourceImpl entitySource, JoinedSubclass entityDescriptor) {
MappingDocument mappingDocument = entitySource.sourceMappingDocument();
bindBasicEntityValues(mappingDocument, entitySource, entityDescriptor);
final Table primaryTable = bindEntityTableSpecification(mappingDocument, entitySource.getPrimaryTable(), null, entitySource, entityDescriptor);
entityDescriptor.setTable(primaryTable);
if (log.isDebugEnabled()) {
log.debugf("Mapping joined-subclass: %s -> %s", entityDescriptor.getEntityName(), primaryTable.getName());
}
// KEY
final SimpleValue keyBinding = new DependantValue(mappingDocument.getMetadataCollector(), primaryTable, entityDescriptor.getIdentifier());
if (mappingDocument.getBuildingOptions().useNationalizedCharacterData()) {
keyBinding.makeNationalized();
}
entityDescriptor.setKey(keyBinding);
keyBinding.setCascadeDeleteEnabled(entitySource.isCascadeDeleteEnabled());
relationalObjectBinder.bindColumns(mappingDocument, entitySource.getPrimaryKeyColumnSources(), keyBinding, false, new RelationalObjectBinder.ColumnNamingDelegate() {
int count = 0;
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
final Column column = primaryTable.getPrimaryKey().getColumn(count++);
return database.toIdentifier(column.getQuotedName());
}
});
keyBinding.setForeignKeyName(entitySource.getExplicitForeignKeyName());
// model.getKey().setType( new Type( model.getIdentifier() ) );
entityDescriptor.createPrimaryKey();
entityDescriptor.createForeignKey();
// todo : tooling hints
bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
bindJoinedSubclassEntities(entitySource, entityDescriptor);
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class RelationalObjectBinder method bindColumn.
public void bindColumn(MappingDocument sourceDocument, ColumnSource columnSource, SimpleValue simpleValue, boolean areColumnsNullableByDefault, ColumnNamingDelegate columnNamingDelegate) {
Table table = simpleValue.getTable();
final Column column = new Column();
column.setValue(simpleValue);
// resolve column name
final Identifier logicalName;
if (StringHelper.isNotEmpty(columnSource.getName())) {
logicalName = database.toIdentifier(columnSource.getName());
} else {
logicalName = columnNamingDelegate.determineImplicitName(sourceDocument);
}
final Identifier physicalName = physicalNamingStrategy.toPhysicalColumnName(logicalName, database.getJdbcEnvironment());
column.setName(physicalName.render(database.getDialect()));
if (table != null) {
table.addColumn(column);
sourceDocument.getMetadataCollector().addColumnNameBinding(table, logicalName, column);
}
if (columnSource.getSizeSource() != null) {
// to indicate null
if (columnSource.getSizeSource().getLength() != null) {
column.setLength(columnSource.getSizeSource().getLength());
} else {
column.setLength(Column.DEFAULT_LENGTH);
}
if (columnSource.getSizeSource().getScale() != null) {
column.setScale(columnSource.getSizeSource().getScale());
} else {
column.setScale(Column.DEFAULT_SCALE);
}
if (columnSource.getSizeSource().getPrecision() != null) {
column.setPrecision(columnSource.getSizeSource().getPrecision());
} else {
column.setPrecision(Column.DEFAULT_PRECISION);
}
}
column.setNullable(interpretNullability(columnSource.isNullable(), areColumnsNullableByDefault));
column.setUnique(columnSource.isUnique());
column.setCheckConstraint(columnSource.getCheckCondition());
column.setDefaultValue(columnSource.getDefaultValue());
column.setSqlType(columnSource.getSqlType());
column.setComment(columnSource.getComment());
column.setCustomRead(columnSource.getReadFragment());
column.setCustomWrite(columnSource.getWriteFragment());
simpleValue.addColumn(column);
if (table != null) {
for (String name : columnSource.getIndexConstraintNames()) {
table.getOrCreateIndex(name).addColumn(column);
}
for (String name : columnSource.getUniqueKeyConstraintNames()) {
table.getOrCreateUniqueKey(name).addColumn(column);
}
}
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method determineTable.
private Identifier determineTable(MappingDocument mappingDocument, SingularAttributeSourceEmbedded embeddedAttributeSource) {
Identifier tableName = null;
for (AttributeSource attributeSource : embeddedAttributeSource.getEmbeddableSource().attributeSources()) {
final Identifier determinedName;
if (RelationalValueSourceContainer.class.isInstance(attributeSource)) {
determinedName = determineTable(mappingDocument, embeddedAttributeSource.getAttributeRole().getFullPath(), (RelationalValueSourceContainer) attributeSource);
} else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
determinedName = determineTable(mappingDocument, (SingularAttributeSourceEmbedded) attributeSource);
} else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
determinedName = determineTable(mappingDocument, attributeSource.getAttributeRole().getFullPath(), ((SingularAttributeSourceAny) attributeSource).getKeySource().getRelationalValueSources());
} else {
continue;
}
if (EqualsHelper.equals(tableName, determinedName)) {
continue;
}
if (tableName != null) {
throw new MappingException(String.format(Locale.ENGLISH, "Attribute [%s] referenced columns from multiple tables: %s, %s", embeddedAttributeSource.getAttributeRole().getFullPath(), tableName, determinedName), mappingDocument.getOrigin());
}
tableName = determinedName;
}
return tableName;
}
Aggregations