HHH-16255 Avoid confusing logs "Executing import script"

1. Only log this when we're actually executing the script, i.e. when
   the target is the database.
2. Log "Executing script" rather than "Executing import script" since
   sometimes we're executing a drop script
   ("jakarta.persistence.schema-generation.drop-script-source").
This commit is contained in:
Yoann Rodière 2023-03-27 16:15:32 +02:00 committed by Christian Beikov
parent e112eae4b8
commit 0c70c1ed68
11 changed files with 36 additions and 13 deletions

View File

@ -1650,8 +1650,8 @@ public interface CoreMessageLogger extends BasicLogger {
void logCannotLocateIndexColumnInformation(String columnIdentifierText, String indexIdentifierText);
@LogMessage(level = INFO)
@Message(value = "Executing import script '%s'", id = 476)
void executingImportScript(String scriptName);
@Message(value = "Executing script '%s'", id = 476)
void executingScript(String scriptName);
@LogMessage(level = INFO)
@Message(value = "Starting delayed evictData of schema as part of SessionFactory shut-down'", id = 477)

View File

@ -250,6 +250,9 @@ public class Helper {
final List<String> commands = scriptInput.extract(
reader -> commandExtractor.extractCommands( reader, dialect )
);
for ( GenerationTarget target : targets ) {
target.beforeScript( scriptInput );
}
for ( String command : commands ) {
applySqlString( command, formatter, options, targets );
}

View File

@ -22,18 +22,12 @@ import org.hibernate.tool.schema.spi.ScriptSourceInput;
*/
public abstract class AbstractScriptSourceInput implements ScriptSourceInput {
private static final CoreMessageLogger log = CoreLogging.messageLogger( SchemaCreatorImpl.class );
protected abstract String getScriptDescription();
protected abstract Reader prepareReader();
protected abstract void releaseReader(Reader reader);
@Override
public List<String> extract(Function<Reader, List<String>> extractor) {
log.executingImportScript( getScriptDescription() );
final Reader inputReader = prepareReader();
try {

View File

@ -6,7 +6,11 @@
*/
package org.hibernate.tool.schema.internal.exec;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
import org.hibernate.tool.schema.spi.SchemaManagementException;
import org.hibernate.tool.schema.spi.ScriptSourceInput;
/**
* Describes a schema generation target
@ -14,6 +18,7 @@ import org.hibernate.tool.schema.spi.SchemaManagementException;
* @author Steve Ebersole
*/
public interface GenerationTarget {
/**
* Prepare for accepting actions
*
@ -21,6 +26,16 @@ public interface GenerationTarget {
*/
void prepare();
/**
* Called just before a script is executed using one or more calls to {@link #accept(String)}.
* <p>
* May be used for logging in particular.
* @param scriptSource The source for the script that is about to be executed.
*/
default void beforeScript(ScriptSourceInput scriptSource) {
// Defaults to no-op
}
/**
* Accept a command
*

View File

@ -18,6 +18,7 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
import org.hibernate.tool.schema.spi.ScriptSourceInput;
/**
* A {@link GenerationTarget} which exports DDL directly to the database.
@ -63,6 +64,11 @@ public class GenerationTargetToDatabase implements GenerationTarget {
public void prepare() {
}
@Override
public void beforeScript(ScriptSourceInput scriptSource) {
log.executingScript( scriptSource.getScriptDescription() );
}
@Override
public void accept(String command) {
getSqlStatementLogger().logStatement( command, FormatStyle.NONE.getFormatter() );

View File

@ -47,7 +47,7 @@ public class ScriptSourceInputAggregate implements ScriptSourceInput {
final AbstractScriptSourceInput scriptSourceInput = inputs[i];
final Reader reader = scriptSourceInput.prepareReader();
try {
log.executingImportScript( scriptSourceInput.getScriptDescription() );
log.executingScript( scriptSourceInput.getScriptDescription() );
lists[i] = extractor.apply( reader );
size += lists[i].size();
}

View File

@ -40,7 +40,7 @@ public class ScriptSourceInputFromFile extends AbstractScriptSourceInput {
}
@Override
protected String getScriptDescription() {
public String getScriptDescription() {
return file.getAbsolutePath();
}

View File

@ -27,7 +27,7 @@ public class ScriptSourceInputFromReader extends AbstractScriptSourceInput {
}
@Override
protected String getScriptDescription() {
public String getScriptDescription() {
return "[injected ScriptSourceInputFromReader script]";
}

View File

@ -39,7 +39,7 @@ public class ScriptSourceInputFromUrl extends AbstractScriptSourceInput {
}
@Override
protected String getScriptDescription() {
public String getScriptDescription() {
return url.toExternalForm();
}

View File

@ -26,7 +26,7 @@ public class ScriptSourceInputNonExistentImpl extends AbstractScriptSourceInput
public static final ScriptSourceInputNonExistentImpl INSTANCE = new ScriptSourceInputNonExistentImpl();
@Override
protected String getScriptDescription() {
public String getScriptDescription() {
return "[injected ScriptSourceInputNonExistentImpl script]";
}

View File

@ -18,6 +18,11 @@ import java.util.function.Function;
* @author Steve Ebersole
*/
public interface ScriptSourceInput {
default String getScriptDescription() {
return toString();
}
/**
* Allows managed access to the input's Reader, returning a result
*/