diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaTruncatorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaTruncatorImpl.java index 2dc98290ec83..3d556c48a435 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaTruncatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaTruncatorImpl.java @@ -4,14 +4,18 @@ */ package org.hibernate.tool.schema.internal; +import org.hibernate.Internal; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.Exportable; import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.internal.FormatStyle; import org.hibernate.engine.jdbc.internal.Formatter; import org.hibernate.internal.util.StringHelper; @@ -25,6 +29,7 @@ import org.hibernate.tool.schema.internal.exec.ScriptSourceInputFromUrl; import org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl; import org.hibernate.tool.schema.spi.ContributableMatcher; +import org.hibernate.tool.schema.spi.ExceptionHandler; import org.hibernate.tool.schema.spi.ExecutionOptions; import org.hibernate.tool.schema.spi.SchemaFilter; import org.hibernate.tool.schema.spi.SchemaManagementException; @@ -81,7 +86,8 @@ public void doTruncate( doTruncate( metadata, options, contributableInclusionFilter, jdbcContext.getDialect(), targets ); } - private void doTruncate( + @Internal + public void doTruncate( Metadata metadata, ExecutionOptions options, ContributableMatcher contributableInclusionFilter, @@ -343,4 +349,57 @@ private ScriptSourceInput interpretLegacyImportScriptSetting( } } + /** + * Intended for use from tests + */ + @Internal + public void doTruncate( + Metadata metadata, + final boolean manageNamespaces, + GenerationTarget... targets) { + final ServiceRegistry serviceRegistry = + ( (MetadataImplementor) metadata ).getMetadataBuildingOptions() + .getServiceRegistry(); + doTruncate( + metadata, + serviceRegistry, + serviceRegistry.requireService( ConfigurationService.class ).getSettings(), + manageNamespaces, + targets + ); + } + + /** + * Intended for use from tests + */ + @Internal + public void doTruncate( + Metadata metadata, + final ServiceRegistry serviceRegistry, + final Map settings, + final boolean manageNamespaces, + GenerationTarget... targets) { + doTruncate( + metadata, + new ExecutionOptions() { + @Override + public boolean shouldManageNamespaces() { + return manageNamespaces; + } + + @Override + public Map getConfigurationValues() { + return settings; + } + + @Override + public ExceptionHandler getExceptionHandler() { + return ExceptionHandlerLoggedImpl.INSTANCE; + } + }, + (contributed) -> true, + serviceRegistry.requireService( JdbcEnvironment.class ).getDialect(), + targets + ); + } }