Search in sources :

Example 1 with ObjectNameNormalizer

use of org.hibernate.boot.model.naming.ObjectNameNormalizer 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)

Example 2 with ObjectNameNormalizer

use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.

the class SequenceHiLoGeneratorNoIncrementTest method setUp.

@Before
public void setUp() throws Exception {
    serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    generator = new SequenceStyleGenerator();
    // Build the properties used to configure the id generator
    Properties properties = new Properties();
    properties.setProperty(SequenceStyleGenerator.SEQUENCE_PARAM, TEST_SEQUENCE);
    properties.setProperty(SequenceStyleGenerator.OPT_PARAM, "legacy-hilo");
    // JPA allocationSize of 1
    properties.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "0");
    properties.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() {

        @Override
        protected MetadataBuildingContext getBuildingContext() {
            return new MetadataBuildingContextTestingImpl(serviceRegistry);
        }
    });
    generator.configure(StandardBasicTypes.LONG, properties, serviceRegistry);
    final Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
    generator.registerExportables(metadata.getDatabase());
    sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
    sequenceValueExtractor = new SequenceValueExtractor(sessionFactory.getDialect(), TEST_SEQUENCE);
}
Also used : MetadataBuildingContextTestingImpl(org.hibernate.testing.boot.MetadataBuildingContextTestingImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer) SequenceStyleGenerator(org.hibernate.id.enhanced.SequenceStyleGenerator) Properties(java.util.Properties) Before(org.junit.Before)

Example 3 with ObjectNameNormalizer

use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.

the class SequenceGenerator method configure.

@Override
@SuppressWarnings("StatementWithEmptyBody")
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
    DeprecationLogger.DEPRECATION_LOGGER.deprecatedSequenceGenerator(getClass().getName());
    identifierType = type;
    final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER);
    logicalQualifiedSequenceName = QualifiedNameParser.INSTANCE.parse(ConfigurationHelper.getString(SEQUENCE, params, "hibernate_sequence"), normalizer.normalizeIdentifierQuoting(params.getProperty(CATALOG)), normalizer.normalizeIdentifierQuoting(params.getProperty(SCHEMA)));
    if (params.containsKey(PARAMETERS)) {
        LOG.warn("Use of 'parameters' config setting is no longer supported; " + "to specify initial-value or increment use the " + "org.hibernate.id.enhanced.SequenceStyleGenerator generator instead.");
    }
}
Also used : ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer)

Example 4 with ObjectNameNormalizer

use of org.hibernate.boot.model.naming.ObjectNameNormalizer 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 5 with ObjectNameNormalizer

use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.

the class Ejb3JoinColumn method buildJoinColumn.

/**
 * Build JoinColumn for a JOINED hierarchy
 */
public static Ejb3JoinColumn buildJoinColumn(PrimaryKeyJoinColumn pkJoinAnn, JoinColumn joinAnn, Value identifier, Map<String, Join> joins, PropertyHolder propertyHolder, MetadataBuildingContext context) {
    final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
    Column col = (Column) identifier.getColumnIterator().next();
    String defaultName = context.getMetadataCollector().getLogicalColumnName(identifier.getTable(), col.getQuotedName());
    if (pkJoinAnn != null || joinAnn != null) {
        String colName;
        String columnDefinition;
        String referencedColumnName;
        if (pkJoinAnn != null) {
            colName = pkJoinAnn.name();
            columnDefinition = pkJoinAnn.columnDefinition();
            referencedColumnName = pkJoinAnn.referencedColumnName();
        } else {
            colName = joinAnn.name();
            columnDefinition = joinAnn.columnDefinition();
            referencedColumnName = joinAnn.referencedColumnName();
        }
        final String sqlType;
        if (columnDefinition.equals("")) {
            sqlType = null;
        } else {
            sqlType = normalizer.toDatabaseIdentifierText(columnDefinition);
        }
        final String name;
        if ("".equals(colName)) {
            name = normalizer.normalizeIdentifierQuotingAsString(defaultName);
        } else {
            name = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(colName);
        }
        return new Ejb3JoinColumn(sqlType, name, false, false, true, true, referencedColumnName, null, joins, propertyHolder, null, null, false, context);
    } else {
        defaultName = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(defaultName);
        return new Ejb3JoinColumn(null, defaultName, false, false, true, true, null, null, joins, propertyHolder, null, null, true, context);
    }
}
Also used : JoinColumn(javax.persistence.JoinColumn) Column(org.hibernate.mapping.Column) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer)

Aggregations

ObjectNameNormalizer (org.hibernate.boot.model.naming.ObjectNameNormalizer)8 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)3 Database (org.hibernate.boot.model.relational.Database)3 Identifier (org.hibernate.boot.model.naming.Identifier)2 ImplicitBasicColumnNameSource (org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource)2 PhysicalNamingStrategy (org.hibernate.boot.model.naming.PhysicalNamingStrategy)2 Column (org.hibernate.mapping.Column)2 Properties (java.util.Properties)1 JoinColumn (javax.persistence.JoinColumn)1 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)1 AnnotationException (org.hibernate.AnnotationException)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 AttributePath (org.hibernate.boot.model.source.spi.AttributePath)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 SequenceStyleGenerator (org.hibernate.id.enhanced.SequenceStyleGenerator)1 MetadataBuildingContextTestingImpl (org.hibernate.testing.boot.MetadataBuildingContextTestingImpl)1 Before (org.junit.Before)1