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);
}
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;
}
}
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();
}
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;
}
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();
}
}
Aggregations