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;
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method createBasicAttribute.
private Property createBasicAttribute(MappingDocument sourceDocument, final SingularAttributeSourceBasic attributeSource, SimpleValue value, String containingClassName) {
final String attributeName = attributeSource.getName();
bindSimpleValueType(sourceDocument, attributeSource.getTypeInformation(), value);
relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, attributeSource.getRelationalValueSources(), value, attributeSource.areValuesNullableByDefault(), new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
return implicitNamingStrategy.determineBasicColumnName(attributeSource);
}
});
prepareValueTypeViaReflection(sourceDocument, value, containingClassName, attributeName, attributeSource.getAttributeRole());
// // this is done here 'cos we might only know the type here (ugly!)
// // TODO: improve this a lot:
// if ( value instanceof ToOne ) {
// ToOne toOne = (ToOne) value;
// String propertyRef = toOne.getReferencedEntityAttributeName();
// if ( propertyRef != null ) {
// mappings.addUniquePropertyReference( toOne.getReferencedEntityName(), propertyRef );
// }
// toOne.setCascadeDeleteEnabled( "cascade".equals( subnode.attributeValue( "on-delete" ) ) );
// }
// else if ( value instanceof Collection ) {
// Collection coll = (Collection) value;
// String propertyRef = coll.getReferencedEntityAttributeName();
// // not necessarily a *unique* property reference
// if ( propertyRef != null ) {
// mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );
// }
// }
value.createForeignKey();
Property property = new Property();
property.setValue(value);
bindProperty(sourceDocument, attributeSource, property);
return property;
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class Namespace method createDenormalizedTable.
public DenormalizedTable createDenormalizedTable(Identifier logicalTableName, boolean isAbstract, Table includedTable) {
final Table existing = tables.get(logicalTableName);
if (existing != null) {
// for now assume it is
return (DenormalizedTable) existing;
}
final Identifier physicalTableName = database.getPhysicalNamingStrategy().toPhysicalTableName(logicalTableName, database.getJdbcEnvironment());
DenormalizedTable table = new DenormalizedTable(this, physicalTableName, isAbstract, includedTable);
tables.put(logicalTableName, table);
return table;
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class Namespace method createSequence.
public Sequence createSequence(Identifier logicalName, int initialValue, int increment) {
if (sequences.containsKey(logicalName)) {
throw new HibernateException("Sequence was already registered with that name [" + logicalName.toString() + "]");
}
final Identifier physicalName = database.getPhysicalNamingStrategy().toPhysicalSequenceName(logicalName, database.getJdbcEnvironment());
Sequence sequence = new Sequence(this.physicalName.getCatalog(), this.physicalName.getSchema(), physicalName, initialValue, increment);
sequences.put(logicalName, sequence);
return sequence;
}
Aggregations