Search in sources :

Example 11 with Identifier

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);
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 12 with Identifier

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());
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier) PluralAttributeElementSourceOneToMany(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceOneToMany) PluralAttributeSequentialIndexSource(org.hibernate.boot.model.source.spi.PluralAttributeSequentialIndexSource) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) ImplicitIndexColumnNameSource(org.hibernate.boot.model.naming.ImplicitIndexColumnNameSource) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 13 with Identifier

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);
}
Also used : NamingStrategyHelper(org.hibernate.boot.model.naming.NamingStrategyHelper) ImplicitCollectionTableNameSource(org.hibernate.boot.model.naming.ImplicitCollectionTableNameSource) Identifier(org.hibernate.boot.model.naming.Identifier) ObjectNameSource(org.hibernate.cfg.ObjectNameSource) ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) EntityNaming(org.hibernate.boot.model.naming.EntityNaming) ImplicitJoinTableNameSource(org.hibernate.boot.model.naming.ImplicitJoinTableNameSource) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext)

Example 14 with Identifier

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));
        }
    }
}
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 15 with Identifier

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());
}
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)46 Table (org.hibernate.mapping.Table)15 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)10 DenormalizedTable (org.hibernate.mapping.DenormalizedTable)9 SimpleValue (org.hibernate.mapping.SimpleValue)9 HashMap (java.util.HashMap)7 MappingException (org.hibernate.boot.MappingException)7 Namespace (org.hibernate.boot.model.relational.Namespace)7 Database (org.hibernate.boot.model.relational.Database)6 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)5 DatabaseIdentifier (org.hibernate.boot.model.naming.DatabaseIdentifier)5 Column (org.hibernate.mapping.Column)5 Property (org.hibernate.mapping.Property)5 HashSet (java.util.HashSet)4 DuplicateMappingException (org.hibernate.DuplicateMappingException)4 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)4 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)4 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)4