HHH-14922 Give precedence to default catalog/schema over implicit catalog/schema

This commit is contained in:
Yoann Rodière 2021-11-10 09:57:31 +01:00
parent 30e3aa4e7f
commit 37d3b66ce4
3 changed files with 15 additions and 13 deletions

View File

@ -41,8 +41,8 @@ public class SqlStringGenerationContextImpl
/** /**
* @param jdbcEnvironment The JDBC environment, to extract the dialect, identifier helper, etc. * @param jdbcEnvironment The JDBC environment, to extract the dialect, identifier helper, etc.
* @param database The database metadata, to retrieve the implicit namespace name configured through XML mapping. * @param database The database metadata, to retrieve the implicit namespace name configured through XML mapping.
* @param defaultCatalog The default catalog to use, unless an implicit catalog was configured through XML mapping. * @param defaultCatalog The default catalog to use; if {@code null}, will use the implicit catalog that was configured through XML mapping.
* @param defaultSchema The default schema to use, unless an implicit schema was configured through XML mapping. * @param defaultSchema The default schema to use; if {@code null}, will use the implicit schema that was configured through XML mapping.
* @return An {@link SqlStringGenerationContext}. * @return An {@link SqlStringGenerationContext}.
*/ */
public static SqlStringGenerationContext fromExplicit(JdbcEnvironment jdbcEnvironment, public static SqlStringGenerationContext fromExplicit(JdbcEnvironment jdbcEnvironment,
@ -52,15 +52,17 @@ public class SqlStringGenerationContextImpl
NameQualifierSupport nameQualifierSupport = jdbcEnvironment.getNameQualifierSupport(); NameQualifierSupport nameQualifierSupport = jdbcEnvironment.getNameQualifierSupport();
Identifier actualDefaultCatalog = null; Identifier actualDefaultCatalog = null;
if ( nameQualifierSupport.supportsCatalogs() ) { if ( nameQualifierSupport.supportsCatalogs() ) {
actualDefaultCatalog = implicitNamespaceName.getCatalog() != null actualDefaultCatalog = identifierHelper.toIdentifier( defaultCatalog );
? implicitNamespaceName.getCatalog() if ( actualDefaultCatalog == null ) {
: identifierHelper.toIdentifier( defaultCatalog ); actualDefaultCatalog = implicitNamespaceName.getCatalog();
}
} }
Identifier actualDefaultSchema = null; Identifier actualDefaultSchema = null;
if ( nameQualifierSupport.supportsSchemas() ) { if ( nameQualifierSupport.supportsSchemas() ) {
actualDefaultSchema = implicitNamespaceName.getSchema() != null actualDefaultSchema = identifierHelper.toIdentifier( defaultSchema );
? implicitNamespaceName.getSchema() if ( defaultSchema == null ) {
: identifierHelper.toIdentifier( defaultSchema ); actualDefaultSchema = implicitNamespaceName.getSchema();
}
} }
return new SqlStringGenerationContextImpl( jdbcEnvironment, actualDefaultCatalog, actualDefaultSchema ); return new SqlStringGenerationContextImpl( jdbcEnvironment, actualDefaultCatalog, actualDefaultSchema );
} }

View File

@ -58,8 +58,8 @@ public final class Settings {
public Settings(SessionFactoryOptions sessionFactoryOptions, String defaultCatalogName, String defaultSchemaName) { public Settings(SessionFactoryOptions sessionFactoryOptions, String defaultCatalogName, String defaultSchemaName) {
this.sessionFactoryOptions = sessionFactoryOptions; this.sessionFactoryOptions = sessionFactoryOptions;
this.defaultCatalogName = defaultCatalogName != null ? defaultCatalogName : sessionFactoryOptions.getDefaultCatalog(); this.defaultCatalogName = sessionFactoryOptions.getDefaultCatalog() != null ? sessionFactoryOptions.getDefaultCatalog() : defaultCatalogName;
this.defaultSchemaName = defaultSchemaName != null ? defaultSchemaName : sessionFactoryOptions.getDefaultSchema(); this.defaultSchemaName = sessionFactoryOptions.getDefaultSchema() != null ? sessionFactoryOptions.getDefaultSchema() : defaultSchemaName;
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( "SessionFactory name : %s", sessionFactoryOptions.getSessionFactoryName() ); LOG.debugf( "SessionFactory name : %s", sessionFactoryOptions.getSessionFactoryName() );

View File

@ -129,9 +129,9 @@ public class DefaultCatalogAndSchemaTest {
// HHH-14922: Inconsistent precedence of orm.xml implicit catalog/schema over "default_catalog"/"default_schema" // HHH-14922: Inconsistent precedence of orm.xml implicit catalog/schema over "default_catalog"/"default_schema"
params.add( new Object[] { mode, "implicit-global-catalog-and-schema.orm.xml", params.add( new Object[] { mode, "implicit-global-catalog-and-schema.orm.xml",
"someDefaultCatalog", "someDefaultSchema", "someDefaultCatalog", "someDefaultSchema",
// The implicit catalog/schema defined in the mapping should take precedence // The default catalog/schema should replace the
// over the default catalog/schema defined in settings. // implicit catalog/schema defined in the mapping.
"someImplicitCatalog", "someImplicitSchema" } ); "someDefaultCatalog", "someDefaultSchema" } );
} }
return params; return params;
} }