HHH-10197 - Fix SchemaManagementException when performing SchemaUpdate

This commit is contained in:
Andrea Boriero 2015-10-15 18:08:51 +01:00
parent dc902bb0a3
commit d44cb40c34
3 changed files with 44 additions and 5 deletions

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 );
}
}

View File

@ -10,6 +10,7 @@ import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.hibernate.boot.model.naming.DatabaseIdentifier;
import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy; import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; 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" ); throw new IllegalArgumentException( "Identifier cannot be null; bad usage" );
} }
if ( identifier instanceof DatabaseIdentifier ) {
return identifier.getText();
}
if ( identifier.isQuoted() ) { if ( identifier.isQuoted() ) {
switch ( quotedCaseStrategy ) { switch ( quotedCaseStrategy ) {
case UPPER: { case UPPER: {

View File

@ -18,6 +18,7 @@ import java.util.StringTokenizer;
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.hibernate.boot.model.TruthValue; 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.naming.Identifier;
import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
@ -647,6 +648,7 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
return fks; return fks;
} }
private ForeignKeyBuilder generateForeignKeyBuilder(Identifier fkIdentifier) { private ForeignKeyBuilder generateForeignKeyBuilder(Identifier fkIdentifier) {
return new ForeignKeyBuilderImpl( fkIdentifier ); return new ForeignKeyBuilderImpl( fkIdentifier );
} }
@ -688,10 +690,10 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
final String incomingSchemaName = resultSet.getString( prefix + "TABLE_SCHEM" ); final String incomingSchemaName = resultSet.getString( prefix + "TABLE_SCHEM" );
final String incomingTableName = resultSet.getString( prefix + "TABLE_NAME" ); final String incomingTableName = resultSet.getString( prefix + "TABLE_NAME" );
return new QualifiedTableName( final DatabaseIdentifier catalog = DatabaseIdentifier.toIdentifier( incomingCatalogName );
identifierHelper().toIdentifier( incomingCatalogName ), final DatabaseIdentifier schema = DatabaseIdentifier.toIdentifier( incomingSchemaName );
identifierHelper().toIdentifier( incomingSchemaName ), final DatabaseIdentifier table = DatabaseIdentifier.toIdentifier( incomingTableName );
identifierHelper().toIdentifier( incomingTableName )
); return new QualifiedTableName( catalog, schema, table );
} }
} }