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  
24  /**
25   * Generates SQL for populating the id table in the database.
26   *
27   * @author Raphael Pieroni (rafale_at_codehaus.org)
28   * @author <a href="fischer@seitenbau.de">Thomas Fischer</a>
29   * @author <a href="kannegiesser@synyx.de">Marc Kannegiesser</a>
30   *
31   * @goal id-table-init-sql
32   * @phase generate-sources
33   */
34  public class IdTableInitSqlMojo extends SqlMojoBase
35  {
36      public static final String INITIALID_CONTEXT_PROPERTY
37              = "initialID";
38      public static final String INITIALIDVALUE_CONTEXT_PROPERTY
39              = "initialIDValue";
40      public static final String INITIALIDSTEP_CONTEXT_PROPERTY
41              = "initialIDStep";
42  
43      // The following dummies trick the Mojo Description Extractor
44      // into setting the correct default values for
45      // outputDir, reportFile, contextPropertiesPath, schemaExcludes, suffix
46      /**
47       * The directory in which the SQL will be generated.
48       *
49       * @parameter property="outputDir"
50       *            expression="${project.build.directory}/generated-sql/torque"
51       */
52      private String dummy;
53  
54      /**
55       * The location where the report file will be generated.
56       *
57       * @parameter property="reportFile"
58       *            expression="../../torque/report.${project.artifact.artifactId}.idtable-init-sql.generation"
59       */
60      private String dummy2;
61  
62      /**
63       * The location where the context property file for velocity will be
64       * generated.
65       *
66       * @parameter property="contextPropertiesPath"
67       *            expression="${project.build.directory}/torque/context.idtable-init-sql.properties"
68       */
69      private String dummy3;
70  
71      /**
72       * The schema files which should be excluded in generation
73       * (in ant-style notation).
74       *
75       * @parameter property="schemaExcludes" expression="id-table-schema.xml"
76       */
77      private String dummy4;
78  
79      /**
80       * The suffix of the idTable-sql files.
81       *
82       * @parameter property="suffix"
83       *            expression="-idtable-init"
84       */
85      private String dummy5;
86   
87      /**
88       * The initial ID of the idtables
89       *
90       * @parameter expression="101"
91       */
92      private String initialID;
93  
94      /**
95       * The initial IDValue of the idtable
96       *
97       * @parameter expression="1000"
98       */
99      private String initialIDValue;
100 
101     /**
102      * The initial ID Step of the idtable
103      *
104      * @parameter expression="10"
105      */
106     private String initialIDStep;
107 
108     /**
109      * Creates a new IdTableInitSqlMojo object.
110      */
111     public IdTableInitSqlMojo()
112     {
113     }
114 
115     /**
116      * Sets the initial id of the idtables
117      *
118      * @param initialID The initial of the idtables
119      */
120     public void setInitialID(String initialID)
121     {
122         this.initialID = initialID;
123     }
124 
125     /**
126      * Returns the initial id of the idtable
127      *
128      * @return initialID The initial ID of the idtables
129      */
130     public String getInitialID()
131     {
132         return this.initialID;
133     }
134 
135 
136 
137     /**
138      * Sets the initial id value of the idtables
139      *
140      * @param initialIDValue The initial id value of the tables
141      */
142     public void setInitialIDValue(String initialIDValue)
143     {
144         this.initialIDValue = initialIDValue;
145     }
146 
147     /**
148      * Returns the initial id value of the idtables
149      *
150      * @return initialIDValue the initial id value of the idtables
151      */
152     public String getInitialIDValue()
153     {
154         return this.initialIDValue;
155     }
156 
157 
158 
159     /**
160      * Sets the initial id step of the idtables
161      *
162      * @param initialIDStep The initial id step of the tables
163      */
164     public void setInitialIDStep(String initialIDStep)
165     {
166         this.initialIDStep = initialIDStep;
167     }
168 
169     /**
170      * Returns the initial id step of the idtables
171      *
172      * @return initialIDStep the initial id step of the idtables
173      */
174     public String getInitialIDStep()
175     {
176         return this.initialIDStep;
177     }
178 
179     /**
180      * Returns the context properties for the Texen task.
181      *
182      * @return The PropertiesConfiguration containing all context properties,
183      *         not null.
184      */
185     protected PropertiesConfiguration getMojoContextProperties()
186     {
187       PropertiesConfiguration configuration = super.getMojoContextProperties();
188       configuration.addProperty(
189                INITIALID_CONTEXT_PROPERTY,
190                initialID);
191 
192       configuration.addProperty(
193                INITIALIDVALUE_CONTEXT_PROPERTY,
194                initialIDValue);
195 
196       configuration.addProperty(
197                INITIALIDSTEP_CONTEXT_PROPERTY,
198                initialIDStep);
199         return configuration;
200     }
201 
202     /**
203      * Returns the path to the control template.
204      *
205      * @return "sql/id-table/Control.vm"
206      */
207     protected String getControlTemplate()
208     {
209         return "sql/id-table/Control.vm";
210     }
211 }