Search in sources :

Example 1 with ObjectNameSource

use of org.hibernate.cfg.ObjectNameSource 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)

Aggregations

EntityNaming (org.hibernate.boot.model.naming.EntityNaming)1 Identifier (org.hibernate.boot.model.naming.Identifier)1 ImplicitCollectionTableNameSource (org.hibernate.boot.model.naming.ImplicitCollectionTableNameSource)1 ImplicitJoinTableNameSource (org.hibernate.boot.model.naming.ImplicitJoinTableNameSource)1 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)1 NamingStrategyHelper (org.hibernate.boot.model.naming.NamingStrategyHelper)1 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)1 ObjectNameSource (org.hibernate.cfg.ObjectNameSource)1