{
thread.setContextClassLoader(classLoader);
ExceptionHandlerCollectingImpl handler =
- build((MetadataImplementor)metadataBuilder.build());
+ build((MetadataImplementor)metadataBuilder.build(), output);
if (handler.getExceptions().size() > 0)
{
StringBuilder builder = new StringBuilder();
}
- abstract ExceptionHandlerCollectingImpl build(MetadataImplementor metadata)
+ abstract ExceptionHandlerCollectingImpl build(
+ MetadataImplementor metadata,
+ File file
+ )
throws
MojoFailureException,
MojoExecutionException;
* limitations under the License.
*/
+import static de.juplo.plugins.hibernate.AbstractSchemaMojo.EXECUTE;
+import java.io.File;
+import java.util.EnumSet;
import java.util.Map;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.hibernate.boot.spi.MetadataImplementor;
+import org.hibernate.cfg.AvailableSettings;
+import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.service.ServiceRegistry;
-import org.hibernate.tool.schema.SourceType;
+import org.hibernate.tool.schema.TargetType;
+import org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl;
+import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile;
import org.hibernate.tool.schema.spi.ExecutionOptions;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
-import org.hibernate.tool.schema.spi.ScriptSourceInput;
-import org.hibernate.tool.schema.spi.SourceDescriptor;
+import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
+import org.hibernate.tool.schema.spi.ScriptTargetOutput;
import org.hibernate.tool.schema.spi.TargetDescriptor;
@Override
- void build(
- MetadataImplementor metadata,
- ExecutionOptions options,
- TargetDescriptor target
+ ExceptionHandlerCollectingImpl build(
+ final MetadataImplementor metadata,
+ final File output
)
throws
MojoExecutionException,
MojoFailureException
{
- ServiceRegistry service =
+ final ServiceRegistry registry =
metadata.getMetadataBuildingOptions().getServiceRegistry();
- SchemaManagementTool tool = service.getService(SchemaManagementTool.class);
+ final Map settings =
+ registry.getService(ConfigurationService.class).getSettings();
+ SchemaManagementTool tool = registry.getService(SchemaManagementTool.class);
- Map config = options.getConfigurationValues();
- SourceDescriptor source = new SourceDescriptor()
+ final EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
+ if ((Boolean)settings.get(EXECUTE))
+ targetTypes.add(TargetType.DATABASE);
+
+ TargetDescriptor target = new TargetDescriptor()
{
- @Override
- public SourceType getSourceType()
+ @Override
+ public EnumSet<TargetType> getTargetTypes()
{
- return SourceType.METADATA;
+ return targetTypes;
}
@Override
- public ScriptSourceInput getScriptSourceInput()
+ public ScriptTargetOutput getScriptTargetOutput()
{
- return null;
+ String charset =
+ (String)settings.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
+ return new ScriptTargetOutputToFile(output, charset);
}
};
- tool.getSchemaCreator(config).doCreation(metadata, options, source, target);
+ ExceptionHandlerCollectingImpl handler =
+ new ExceptionHandlerCollectingImpl();
+
+ ExecutionOptions options =
+ SchemaManagementToolCoordinator.buildExecutionOptions(
+ registry
+ .getService(ConfigurationService.class)
+ .getSettings(),
+ handler
+ );
+
+ Map config = options.getConfigurationValues();
+
+ tool.getSchemaMigrator(config).doMigration(metadata, options, target);
+
+ return handler;
}
}
* limitations under the License.
*/
+import java.io.File;
+import java.util.EnumSet;
import java.util.Map;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.hibernate.boot.spi.MetadataImplementor;
+import org.hibernate.cfg.AvailableSettings;
+import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.service.ServiceRegistry;
-import org.hibernate.tool.schema.SourceType;
+import org.hibernate.tool.schema.TargetType;
+import org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl;
+import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile;
import org.hibernate.tool.schema.spi.ExecutionOptions;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
-import org.hibernate.tool.schema.spi.ScriptSourceInput;
-import org.hibernate.tool.schema.spi.SourceDescriptor;
+import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
+import org.hibernate.tool.schema.spi.ScriptTargetOutput;
import org.hibernate.tool.schema.spi.TargetDescriptor;
@Override
- void build(
- MetadataImplementor metadata,
- ExecutionOptions options,
- TargetDescriptor target
+ ExceptionHandlerCollectingImpl build(
+ final MetadataImplementor metadata,
+ final File output
)
throws
MojoExecutionException,
MojoFailureException
{
- ServiceRegistry service =
+ final ServiceRegistry registry =
metadata.getMetadataBuildingOptions().getServiceRegistry();
- SchemaManagementTool tool = service.getService(SchemaManagementTool.class);
+ final Map settings =
+ registry.getService(ConfigurationService.class).getSettings();
+ SchemaManagementTool tool = registry.getService(SchemaManagementTool.class);
- Map config = options.getConfigurationValues();
- SourceDescriptor source = new SourceDescriptor()
+ final EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
+ if ((Boolean)settings.get(EXECUTE))
+ targetTypes.add(TargetType.DATABASE);
+
+ TargetDescriptor target = new TargetDescriptor()
{
- @Override
- public SourceType getSourceType()
+ @Override
+ public EnumSet<TargetType> getTargetTypes()
{
- return SourceType.METADATA;
+ return targetTypes;
}
@Override
- public ScriptSourceInput getScriptSourceInput()
+ public ScriptTargetOutput getScriptTargetOutput()
{
- return null;
+ String charset =
+ (String)settings.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
+ return new ScriptTargetOutputToFile(output, charset);
}
};
- tool.getSchemaDropper(config).doDrop(metadata, options, source, target);
+ ExceptionHandlerCollectingImpl handler =
+ new ExceptionHandlerCollectingImpl();
+
+ ExecutionOptions options =
+ SchemaManagementToolCoordinator.buildExecutionOptions(
+ registry
+ .getService(ConfigurationService.class)
+ .getSettings(),
+ handler
+ );
+
+ Map config = options.getConfigurationValues();
+
+ tool.getSchemaMigrator(config).doMigration(metadata, options, target);
+
+ return handler;
}
}
* limitations under the License.
*/
+import java.io.File;
import java.util.EnumSet;
-import java.util.HashMap;
import java.util.Map;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@Override
- ExceptionHandlerCollectingImpl build(MetadataImplementor metadata)
+ ExceptionHandlerCollectingImpl build(
+ final MetadataImplementor metadata,
+ final File output
+ )
throws
MojoExecutionException,
MojoFailureException
{
- final ServiceRegistry service =
+ final ServiceRegistry registry =
metadata.getMetadataBuildingOptions().getServiceRegistry();
- SchemaManagementTool tool = service.getService(SchemaManagementTool.class);
+ final Map settings =
+ registry.getService(ConfigurationService.class).getSettings();
+ SchemaManagementTool tool = registry.getService(SchemaManagementTool.class);
final EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
- if (execute)
+ if ((Boolean)settings.get(EXECUTE))
targetTypes.add(TargetType.DATABASE);
TargetDescriptor target = new TargetDescriptor()
@Override
public ScriptTargetOutput getScriptTargetOutput()
{
- String charset
- = (String) service
- .getService(ConfigurationService.class)
- .getSettings()
- .get(AvailableSettings.HBM2DDL_CHARSET_NAME);
+ String charset =
+ (String)settings.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
return new ScriptTargetOutputToFile(output, charset);
}
};
+ ExceptionHandlerCollectingImpl handler =
+ new ExceptionHandlerCollectingImpl();
+
ExecutionOptions options =
SchemaManagementToolCoordinator.buildExecutionOptions(
- service
+ registry
.getService(ConfigurationService.class)
.getSettings(),
- new ExceptionHandlerCollectingImpl()
+ handler
);
Map config = options.getConfigurationValues();
tool.getSchemaMigrator(config).doMigration(metadata, options, target);
+
+ return handler;
}
}
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl;
-import org.hibernate.tool.schema.spi.ExecutionOptions;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
-import org.hibernate.tool.schema.spi.TargetDescriptor;
/**