Skip to content

Commit

Permalink
HHH-19098 Disable implicit loading of the default import script
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 authored and yrodiere committed Feb 12, 2025
1 parent 1b13fd3 commit 287b920
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ public interface SchemaToolingSettings {
@Deprecated
String HBM2DDL_IMPORT_FILES = "hibernate.hbm2ddl.import_files";

/**
* Specifies if the default {@code /import.sql} script file should not be executed
* when {@link #HBM2DDL_IMPORT_FILES} is not specified and {@value #HBM2DDL_AUTO} is set to {@code create} or {@code create-drop}.
*
* The default value is {@code false}.
*/
String HBM2DDL_SKIP_DEFAULT_IMPORT_FILE = "hibernate.hbm2ddl.skip_default_import_file";

/**
* Specifies whether to automatically create also the database schema/catalog.
* The default is false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_IMPORT_FILES;
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE;
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_SKIP_DEFAULT_IMPORT_FILE;
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
import static org.hibernate.tool.schema.internal.Helper.applyScript;
import static org.hibernate.tool.schema.internal.Helper.applySqlStrings;
Expand Down Expand Up @@ -597,11 +599,24 @@ private void applyImportSources(
commandExtractor,
dialect,
formatter,
hasDefaultImportFileScriptBeenExecuted ? "" : DEFAULT_IMPORT_FILE,
hasDefaultImportFileScriptBeenExecuted ? "" : getDefaultImportFile( options ),
targets
);
}

private String getDefaultImportFile(ExecutionOptions options) {
if ( skipDefaultFileImport( options ) ) {
return "";
}
else {
return DEFAULT_IMPORT_FILE;
}
}

private static boolean skipDefaultFileImport(ExecutionOptions options) {
return getBoolean( HBM2DDL_SKIP_DEFAULT_IMPORT_FILE, options.getConfigurationValues(), false );
}

/**
* In principle, we should format the commands in the import script if the
* {@code format} parameter is {@code true}, and since it's supposed to be
Expand Down Expand Up @@ -642,16 +657,19 @@ private boolean applyImportScript(
formatter,
targets
);
return containsDefaultImportFile( importScriptInput );
return containsDefaultImportFile( importScriptInput, options );
}
else {
return false;
}
}

private boolean containsDefaultImportFile(ScriptSourceInput importScriptInput) {
private boolean containsDefaultImportFile(ScriptSourceInput importScriptInput,ExecutionOptions options ) {
if ( skipDefaultFileImport( options ) ) {
return false;
}
final URL defaultImportFileUrl = getClassLoaderService().locateResource( DEFAULT_IMPORT_FILE );
return defaultImportFileUrl != null && importScriptInput.containsScript(defaultImportFileUrl);
return defaultImportFileUrl != null && importScriptInput.containsScript( defaultImportFileUrl );
}

/**
Expand Down

0 comments on commit 287b920

Please sign in to comment.