1 package de.juplo.plugins.hibernate;
4 * Copyright 2001-2005 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import java.security.NoSuchAlgorithmException;
21 import java.util.EnumSet;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.hibernate.boot.spi.MetadataImplementor;
26 import org.hibernate.cfg.AvailableSettings;
27 import org.hibernate.engine.config.spi.ConfigurationService;
28 import org.hibernate.service.ServiceRegistry;
29 import org.hibernate.tool.schema.TargetType;
30 import org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl;
31 import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToFile;
32 import org.hibernate.tool.schema.spi.ExecutionOptions;
33 import org.hibernate.tool.schema.spi.SchemaManagementTool;
34 import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
35 import org.hibernate.tool.schema.spi.ScriptTargetOutput;
36 import org.hibernate.tool.schema.spi.TargetDescriptor;
40 * Generate/Execute SQL to drop all tables of a database-schema that represents
41 * the configured mappings.
44 * @phase process-classes
46 * @requiresDependencyResolution runtime
48 public class DropMojo extends AbstractSchemaMojo
53 * If the specified filename is not absolut, the file will be created
54 * relative to the project build directory
55 * (<code>project.build.directory</code>).
57 * @parameter property="hibernate.schema.drop" default-value="drop.sql"
60 private String outputFile;
64 public final void execute()
67 MojoExecutionException
71 super.execute(new MD5ModificationTracker(buildDirectory, outputFile, getLog()));
73 catch (NoSuchAlgorithmException e)
75 throw new MojoFailureException("Digest-Algorithm MD5 is missing!", e);
81 ExceptionHandlerCollectingImpl build(final MetadataImplementor metadata)
83 MojoExecutionException,
86 final ServiceRegistry registry =
87 metadata.getMetadataBuildingOptions().getServiceRegistry();
89 registry.getService(ConfigurationService.class).getSettings();
90 SchemaManagementTool tool = registry.getService(SchemaManagementTool.class);
92 final EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
93 if ((Boolean)settings.get(EXECUTE))
94 targetTypes.add(TargetType.DATABASE);
96 TargetDescriptor target = new TargetDescriptor()
99 public EnumSet<TargetType> getTargetTypes()
105 public ScriptTargetOutput getScriptTargetOutput()
108 (String)settings.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
109 return new ScriptTargetOutputToFile(new File(outputFile), charset);
113 ExceptionHandlerCollectingImpl handler =
114 new ExceptionHandlerCollectingImpl();
116 ExecutionOptions options =
117 SchemaManagementToolCoordinator.buildExecutionOptions(
119 .getService(ConfigurationService.class)
124 Map config = options.getConfigurationValues();
126 tool.getSchemaMigrator(config).doMigration(metadata, options, target);