View Javadoc

1   package org.apache.torque.mojo;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.configuration.PropertiesConfiguration;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.torque.task.TorqueDataSQLTask;
25  
26  /**
27   * Generates SQL for populating the database from data.xml files.
28   *
29   * @author Raphael Pieroni (rafale_at_codehaus.org)
30   * @author <a href="fischer@seitenbau.de">Thomas Fischer</a>
31   *
32   * @goal datasql
33   * @phase generate-sources
34   */
35  public class DataSqlMojo extends DataModelTaskMojo
36  {
37      // The following three dummies trick the Mojo Description Extractor
38      // into setting the correct default values for
39      // outputDir, reportFile and contextPropertiesPath
40      /**
41       * The directory in which the sql will be generated.
42       *
43       * @parameter property="outputDir"
44       *            expression="${project.build.directory}/generated-sql/torque"
45       */
46      private String dummy;
47  
48      /**
49       * The location where the sql file will be generated.
50       *
51       * @parameter property="reportFile"
52       *            expression="${project.artifact.artifactId}-data.sql"
53       */
54      private String dummy2;
55  
56      /**
57       * The location where the context property file for velocity will be
58       * generated.
59       *
60       * @parameter property="contextPropertiesPath"
61       *            expression="${project.build.directory}/torque/context.datasql.properties"
62       */
63      private String dummy3;
64  
65      /**
66       * The schema files which should be excluded in generation
67       * (in ant-style notation).
68       *
69       * @parameter property="schemaExcludes" expression="id-table-schema.xml"
70       */
71      private String dummy4;
72  
73      /**
74       * The data Xml file to process.
75       *
76       * @parameter
77       * @required
78       */
79      private String dataXmlFile;
80  
81      /**
82       * The data dtd file for the data xml file to process.
83       *
84       * @parameter
85       * @required
86       */
87      private String dataDtd;
88  
89      /**
90       * Creates a new SQLMojo object.
91       */
92      public DataSqlMojo()
93      {
94          super(new TorqueDataSQLTask());
95      }
96  
97      /**
98       * Returns the context properties for the Texen task.
99       *
100      * @return The PropertiesConfiguration containing all context properties,
101      *         not null.
102      */
103     protected PropertiesConfiguration getMojoContextProperties()
104     {
105         PropertiesConfiguration configuration = new PropertiesConfiguration();
106         return configuration;
107     }
108 
109     /**
110      * Configures the Texen task which is wrapped by this mojo.
111      * In addition to the prioerties set by DataModelTaskMojo#configureTask(),
112      * the properties dataXmlFile and dataDTD are set.
113      *
114      * @throws MojoExecutionException if an error occurs when setting the Tasks
115      *         properties.
116      *
117      * @see DataModelTaskMojo#configureTask()
118      */
119     protected void configureTask() throws MojoExecutionException
120     {
121         super.configureTask();
122 
123         TorqueDataSQLTask task
124                 = (TorqueDataSQLTask) super.getGeneratorTask();
125 
126         task.setDataXmlFile(dataXmlFile);
127         task.setDataDTD(dataDtd);
128     }
129 
130     /**
131      * Returns the path to the control template.
132      *
133      * @return "sql/load/Control.vm"
134      */
135     protected String getControlTemplate()
136     {
137         return "sql/load/Control.vm";
138     }
139 
140     /**
141      * Returns the data dtd file for the data xml file.
142      *
143      * @return the data dtd file for the data xml file.
144      */
145     public String getDataDtd()
146     {
147         return dataDtd;
148     }
149 
150     /**
151      * Sets the data dtd file for the data xml file.
152      *
153      * @param dataDtd the data dtd file for the data xml file.
154      */
155     public void setDataDtd(String dataDtd)
156     {
157         this.dataDtd = dataDtd;
158     }
159 
160     /**
161      * Returns the data xml file which should be processed.
162      *
163      * @return the data xml file which should be processed.
164      */
165     public String getDataXmlFile()
166     {
167         return dataXmlFile;
168     }
169 
170     /**
171      * Sets the data xml file which should be processed.
172      *
173      * @param dataXmlFile the data xml file which should be processed.
174      */
175     public void setDataXmlFile(String dataXmlFile)
176     {
177         this.dataXmlFile = dataXmlFile;
178     }
179 }