HHH-15717 SQL script executed twice when using persistence.xml jakarta.persistence.sql-load-script-source property with the default sql script name
This commit is contained in:
parent
9720037963
commit
476da28da9
|
@ -524,8 +524,13 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
|||
}
|
||||
String charsetName = (String) options.getConfigurationValues().get( HBM2DDL_CHARSET_NAME );
|
||||
|
||||
boolean hasDefaultImportFileScriptBeenExecuted = false;
|
||||
if ( importScriptSetting != null ) {
|
||||
final ScriptSourceInput importScriptInput = interpretScriptSourceSetting( importScriptSetting, classLoaderService, charsetName );
|
||||
final URL defaultImportFileUrl = classLoaderService.locateResource( DEFAULT_IMPORT_FILE );
|
||||
if ( defaultImportFileUrl != null && importScriptInput.containsScript( defaultImportFileUrl ) ) {
|
||||
hasDefaultImportFileScriptBeenExecuted = true;
|
||||
}
|
||||
final List<String> commands = importScriptInput.extract(
|
||||
reader -> commandExtractor.extractCommands( reader, dialect )
|
||||
);
|
||||
|
@ -537,7 +542,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
|||
final String importFiles = ConfigurationHelper.getString(
|
||||
AvailableSettings.HBM2DDL_IMPORT_FILES,
|
||||
options.getConfigurationValues(),
|
||||
DEFAULT_IMPORT_FILE
|
||||
hasDefaultImportFileScriptBeenExecuted ? "" : DEFAULT_IMPORT_FILE
|
||||
);
|
||||
|
||||
for ( String currentFile : importFiles.split( "," ) ) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.tool.schema.internal.exec;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -62,6 +63,16 @@ public class ScriptSourceInputAggregate implements ScriptSourceInput {
|
|||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsScript(URL url) {
|
||||
for ( int i = 0; i < inputs.length; i++ ) {
|
||||
if ( inputs[i].containsScript( url ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScriptSourceInputAggregate(" + Arrays.toString( inputs ) + ")";
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
|
||||
import org.hibernate.tool.schema.spi.SchemaManagementException;
|
||||
|
||||
|
@ -86,6 +87,11 @@ public class ScriptSourceInputFromFile extends AbstractScriptSourceInput {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsScript(URL url) {
|
||||
return file.getAbsolutePath().equals( url.getPath() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScriptSourceInputFromFile(" + file.getAbsolutePath() + ")";
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.tool.schema.internal.exec;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* ScriptSourceInput implementation for explicitly given Readers.
|
||||
|
@ -40,6 +41,11 @@ public class ScriptSourceInputFromReader extends AbstractScriptSourceInput {
|
|||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsScript(URL url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScriptSourceInputFromReader()";
|
||||
|
|
|
@ -67,6 +67,11 @@ public class ScriptSourceInputFromUrl extends AbstractScriptSourceInput {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsScript(URL url) {
|
||||
return url.equals( url );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScriptSourceInputFromUrl(" + url.toExternalForm() + ")";
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.tool.schema.internal.exec;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
@ -39,6 +40,11 @@ public class ScriptSourceInputNonExistentImpl extends AbstractScriptSourceInput
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsScript(URL url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> extract(Function<Reader, List<String>> extractor) {
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.tool.schema.spi;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -21,4 +22,9 @@ public interface ScriptSourceInput {
|
|||
* Allows managed access to the input's Reader, returning a result
|
||||
*/
|
||||
List<String> extract(Function<Reader, List<String>> extractor);
|
||||
|
||||
default boolean containsScript(URL url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue