From cf4ef9ad1cde4f3750d72abc75ae5b13af6a7e26 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 15 Oct 2015 18:08:51 +0100 Subject: [PATCH] HHH-10197 - Fix SchemaManagementException when performing SchemaUpdate --- .../boot/model/naming/DatabaseIdentifier.java | 32 +++++++++++++++++++ .../NormalizingIdentifierHelperImpl.java | 5 +++ ...tionExtractorJdbcDatabaseMetaDataImpl.java | 12 ++++--- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/model/naming/DatabaseIdentifier.java 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 ); } }