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.TorqueDataDumpTask; 25 26 /** 27 * Reads the content of tables from thh database and stores the data 28 * in XML files. 29 * 30 * @author Raphael Pieroni (rafale_at_codehaus.org) 31 * @author <a href="fischer@seitenbau.de">Thomas Fischer</a> 32 * 33 * @goal datadump 34 * @phase generate-sources 35 */ 36 public class DataDumpMojo extends DataModelTaskMojo 37 { 38 /** The context property for the name of the project. */ 39 public static final String PROJECT_CONTEXT_PROPERTY 40 = "project"; 41 42 // The following dummies trick the Mojo Description Extractor 43 // into setting the correct default values for 44 // outputDir, reportFile, contextPropertiesPath, schemaExcludes 45 /** 46 * The directory in which the data files will be created. 47 * 48 * @parameter property="outputDir" 49 * expression="${project.build.directory}/data/torque" 50 */ 51 private String dummy; 52 53 /** 54 * The location where the report file will be generated. 55 * 56 * @parameter property="reportFile" 57 * expression="../../torque/report.${project.artifact.artifactId}.data.generation" 58 */ 59 private String dummy2; 60 61 /** 62 * The location where the context property file for velocity will be 63 * generated. 64 * 65 * @parameter property="contextPropertiesPath" 66 * expression="${project.build.directory}/torque/context.data.properties" 67 */ 68 private String dummy3; 69 70 /** 71 * The schema files which should be excluded in generation 72 * (in ant-style notation). 73 * 74 * @parameter property="schemaExcludes" expression="id-table-schema.xml" 75 */ 76 private String dummy4; 77 78 /** 79 * The fully qualified class name of the database driver. 80 * 81 * @parameter 82 * @required 83 */ 84 private String driver = null; 85 86 /** 87 * The connect URL of the database. 88 * 89 * @parameter 90 * @required 91 */ 92 private String url = null; 93 94 /** 95 * The user name to connect to the database. 96 * 97 * @parameter 98 * @required 99 */ 100 private String user = null; 101 102 /** 103 * The password for the database user. 104 * 105 * @parameter 106 */ 107 private String password = null; 108 109 /** 110 * The name of the project, used as a prefix of the names 111 * of the generated files and the name of the datadtd. 112 * 113 * @parameter expression="torque" 114 */ 115 private String projectName = null; 116 117 /** 118 * The name of the xml file to process. Only one xml file can be processed 119 * at a time. 120 * Overrides the settings schemaIncludes and schemaExcludes 121 * 122 * @parameter 123 * @required 124 */ 125 private String xmlFile = null; 126 127 /** 128 * Creates a new SQLMojo object. 129 */ 130 public DataDumpMojo() 131 { 132 super(new TorqueDataDumpTask()); 133 } 134 135 /** 136 * Returns the path to the control template. 137 * 138 * @return "data/Control.vm" 139 */ 140 protected String getControlTemplate() 141 { 142 return "data/dump/Control.vm"; 143 } 144 145 /** 146 * Returns the context properties for the Texen task. 147 * 148 * @return The PropertiesConfiguration containing all context properties, 149 * not null. 150 */ 151 protected PropertiesConfiguration getMojoContextProperties() 152 { 153 PropertiesConfiguration configuration = new PropertiesConfiguration(); 154 configuration.addProperty(PROJECT_CONTEXT_PROPERTY, projectName); 155 return configuration; 156 } 157 158 /** 159 * Configures the Texen task which is wrapped by this mojo. 160 * In this implementation, the context properties, useClasspath, 161 * the output directory, the control template, the schema Fileset, 162 * the target package, the target database and the xml file are set. 163 * 164 * @throws MojoExecutionException if an error occurs when setting the Tasks 165 * properties. 166 * 167 * @see TexenTaskMojo#configureTask() 168 */ 169 protected void configureTask() throws MojoExecutionException 170 { 171 super.configureTask(); 172 173 TorqueDataDumpTask task 174 = (TorqueDataDumpTask) super.getGeneratorTask(); 175 176 task.setDatabaseDriver(driver); 177 task.setDatabaseUrl(url); 178 task.setDatabaseUser(user); 179 task.setDatabasePassword(password); 180 task.setXmlFile(xmlFile); 181 } 182 183 /** 184 * Returns the fully qualified class name of the database driver. 185 * 186 * @return the fully qualified class name of the database driver. 187 */ 188 public String getDriver() 189 { 190 return driver; 191 } 192 193 /** 194 * Sets the fully qualified class name of the database driver. 195 * 196 * @param driver the fully qualified class name of the database driver. 197 */ 198 public void setDriver(String driver) 199 { 200 this.driver = driver; 201 } 202 203 /** 204 * Returns the password of the database user. 205 * 206 * @return the password of the database user. 207 */ 208 public String getPassword() 209 { 210 return password; 211 } 212 213 /** 214 * Sets the password of the database user. 215 * 216 * @param password the password of the database user. 217 */ 218 public void setPassword(String password) 219 { 220 this.password = password; 221 } 222 223 /** 224 * Returns the connect URL to the database. 225 * 226 * @return the connect URL to the database. 227 */ 228 public String getUrl() 229 { 230 return url; 231 } 232 233 /** 234 * Sets the connect URL to the database. 235 * 236 * @param url the connect URL to the database. 237 */ 238 public void setUrl(String url) 239 { 240 this.url = url; 241 } 242 243 /** 244 * Returns the database user. 245 * 246 * @return the userId of the database user. 247 */ 248 public String getUser() 249 { 250 return user; 251 } 252 253 /** 254 * Sets the database user. 255 * 256 * @param user the userId of the database user. 257 */ 258 public void setUser(String user) 259 { 260 this.user = user; 261 } 262 263 /** 264 * Returns the name of the project, which is used as prefix for the 265 * generated table names and the name of the datadtd. 266 * 267 * @return the name of the project. 268 */ 269 public String getProjectName() 270 { 271 return projectName; 272 } 273 274 /** 275 * Sets the name of the project, which is used as prefix for the 276 * generated table names and the name of the datadtd. 277 * 278 * @param project the name of the project. 279 */ 280 public void setProjectName(String projectName) 281 { 282 this.projectName = projectName; 283 } 284 285 /** 286 * Returns the name of the xml file to process. 287 * 288 * @return the name of the xml file to process. 289 */ 290 public String getXmlFile() 291 { 292 return xmlFile; 293 } 294 295 /** 296 * Sets the name of the xml file to process. 297 * 298 * @param project the name of the xml file to process. 299 */ 300 public void setXmlFile(String xmlFile) 301 { 302 this.xmlFile = xmlFile; 303 } 304 }