X-Git-Url: https://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fplugins%2Fhibernate%2FUpdateMojo.java;fp=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fplugins%2Fhibernate%2FUpdateMojo.java;h=91d978cf8b8a40e5102e9c8d8482def8f40e6743;hp=0000000000000000000000000000000000000000;hb=9ef60a3f37e89f8a2417e340ef6c6b4a11e6013e;hpb=2bc469097f6ff01d83f7a361d2c33e2a3fafef1c diff --git a/src/main/java/de/juplo/plugins/hibernate/UpdateMojo.java b/src/main/java/de/juplo/plugins/hibernate/UpdateMojo.java new file mode 100644 index 00000000..91d978cf --- /dev/null +++ b/src/main/java/de/juplo/plugins/hibernate/UpdateMojo.java @@ -0,0 +1,81 @@ +package de.juplo.plugins.hibernate; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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.service.ServiceRegistry; +import org.hibernate.tool.schema.spi.ExecutionOptions; +import org.hibernate.tool.schema.spi.SchemaManagementTool; +import org.hibernate.tool.schema.spi.TargetDescriptor; + + +/** + * Goal which extracts the hibernate-mapping-configuration and + * exports an according SQL-database-schema. + * + * @goal update + * @phase process-classes + * @threadSafe + * @requiresDependencyResolution runtime + */ +public class UpdateMojo extends AbstractSchemaMojo +{ + /** + * Output file. + *

+ * If the specified filename is not absolut, the file will be created + * relative to the project build directory + * (project.build.directory). + * + * @parameter property="hibernate.schema.update" default-value="update.sql" + * @since 1.0 + */ + private String outputFile; + + + @Override + public final void execute() + throws + MojoFailureException, + MojoExecutionException + { + super.execute(outputFile); + } + + + @Override + void build( + MetadataImplementor metadata, + ExecutionOptions options, + TargetDescriptor target + ) + throws + MojoExecutionException, + MojoFailureException + { + ServiceRegistry service = + metadata.getMetadataBuildingOptions().getServiceRegistry(); + SchemaManagementTool tool = service.getService(SchemaManagementTool.class); + + Map config = options.getConfigurationValues(); + + tool.getSchemaMigrator(config).doMigration(metadata, options, target); + } +}