Search in sources :

Example 1 with ImplicitBasicColumnNameSource

use of org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource 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));
        }
    }
}
Also used : ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) Identifier(org.hibernate.boot.model.naming.Identifier) Database(org.hibernate.boot.model.relational.Database) ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer) ImplicitBasicColumnNameSource(org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource) PhysicalNamingStrategy(org.hibernate.boot.model.naming.PhysicalNamingStrategy) AttributePath(org.hibernate.boot.model.source.spi.AttributePath)

Example 2 with ImplicitBasicColumnNameSource

use of org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource 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());
}
Also used : ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) Identifier(org.hibernate.boot.model.naming.Identifier) Database(org.hibernate.boot.model.relational.Database) ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer) ImplicitBasicColumnNameSource(org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource)

Aggregations

Identifier (org.hibernate.boot.model.naming.Identifier)2 ImplicitBasicColumnNameSource (org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource)2 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)2 ObjectNameNormalizer (org.hibernate.boot.model.naming.ObjectNameNormalizer)2 Database (org.hibernate.boot.model.relational.Database)2 PhysicalNamingStrategy (org.hibernate.boot.model.naming.PhysicalNamingStrategy)1 AttributePath (org.hibernate.boot.model.source.spi.AttributePath)1