use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method bindEntityDiscriminator.
private void bindEntityDiscriminator(MappingDocument sourceDocument, final EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
final SimpleValue discriminatorValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
rootEntityDescriptor.setDiscriminator(discriminatorValue);
String typeName = hierarchySource.getDiscriminatorSource().getExplicitHibernateTypeName();
if (typeName == null) {
typeName = "string";
}
bindSimpleValueType(sourceDocument, new HibernateTypeSourceImpl(typeName), discriminatorValue);
relationalObjectBinder.bindColumnOrFormula(sourceDocument, hierarchySource.getDiscriminatorSource().getDiscriminatorRelationalValueSource(), discriminatorValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
return implicitNamingStrategy.determineDiscriminatorColumnName(hierarchySource.getDiscriminatorSource());
}
});
rootEntityDescriptor.setPolymorphic(true);
rootEntityDescriptor.setDiscriminatorInsertable(hierarchySource.getDiscriminatorSource().isInserted());
// todo : currently isForced() is defined as boolean, not Boolean
// although it has always been that way (DTD too)
final boolean force = hierarchySource.getDiscriminatorSource().isForced() || sourceDocument.getBuildingOptions().shouldImplicitlyForceDiscriminatorInSelect();
rootEntityDescriptor.setForceDiscriminator(force);
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class ModelBinder method bindListOrArrayIndex.
public void bindListOrArrayIndex(MappingDocument mappingDocument, final IndexedPluralAttributeSource attributeSource, org.hibernate.mapping.List collectionBinding) {
final PluralAttributeSequentialIndexSource indexSource = (PluralAttributeSequentialIndexSource) attributeSource.getIndexSource();
final SimpleValue indexBinding = new SimpleValue(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
bindSimpleValueType(mappingDocument, indexSource.getTypeInformation(), indexBinding);
relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, indexSource.getRelationalValueSources(), indexBinding, attributeSource.getElementSource() instanceof PluralAttributeElementSourceOneToMany, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
return context.getBuildingOptions().getImplicitNamingStrategy().determineListIndexColumnName(new ImplicitIndexColumnNameSource() {
@Override
public AttributePath getPluralAttributePath() {
return attributeSource.getAttributePath();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
});
}
});
collectionBinding.setIndex(indexBinding);
collectionBinding.setBaseIndex(indexSource.getBase());
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class TableBinder method bind.
// only bind association table currently
public Table bind() {
final Identifier ownerEntityTableNameIdentifier = toIdentifier(ownerEntityTable);
final Identifier associatedEntityTableNameIdentifier = toIdentifier(associatedEntityTable);
//logicalName only accurate for assoc table...
final String unquotedOwnerTable = StringHelper.unquote(ownerEntityTable);
final String unquotedAssocTable = StringHelper.unquote(associatedEntityTable);
//@ElementCollection use ownerEntity_property instead of the cleaner ownerTableName_property
// ownerEntity can be null when the table name is explicitly set; <== gb: doesn't seem to be true...
final String ownerObjectName = isJPA2ElementCollection && ownerEntity != null ? StringHelper.unqualify(ownerEntity) : unquotedOwnerTable;
final ObjectNameSource nameSource = buildNameContext(ownerObjectName, unquotedAssocTable);
final boolean ownerEntityTableQuoted = StringHelper.isQuoted(ownerEntityTable);
final boolean associatedEntityTableQuoted = StringHelper.isQuoted(associatedEntityTable);
final NamingStrategyHelper namingStrategyHelper = new NamingStrategyHelper() {
@Override
public Identifier determineImplicitName(final MetadataBuildingContext buildingContext) {
final ImplicitNamingStrategy namingStrategy = buildingContext.getBuildingOptions().getImplicitNamingStrategy();
Identifier name;
if (isJPA2ElementCollection) {
name = namingStrategy.determineCollectionTableName(new ImplicitCollectionTableNameSource() {
private final EntityNaming entityNaming = new EntityNaming() {
@Override
public String getClassName() {
return ownerClassName;
}
@Override
public String getEntityName() {
return ownerEntity;
}
@Override
public String getJpaEntityName() {
return ownerJpaEntity;
}
};
@Override
public Identifier getOwningPhysicalTableName() {
return ownerEntityTableNameIdentifier;
}
@Override
public EntityNaming getOwningEntityNaming() {
return entityNaming;
}
@Override
public AttributePath getOwningAttributePath() {
return AttributePath.parse(propertyName);
}
@Override
public MetadataBuildingContext getBuildingContext() {
return buildingContext;
}
});
} else {
name = namingStrategy.determineJoinTableName(new ImplicitJoinTableNameSource() {
private final EntityNaming owningEntityNaming = new EntityNaming() {
@Override
public String getClassName() {
return ownerClassName;
}
@Override
public String getEntityName() {
return ownerEntity;
}
@Override
public String getJpaEntityName() {
return ownerJpaEntity;
}
};
private final EntityNaming nonOwningEntityNaming = new EntityNaming() {
@Override
public String getClassName() {
return associatedClassName;
}
@Override
public String getEntityName() {
return associatedEntity;
}
@Override
public String getJpaEntityName() {
return associatedJpaEntity;
}
};
@Override
public String getOwningPhysicalTableName() {
return unquotedOwnerTable;
}
@Override
public EntityNaming getOwningEntityNaming() {
return owningEntityNaming;
}
@Override
public String getNonOwningPhysicalTableName() {
return unquotedAssocTable;
}
@Override
public EntityNaming getNonOwningEntityNaming() {
return nonOwningEntityNaming;
}
@Override
public AttributePath getAssociationOwningAttributePath() {
return AttributePath.parse(propertyName);
}
@Override
public MetadataBuildingContext getBuildingContext() {
return buildingContext;
}
});
}
if (ownerEntityTableQuoted || associatedEntityTableQuoted) {
name = Identifier.quote(name);
}
return name;
}
@Override
public Identifier handleExplicitName(String explicitName, MetadataBuildingContext buildingContext) {
return buildingContext.getMetadataCollector().getDatabase().toIdentifier(explicitName);
}
@Override
public Identifier toPhysicalName(Identifier logicalName, MetadataBuildingContext buildingContext) {
return buildingContext.getBuildingOptions().getPhysicalNamingStrategy().toPhysicalTableName(logicalName, buildingContext.getMetadataCollector().getDatabase().getJdbcEnvironment());
}
};
return buildAndFillTable(schema, catalog, nameSource, namingStrategyHelper, isAbstract, uniqueConstraints, jpaIndexHolders, constraints, buildingContext, null, null);
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class Ejb3Column method redefineColumnName.
public void redefineColumnName(String columnName, String propertyName, boolean applyNamingStrategy) {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
final Database database = context.getMetadataCollector().getDatabase();
final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions().getImplicitNamingStrategy();
final PhysicalNamingStrategy physicalNamingStrategy = context.getBuildingOptions().getPhysicalNamingStrategy();
if (applyNamingStrategy) {
if (StringHelper.isEmpty(columnName)) {
if (propertyName != null) {
final AttributePath attributePath = AttributePath.parse(propertyName);
Identifier implicitName = normalizer.normalizeIdentifierQuoting(implicitNamingStrategy.determineBasicColumnName(new ImplicitBasicColumnNameSource() {
@Override
public AttributePath getAttributePath() {
return attributePath;
}
@Override
public boolean isCollectionElement() {
// @Column refers to the element column
return !propertyHolder.isComponent() && !propertyHolder.isEntity();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
}));
// HHH-6005 magic
if (implicitName.getText().contains("_collection&&element_")) {
implicitName = Identifier.toIdentifier(implicitName.getText().replace("_collection&&element_", "_"), implicitName.isQuoted());
}
final Identifier physicalName = physicalNamingStrategy.toPhysicalColumnName(implicitName, database.getJdbcEnvironment());
mappingColumn.setName(physicalName.render(database.getDialect()));
}
//Do nothing otherwise
} else {
final Identifier explicitName = database.toIdentifier(columnName);
final Identifier physicalName = physicalNamingStrategy.toPhysicalColumnName(explicitName, database.getJdbcEnvironment());
mappingColumn.setName(physicalName.render(database.getDialect()));
}
} else {
if (StringHelper.isNotEmpty(columnName)) {
mappingColumn.setName(normalizer.toDatabaseIdentifierText(columnName));
}
}
}
use of org.hibernate.boot.model.naming.Identifier in project hibernate-orm by hibernate.
the class Ejb3Column method addColumnBinding.
protected void addColumnBinding(SimpleValue value) {
final String logicalColumnName;
if (StringHelper.isNotEmpty(this.logicalColumnName)) {
logicalColumnName = this.logicalColumnName;
} else {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
final Database database = context.getMetadataCollector().getDatabase();
final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions().getImplicitNamingStrategy();
final Identifier implicitName = normalizer.normalizeIdentifierQuoting(implicitNamingStrategy.determineBasicColumnName(new ImplicitBasicColumnNameSource() {
@Override
public AttributePath getAttributePath() {
return AttributePath.parse(propertyName);
}
@Override
public boolean isCollectionElement() {
return false;
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
}));
logicalColumnName = implicitName.render(database.getDialect());
}
context.getMetadataCollector().addColumnNameBinding(value.getTable(), logicalColumnName, getMappingColumn());
}
Aggregations