diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/naming/DatabaseIdentifier.java b/hibernate-core/src/main/java/org/hibernate/boot/model/naming/DatabaseIdentifier.java new file mode 100644 index 0000000000..6f60bb8fb0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/naming/DatabaseIdentifier.java @@ -0,0 +1,32 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.boot.model.naming; + +import org.hibernate.internal.util.StringHelper; + +/** + * Models an identifier (name), retrieved from the database. + * + * @author Andrea Boriero + */ +public class DatabaseIdentifier extends Identifier { + /** + * Constructs a datatabase identifier instance. + * + * @param text The identifier text. + */ + public DatabaseIdentifier(String text) { + super( text, false ); + } + + public static DatabaseIdentifier toIdentifier(String text) { + if ( StringHelper.isEmpty( text ) ) { + return null; + } + return new DatabaseIdentifier( text ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/NormalizingIdentifierHelperImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/NormalizingIdentifierHelperImpl.java index 0b721af998..443c92dda1 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/NormalizingIdentifierHelperImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/NormalizingIdentifierHelperImpl.java @@ -10,6 +10,7 @@ import java.util.Locale; import java.util.Set; import java.util.TreeSet; +import org.hibernate.boot.model.naming.DatabaseIdentifier; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; @@ -122,6 +123,10 @@ public class NormalizingIdentifierHelperImpl implements IdentifierHelper { throw new IllegalArgumentException( "Identifier cannot be null; bad usage" ); } + if ( identifier instanceof DatabaseIdentifier ) { + return identifier.getText(); + } + if ( identifier.isQuoted() ) { switch ( quotedCaseStrategy ) { case UPPER: { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java index 9aaa25a7aa..74c4f8d08c 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java @@ -18,6 +18,7 @@ import java.util.StringTokenizer; import org.hibernate.JDBCException; import org.hibernate.boot.model.TruthValue; +import org.hibernate.boot.model.naming.DatabaseIdentifier; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.cfg.AvailableSettings; @@ -647,6 +648,7 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information return fks; } + private ForeignKeyBuilder generateForeignKeyBuilder(Identifier fkIdentifier) { return new ForeignKeyBuilderImpl( fkIdentifier ); } @@ -688,10 +690,10 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information final String incomingSchemaName = resultSet.getString( prefix + "TABLE_SCHEM" ); final String incomingTableName = resultSet.getString( prefix + "TABLE_NAME" ); - return new QualifiedTableName( - identifierHelper().toIdentifier( incomingCatalogName ), - identifierHelper().toIdentifier( incomingSchemaName ), - identifierHelper().toIdentifier( incomingTableName ) - ); + final DatabaseIdentifier catalog = DatabaseIdentifier.toIdentifier( incomingCatalogName ); + final DatabaseIdentifier schema = DatabaseIdentifier.toIdentifier( incomingSchemaName ); + final DatabaseIdentifier table = DatabaseIdentifier.toIdentifier( incomingTableName ); + + return new QualifiedTableName( catalog, schema, table ); } }