Search in sources :

Example 1 with Identifier

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

the class InFlightMetadataCollectorImpl method addTableNameBinding.

@Override
public void addTableNameBinding(String schema, String catalog, String logicalName, String realTableName, Table denormalizedSuperTable) {
    final Identifier logicalNameIdentifier = getDatabase().toIdentifier(logicalName);
    final Identifier physicalNameIdentifier = getDatabase().toIdentifier(realTableName);
    logicalToPhysicalTableNameMap.put(logicalNameIdentifier, physicalNameIdentifier);
    physicalToLogicalTableNameMap.put(physicalNameIdentifier, logicalNameIdentifier);
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier)

Example 2 with Identifier

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

the class InFlightMetadataCollectorImpl method addDenormalizedTable.

@Override
public Table addDenormalizedTable(String schemaName, String catalogName, String name, boolean isAbstract, String subselectFragment, Table includedTable) throws DuplicateMappingException {
    final Namespace namespace = getDatabase().locateNamespace(getDatabase().toIdentifier(catalogName), getDatabase().toIdentifier(schemaName));
    // annotation binding depends on the "table name" for @Subselect bindings
    // being set into the generated table (mainly to avoid later NPE), but for now we need to keep that :(
    final Identifier logicalName;
    if (name != null) {
        logicalName = getDatabase().toIdentifier(name);
    } else {
        logicalName = null;
    }
    if (subselectFragment != null) {
        return new DenormalizedTable(namespace, logicalName, subselectFragment, isAbstract, includedTable);
    } else {
        Table table = namespace.locateTable(logicalName);
        if (table != null) {
            throw new DuplicateMappingException(DuplicateMappingException.Type.TABLE, logicalName.toString());
        } else {
            table = namespace.createDenormalizedTable(logicalName, isAbstract, includedTable);
        }
        return table;
    }
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) Table(org.hibernate.mapping.Table) DuplicateMappingException(org.hibernate.DuplicateMappingException) Namespace(org.hibernate.boot.model.relational.Namespace)

Example 3 with Identifier

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

the class InFlightMetadataCollectorImpl method getLogicalColumnName.

@Override
public String getLogicalColumnName(Table table, Identifier physicalName) throws MappingException {
    final String physicalNameString = physicalName.render(getDatabase().getJdbcEnvironment().getDialect());
    Identifier logicalName = null;
    Table currentTable = table;
    while (currentTable != null) {
        final TableColumnNameBinding binding = columnNameBindingByTableMap.get(currentTable);
        if (binding != null) {
            logicalName = binding.physicalToLogical.get(physicalNameString);
            if (logicalName != null) {
                break;
            }
        }
        if (DenormalizedTable.class.isInstance(currentTable)) {
            currentTable = ((DenormalizedTable) currentTable).getIncludedTable();
        } else {
            currentTable = null;
        }
    }
    if (logicalName == null) {
        throw new MappingException("Unable to find column with physical name " + physicalNameString + " in table " + table.getName());
    }
    return logicalName.render();
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) Table(org.hibernate.mapping.Table) DuplicateMappingException(org.hibernate.DuplicateMappingException) MappingException(org.hibernate.MappingException)

Example 4 with Identifier

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

the class Namespace method createTable.

/**
	 * Creates a mapping Table instance.
	 *
	 * @param logicalTableName The logical table name
	 *
	 * @return the created table.
	 */
public Table createTable(Identifier logicalTableName, boolean isAbstract) {
    final Table existing = tables.get(logicalTableName);
    if (existing != null) {
        return existing;
    }
    final Identifier physicalTableName = database.getPhysicalNamingStrategy().toPhysicalTableName(logicalTableName, database.getJdbcEnvironment());
    Table table = new Table(this, physicalTableName, isAbstract);
    tables.put(logicalTableName, table);
    return table;
}
Also used : DenormalizedTable(org.hibernate.mapping.DenormalizedTable) Table(org.hibernate.mapping.Table) Identifier(org.hibernate.boot.model.naming.Identifier)

Example 5 with Identifier

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

the class ModelBinder method bindSecondaryTable.

private void bindSecondaryTable(MappingDocument mappingDocument, SecondaryTableSource secondaryTableSource, Join secondaryTableJoin, final EntityTableXref entityTableXref) {
    final PersistentClass persistentClass = secondaryTableJoin.getPersistentClass();
    final Identifier catalogName = determineCatalogName(secondaryTableSource.getTableSource());
    final Identifier schemaName = determineSchemaName(secondaryTableSource.getTableSource());
    final Namespace namespace = database.locateNamespace(catalogName, schemaName);
    Table secondaryTable;
    final Identifier logicalTableName;
    if (TableSource.class.isInstance(secondaryTableSource.getTableSource())) {
        final TableSource tableSource = (TableSource) secondaryTableSource.getTableSource();
        logicalTableName = database.toIdentifier(tableSource.getExplicitTableName());
        secondaryTable = namespace.locateTable(logicalTableName);
        if (secondaryTable == null) {
            secondaryTable = namespace.createTable(logicalTableName, false);
        } else {
            secondaryTable.setAbstract(false);
        }
        secondaryTable.setComment(tableSource.getComment());
    } else {
        final InLineViewSource inLineViewSource = (InLineViewSource) secondaryTableSource.getTableSource();
        secondaryTable = new Table(namespace, inLineViewSource.getSelectStatement(), false);
        logicalTableName = Identifier.toIdentifier(inLineViewSource.getLogicalName());
    }
    secondaryTableJoin.setTable(secondaryTable);
    entityTableXref.addSecondaryTable(mappingDocument, logicalTableName, secondaryTableJoin);
    bindCustomSql(mappingDocument, secondaryTableSource, secondaryTableJoin);
    secondaryTableJoin.setSequentialSelect(secondaryTableSource.getFetchStyle() == FetchStyle.SELECT);
    secondaryTableJoin.setInverse(secondaryTableSource.isInverse());
    secondaryTableJoin.setOptional(secondaryTableSource.isOptional());
    if (log.isDebugEnabled()) {
        log.debugf("Mapping entity secondary-table: %s -> %s", persistentClass.getEntityName(), secondaryTable.getName());
    }
    final SimpleValue keyBinding = new DependantValue(mappingDocument.getMetadataCollector(), secondaryTable, persistentClass.getIdentifier());
    if (mappingDocument.getBuildingOptions().useNationalizedCharacterData()) {
        keyBinding.makeNationalized();
    }
    secondaryTableJoin.setKey(keyBinding);
    keyBinding.setCascadeDeleteEnabled(secondaryTableSource.isCascadeDeleteEnabled());
    // NOTE : no Type info to bind...
    relationalObjectBinder.bindColumns(mappingDocument, secondaryTableSource.getPrimaryKeyColumnSources(), keyBinding, secondaryTableSource.isOptional(), new RelationalObjectBinder.ColumnNamingDelegate() {

        int count = 0;

        @Override
        public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
            final Column correspondingColumn = entityTableXref.getPrimaryTable().getPrimaryKey().getColumn(count++);
            return database.toIdentifier(correspondingColumn.getQuotedName());
        }
    });
    keyBinding.setForeignKeyName(secondaryTableSource.getExplicitForeignKeyName());
    // skip creating primary and foreign keys for a subselect.
    if (secondaryTable.getSubselect() == null) {
        secondaryTableJoin.createPrimaryKey();
        secondaryTableJoin.createForeignKey();
    }
}
Also used : Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) DependantValue(org.hibernate.mapping.DependantValue) InLineViewSource(org.hibernate.boot.model.source.spi.InLineViewSource) Namespace(org.hibernate.boot.model.relational.Namespace) SimpleValue(org.hibernate.mapping.SimpleValue) Identifier(org.hibernate.boot.model.naming.Identifier) TableSource(org.hibernate.boot.model.source.spi.TableSource) SecondaryTableSource(org.hibernate.boot.model.source.spi.SecondaryTableSource) Column(org.hibernate.mapping.Column) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) PersistentClass(org.hibernate.mapping.PersistentClass)

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