View Javadoc
1   package de.juplo.plugins.hibernate;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
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
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  
19  import java.util.Map;
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.plugin.MojoFailureException;
22  import org.hibernate.boot.spi.MetadataImplementor;
23  import org.hibernate.service.ServiceRegistry;
24  import org.hibernate.tool.schema.spi.ExecutionOptions;
25  import org.hibernate.tool.schema.spi.SchemaManagementTool;
26  import org.hibernate.tool.schema.spi.TargetDescriptor;
27  
28  
29  /**
30   * Generate/Execute SQL to update the database-schema according to the
31   * configured mappings.
32   *
33   * @goal update
34   * @phase process-classes
35   * @threadSafe
36   * @requiresDependencyResolution runtime
37   */
38  public class UpdateMojo extends AbstractSchemaMojo
39  {
40    /**
41     * Output file.
42     * <p>
43     * If the specified filename is not absolut, the file will be created
44     * relative to the project build directory
45     * (<code>project.build.directory</code>).
46     *
47     * @parameter property="hibernate.schema.update" default-value="update.sql"
48     * @since 1.0
49     */
50    private String outputFile;
51  
52  
53    @Override
54    public final void execute()
55      throws
56        MojoFailureException,
57        MojoExecutionException
58    {
59      super.execute(outputFile);
60    }
61  
62  
63    @Override
64    void build(
65        MetadataImplementor metadata,
66        ExecutionOptions options,
67        TargetDescriptor target
68        )
69        throws
70          MojoExecutionException,
71          MojoFailureException
72    {
73      ServiceRegistry service =
74          metadata.getMetadataBuildingOptions().getServiceRegistry();
75      SchemaManagementTool tool = service.getService(SchemaManagementTool.class);
76  
77      Map config = options.getConfigurationValues();
78  
79      tool.getSchemaMigrator(config).doMigration(metadata, options, target);
80    }
81  }