HHH-16255 De-duplicate a few methods from SchemaCreatorImpl/SchemaDropperImpl/SchemaTruncatorImpl
This commit is contained in:
parent
d99889359d
commit
943fd55ba2
|
@ -11,21 +11,29 @@ import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.model.relational.Database;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
|
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
|
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
|
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl;
|
import org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl;
|
||||||
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
|
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
|
||||||
import org.hibernate.tool.schema.internal.exec.AbstractScriptSourceInput;
|
import org.hibernate.tool.schema.internal.exec.AbstractScriptSourceInput;
|
||||||
|
import org.hibernate.tool.schema.internal.exec.GenerationTarget;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputAggregate;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputAggregate;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromFile;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromFile;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromReader;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromReader;
|
||||||
|
@ -33,9 +41,12 @@ import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile;
|
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToUrl;
|
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToUrl;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter;
|
import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter;
|
||||||
|
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
||||||
|
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
||||||
import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
||||||
import org.hibernate.tool.schema.spi.ScriptSourceInput;
|
import org.hibernate.tool.schema.spi.ScriptSourceInput;
|
||||||
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
|
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
|
||||||
|
import org.hibernate.tool.schema.spi.SqlScriptCommandExtractor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper methods.
|
* Helper methods.
|
||||||
|
@ -185,4 +196,62 @@ public class Helper {
|
||||||
throw jdbcEnvironment.getSqlExceptionHelper().convert( e, "Unable to build DatabaseInformation" );
|
throw jdbcEnvironment.getSqlExceptionHelper().convert( e, "Unable to build DatabaseInformation" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SqlStringGenerationContext createSqlStringGenerationContext(ExecutionOptions options, Metadata metadata) {
|
||||||
|
final Database database = metadata.getDatabase();
|
||||||
|
return SqlStringGenerationContextImpl.fromConfigurationMap(
|
||||||
|
database.getJdbcEnvironment(),
|
||||||
|
database,
|
||||||
|
options.getConfigurationValues()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void applySqlStrings(
|
||||||
|
String[] sqlStrings,
|
||||||
|
Formatter formatter,
|
||||||
|
ExecutionOptions options,
|
||||||
|
GenerationTarget... targets) {
|
||||||
|
if ( sqlStrings == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( String sqlString : sqlStrings ) {
|
||||||
|
applySqlString( sqlString, formatter, options, targets );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void applySqlString(
|
||||||
|
String sqlString,
|
||||||
|
Formatter formatter,
|
||||||
|
ExecutionOptions options,
|
||||||
|
GenerationTarget... targets) {
|
||||||
|
if ( StringHelper.isEmpty( sqlString ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sqlStringFormatted = formatter.format( sqlString );
|
||||||
|
for ( GenerationTarget target : targets ) {
|
||||||
|
try {
|
||||||
|
target.accept( sqlStringFormatted );
|
||||||
|
}
|
||||||
|
catch (CommandAcceptanceException e) {
|
||||||
|
options.getExceptionHandler().handleException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void applyScript(
|
||||||
|
ExecutionOptions options,
|
||||||
|
SqlScriptCommandExtractor commandExtractor,
|
||||||
|
Dialect dialect,
|
||||||
|
ScriptSourceInput scriptInput,
|
||||||
|
Formatter formatter,
|
||||||
|
GenerationTarget[] targets) {
|
||||||
|
final List<String> commands = scriptInput.extract(
|
||||||
|
reader -> commandExtractor.extractCommands( reader, dialect )
|
||||||
|
);
|
||||||
|
for ( String command : commands ) {
|
||||||
|
applySqlString( command, formatter, options, targets );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,11 @@ import org.hibernate.Internal;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.boot.model.relational.Database;
|
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.InitCommand;
|
import org.hibernate.boot.model.relational.InitCommand;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.Sequence;
|
import org.hibernate.boot.model.relational.Sequence;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
@ -46,7 +44,6 @@ import org.hibernate.tool.schema.internal.exec.GenerationTarget;
|
||||||
import org.hibernate.tool.schema.internal.exec.JdbcContext;
|
import org.hibernate.tool.schema.internal.exec.JdbcContext;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl;
|
||||||
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
|
||||||
import org.hibernate.tool.schema.spi.ContributableMatcher;
|
import org.hibernate.tool.schema.spi.ContributableMatcher;
|
||||||
import org.hibernate.tool.schema.spi.ExceptionHandler;
|
import org.hibernate.tool.schema.spi.ExceptionHandler;
|
||||||
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
||||||
|
@ -63,9 +60,11 @@ import static org.hibernate.cfg.AvailableSettings.HBM2DDL_CHARSET_NAME;
|
||||||
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_IMPORT_FILES;
|
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.HBM2DDL_LOAD_SCRIPT_SOURCE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE;
|
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE;
|
||||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
|
||||||
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
|
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
|
||||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
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;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.createSqlStringGenerationContext;
|
||||||
import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled;
|
import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled;
|
||||||
import static org.hibernate.tool.schema.internal.Helper.interpretScriptSourceSetting;
|
import static org.hibernate.tool.schema.internal.Helper.interpretScriptSourceSetting;
|
||||||
|
|
||||||
|
@ -200,12 +199,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
Dialect dialect,
|
Dialect dialect,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
final List<String> commands = scriptSourceInput.extract(
|
applyScript( options, commandExtractor, dialect, scriptSourceInput, formatter, targets );
|
||||||
reader -> commandExtractor.extractCommands( reader, dialect )
|
|
||||||
);
|
|
||||||
for ( String command : commands ) {
|
|
||||||
applySqlString( command, formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
|
@ -225,15 +219,6 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SqlStringGenerationContext createSqlStringGenerationContext(ExecutionOptions options, Metadata metadata) {
|
|
||||||
final Database database = metadata.getDatabase();
|
|
||||||
return SqlStringGenerationContextImpl.fromConfigurationMap(
|
|
||||||
database.getJdbcEnvironment(),
|
|
||||||
database,
|
|
||||||
options.getConfigurationValues()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public void createFromMetadata(
|
public void createFromMetadata(
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
|
@ -565,36 +550,6 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
exportIdentifiers.add( exportIdentifier );
|
exportIdentifiers.add( exportIdentifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applySqlStrings(
|
|
||||||
String[] sqlStrings,
|
|
||||||
Formatter formatter,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
if ( sqlStrings != null ) {
|
|
||||||
for ( String sqlString : sqlStrings ) {
|
|
||||||
applySqlString( sqlString, formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void applySqlString(
|
|
||||||
String sqlString,
|
|
||||||
Formatter formatter,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
if ( isNotEmpty( sqlString ) ) {
|
|
||||||
try {
|
|
||||||
final String sqlStringFormatted = formatter.format( sqlString );
|
|
||||||
for ( GenerationTarget target : targets ) {
|
|
||||||
target.accept( sqlStringFormatted );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (CommandAcceptanceException e) {
|
|
||||||
options.getExceptionHandler().handleException( e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyImportSources(
|
private void applyImportSources(
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
SqlScriptCommandExtractor commandExtractor,
|
SqlScriptCommandExtractor commandExtractor,
|
||||||
|
@ -653,7 +608,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
if ( importScriptSetting != null ) {
|
if ( importScriptSetting != null ) {
|
||||||
final ScriptSourceInput importScriptInput =
|
final ScriptSourceInput importScriptInput =
|
||||||
interpretScriptSourceSetting( importScriptSetting, getClassLoaderService(), getCharsetName( options ) );
|
interpretScriptSourceSetting( importScriptSetting, getClassLoaderService(), getCharsetName( options ) );
|
||||||
applyImportScript(
|
applyScript(
|
||||||
options,
|
options,
|
||||||
commandExtractor,
|
commandExtractor,
|
||||||
dialect,
|
dialect,
|
||||||
|
@ -692,7 +647,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
for ( String currentFile : importFiles ) {
|
for ( String currentFile : importFiles ) {
|
||||||
final String resourceName = currentFile.trim();
|
final String resourceName = currentFile.trim();
|
||||||
if ( !resourceName.isEmpty() ) { //skip empty resource names
|
if ( !resourceName.isEmpty() ) { //skip empty resource names
|
||||||
applyImportScript(
|
applyScript(
|
||||||
options,
|
options,
|
||||||
commandExtractor,
|
commandExtractor,
|
||||||
dialect,
|
dialect,
|
||||||
|
@ -704,21 +659,6 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyImportScript(
|
|
||||||
ExecutionOptions options,
|
|
||||||
SqlScriptCommandExtractor commandExtractor,
|
|
||||||
Dialect dialect,
|
|
||||||
ScriptSourceInput importScriptInput,
|
|
||||||
Formatter formatter,
|
|
||||||
GenerationTarget[] targets) {
|
|
||||||
final List<String> commands = importScriptInput.extract(
|
|
||||||
reader -> commandExtractor.extractCommands( reader, dialect )
|
|
||||||
);
|
|
||||||
for ( String command : commands ) {
|
|
||||||
applySqlString( command, formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ScriptSourceInput interpretLegacyImportScriptSetting(
|
private ScriptSourceInput interpretLegacyImportScriptSetting(
|
||||||
String resourceName,
|
String resourceName,
|
||||||
ClassLoaderService classLoaderService,
|
ClassLoaderService classLoaderService,
|
||||||
|
|
|
@ -19,12 +19,10 @@ import org.hibernate.Internal;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.boot.model.relational.Database;
|
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.Sequence;
|
import org.hibernate.boot.model.relational.Sequence;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
@ -63,8 +61,10 @@ import org.hibernate.tool.schema.spi.TargetDescriptor;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
|
||||||
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
|
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.applyScript;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.applySqlStrings;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.createSqlStringGenerationContext;
|
||||||
import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled;
|
import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,17 +179,17 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
|
|
||||||
switch ( sourceDescriptor.getSourceType() ) {
|
switch ( sourceDescriptor.getSourceType() ) {
|
||||||
case SCRIPT:
|
case SCRIPT:
|
||||||
dropFromScript( sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, dialect, options, targets );
|
applyScript( options, commandExtractor, dialect, sourceDescriptor.getScriptSourceInput(), formatter, targets );
|
||||||
break;
|
break;
|
||||||
case METADATA:
|
case METADATA:
|
||||||
dropFromMetadata( metadata, options, inclusionFilter, dialect, formatter, targets );
|
dropFromMetadata( metadata, options, inclusionFilter, dialect, formatter, targets );
|
||||||
break;
|
break;
|
||||||
case METADATA_THEN_SCRIPT:
|
case METADATA_THEN_SCRIPT:
|
||||||
dropFromMetadata( metadata, options, inclusionFilter, dialect, formatter, targets );
|
dropFromMetadata( metadata, options, inclusionFilter, dialect, formatter, targets );
|
||||||
dropFromScript( sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, dialect, options, targets );
|
applyScript( options, commandExtractor, dialect, sourceDescriptor.getScriptSourceInput(), formatter, targets );
|
||||||
break;
|
break;
|
||||||
case SCRIPT_THEN_METADATA:
|
case SCRIPT_THEN_METADATA:
|
||||||
dropFromScript( sourceDescriptor.getScriptSourceInput(), commandExtractor, formatter, dialect, options, targets );
|
applyScript( options, commandExtractor, dialect, sourceDescriptor.getScriptSourceInput(), formatter, targets );
|
||||||
dropFromMetadata( metadata, options, inclusionFilter, dialect, formatter, targets );
|
dropFromMetadata( metadata, options, inclusionFilter, dialect, formatter, targets );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -199,30 +199,6 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
return tool.getServiceRegistry().getService(SqlScriptCommandExtractor.class);
|
return tool.getServiceRegistry().getService(SqlScriptCommandExtractor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropFromScript(
|
|
||||||
ScriptSourceInput scriptSourceInput,
|
|
||||||
SqlScriptCommandExtractor commandExtractor,
|
|
||||||
Formatter formatter,
|
|
||||||
Dialect dialect,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
final List<String> commands = scriptSourceInput.extract(
|
|
||||||
reader -> commandExtractor.extractCommands( reader, dialect )
|
|
||||||
);
|
|
||||||
for ( String command : commands ) {
|
|
||||||
applySqlString( command, formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SqlStringGenerationContext createSqlStringGenerationContext(ExecutionOptions options, Metadata metadata) {
|
|
||||||
final Database database = metadata.getDatabase();
|
|
||||||
return SqlStringGenerationContextImpl.fromConfigurationMap(
|
|
||||||
database.getJdbcEnvironment(),
|
|
||||||
database,
|
|
||||||
options.getConfigurationValues()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dropFromMetadata(
|
private void dropFromMetadata(
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
ExecutionOptions options,
|
ExecutionOptions options,
|
||||||
|
@ -496,36 +472,6 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
exportIdentifiers.add( exportIdentifier );
|
exportIdentifiers.add( exportIdentifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applySqlStrings(
|
|
||||||
String[] sqlStrings,
|
|
||||||
Formatter formatter,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
if ( sqlStrings != null ) {
|
|
||||||
for ( String sqlString : sqlStrings ) {
|
|
||||||
applySqlString( sqlString, formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void applySqlString(
|
|
||||||
String sqlString,
|
|
||||||
Formatter formatter,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
if ( isNotEmpty( sqlString ) ) {
|
|
||||||
final String sqlStringFormatted = formatter.format( sqlString );
|
|
||||||
for ( GenerationTarget target : targets ) {
|
|
||||||
try {
|
|
||||||
target.accept( sqlStringFormatted );
|
|
||||||
}
|
|
||||||
catch (CommandAcceptanceException e) {
|
|
||||||
options.getExceptionHandler().handleException( e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DelayedDropAction buildDelayedAction(
|
public DelayedDropAction buildDelayedAction(
|
||||||
Metadata metadata,
|
Metadata metadata,
|
||||||
|
|
|
@ -11,13 +11,11 @@ import org.hibernate.boot.model.relational.Database;
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.internal.FormatStyle;
|
import org.hibernate.engine.jdbc.internal.FormatStyle;
|
||||||
import org.hibernate.engine.jdbc.internal.Formatter;
|
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.mapping.ForeignKey;
|
import org.hibernate.mapping.ForeignKey;
|
||||||
|
@ -27,7 +25,6 @@ import org.hibernate.tool.schema.internal.exec.GenerationTarget;
|
||||||
import org.hibernate.tool.schema.internal.exec.JdbcContext;
|
import org.hibernate.tool.schema.internal.exec.JdbcContext;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl;
|
||||||
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl;
|
import org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl;
|
||||||
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
|
||||||
import org.hibernate.tool.schema.spi.ContributableMatcher;
|
import org.hibernate.tool.schema.spi.ContributableMatcher;
|
||||||
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
import org.hibernate.tool.schema.spi.ExecutionOptions;
|
||||||
import org.hibernate.tool.schema.spi.SchemaFilter;
|
import org.hibernate.tool.schema.spi.SchemaFilter;
|
||||||
|
@ -46,6 +43,10 @@ import java.util.Set;
|
||||||
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_CHARSET_NAME;
|
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_CHARSET_NAME;
|
||||||
import static org.hibernate.cfg.AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE;
|
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.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.applyScript;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.applySqlString;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.applySqlStrings;
|
||||||
|
import static org.hibernate.tool.schema.internal.Helper.createSqlStringGenerationContext;
|
||||||
import static org.hibernate.tool.schema.internal.Helper.interpretScriptSourceSetting;
|
import static org.hibernate.tool.schema.internal.Helper.interpretScriptSourceSetting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,9 +122,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
|
||||||
Formatter formatter,
|
Formatter formatter,
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
final Database database = metadata.getDatabase();
|
final Database database = metadata.getDatabase();
|
||||||
SqlStringGenerationContext context = SqlStringGenerationContextImpl.fromConfigurationMap(
|
SqlStringGenerationContext context = createSqlStringGenerationContext( options, metadata );
|
||||||
metadata.getDatabase().getJdbcEnvironment(), database, options.getConfigurationValues() );
|
|
||||||
|
|
||||||
|
|
||||||
final Set<String> exportIdentifiers = CollectionHelper.setOfSize( 50 );
|
final Set<String> exportIdentifiers = CollectionHelper.setOfSize( 50 );
|
||||||
|
|
||||||
|
@ -281,40 +280,6 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
|
||||||
exportIdentifiers.add( exportIdentifier );
|
exportIdentifiers.add( exportIdentifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applySqlStrings(
|
|
||||||
String[] sqlStrings,
|
|
||||||
Formatter formatter,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
if ( sqlStrings == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( String sqlString : sqlStrings ) {
|
|
||||||
applySqlString( sqlString, formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void applySqlString(
|
|
||||||
String sqlString,
|
|
||||||
Formatter formatter,
|
|
||||||
ExecutionOptions options,
|
|
||||||
GenerationTarget... targets) {
|
|
||||||
if ( StringHelper.isEmpty( sqlString ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sqlStringFormatted = formatter.format( sqlString );
|
|
||||||
for ( GenerationTarget target : targets ) {
|
|
||||||
try {
|
|
||||||
target.accept( sqlStringFormatted );
|
|
||||||
}
|
|
||||||
catch (CommandAcceptanceException e) {
|
|
||||||
options.getExceptionHandler().handleException( e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Woooooo, massive copy/paste from SchemaCreatorImpl!
|
//Woooooo, massive copy/paste from SchemaCreatorImpl!
|
||||||
|
|
||||||
private void applyImportSources(
|
private void applyImportSources(
|
||||||
|
@ -339,12 +304,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
|
||||||
|
|
||||||
if ( importScriptSetting != null ) {
|
if ( importScriptSetting != null ) {
|
||||||
final ScriptSourceInput importScriptInput = interpretScriptSourceSetting( importScriptSetting, classLoaderService, charsetName );
|
final ScriptSourceInput importScriptInput = interpretScriptSourceSetting( importScriptSetting, classLoaderService, charsetName );
|
||||||
final List<String> commands = importScriptInput.extract(
|
applyScript( options, commandExtractor, dialect, importScriptInput, formatter, targets );
|
||||||
reader -> commandExtractor.extractCommands( reader, dialect )
|
|
||||||
);
|
|
||||||
for ( int i = 0; i < commands.size(); i++ ) {
|
|
||||||
applySqlString( commands.get( i ), formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String importFiles = ConfigurationHelper.getString(
|
final String importFiles = ConfigurationHelper.getString(
|
||||||
|
@ -360,12 +320,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final ScriptSourceInput importScriptInput = interpretLegacyImportScriptSetting( resourceName, classLoaderService, charsetName );
|
final ScriptSourceInput importScriptInput = interpretLegacyImportScriptSetting( resourceName, classLoaderService, charsetName );
|
||||||
final List<String> commands = importScriptInput.extract(
|
applyScript( options, commandExtractor, dialect, importScriptInput, formatter, targets );
|
||||||
reader -> commandExtractor.extractCommands( reader, dialect )
|
|
||||||
);
|
|
||||||
for ( int i = 0; i < commands.size(); i++ ) {
|
|
||||||
applySqlString( commands.get( i ), formatter, options, targets );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue