HHH-15212 Fix SimpleAuxiliaryDatabaseObject ignoring the default catalog/schema set through configuration properties

This commit is contained in:
Yoann Rodière 2022-04-27 11:28:00 +02:00
parent eab669f04e
commit d28e300013
3 changed files with 28 additions and 5 deletions

View File

@ -78,7 +78,7 @@ public SimpleAuxiliaryDatabaseObject(
public String[] sqlCreateStrings(SqlStringGenerationContext context) {
final String[] copy = new String[createStrings.length];
for ( int i = 0, max =createStrings.length; i<max; i++ ) {
copy[i] = injectCatalogAndSchema( createStrings[i] );
copy[i] = injectCatalogAndSchema( createStrings[i], context );
}
return copy;
}
@ -87,7 +87,7 @@ public String[] sqlCreateStrings(SqlStringGenerationContext context) {
public String[] sqlDropStrings(SqlStringGenerationContext context) {
final String[] copy = new String[dropStrings.length];
for ( int i = 0, max = dropStrings.length; i<max; i++ ) {
copy[i] = injectCatalogAndSchema( dropStrings[i] );
copy[i] = injectCatalogAndSchema( dropStrings[i], context );
}
return copy;
}
@ -100,9 +100,11 @@ protected String getSchemaName() {
return schemaName;
}
private String injectCatalogAndSchema(String ddlString) {
String rtn = StringHelper.replace( ddlString, CATALOG_NAME_PLACEHOLDER, catalogName == null ? "" : catalogName );
rtn = StringHelper.replace( rtn, SCHEMA_NAME_PLACEHOLDER, schemaName == null ? "" : schemaName );
private String injectCatalogAndSchema(String ddlString, SqlStringGenerationContext context) {
Identifier defaultedCatalogName = context.catalogWithDefault( catalogName == null ? null : context.toIdentifier( catalogName ) );
Identifier defaultedSchemaName = context.schemaWithDefault( schemaName == null ? null : context.toIdentifier( schemaName ) );
String rtn = StringHelper.replace( ddlString, CATALOG_NAME_PLACEHOLDER, defaultedCatalogName == null ? "" : defaultedCatalogName.getText() );
rtn = StringHelper.replace( rtn, SCHEMA_NAME_PLACEHOLDER, defaultedSchemaName == null ? "" : defaultedSchemaName.getText() );
return rtn;
}
}

View File

@ -25,9 +25,25 @@ public interface SqlStringGenerationContext {
* @return The helper for dealing with identifiers in the current JDBC environment.
* <p>
* Note that the Identifiers returned from this helper already account for auto-quoting.
*
* @deprecated Use {@link #toIdentifier(String)} instead.
*/
@Deprecated
IdentifierHelper getIdentifierHelper();
/**
* Generate an Identifier instance from its simple name as obtained from mapping
* information.
* <p/>
* Note that Identifiers returned from here may be implicitly quoted based on
* 'globally quoted identifiers' or based on reserved words.
*
* @param text The text form of a name as obtained from mapping information.
*
* @return The identifier form of the name.
*/
Identifier toIdentifier(String text);
/**
* @return The default catalog, used for table/sequence names that do not explicitly mention a catalog.
* May be {@code null}.

View File

@ -114,6 +114,11 @@ public IdentifierHelper getIdentifierHelper() {
return identifierHelper;
}
@Override
public Identifier toIdentifier(String text) {
return identifierHelper != null ? identifierHelper.toIdentifier( text ) : Identifier.toIdentifier( text );
}
@Override
public Identifier getDefaultCatalog() {
return defaultCatalog;