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.TorqueSQLTask; 25 26 /** 27 * Generates SQL from the schema.xml files. 28 * 29 * @author Raphael Pieroni (rafale_at_codehaus.org) 30 * @author <a href="fischer@seitenbau.de">Thomas Fischer</a> 31 * @author <a href="kannegiesser@synyx.de">Marc Kannegiesser</a> 32 * 33 */ 34 public abstract class SqlMojoBase extends DataModelTaskMojo 35 { 36 /** 37 * The suffix of the generated sql files. 38 */ 39 private String suffix =""; 40 41 /** 42 * Creates a new SQLMojo object. 43 */ 44 public SqlMojoBase() 45 { 46 super(new TorqueSQLTask()); 47 } 48 49 /** 50 * Sets the suffix of the generated sql files. 51 * 52 * @param suffix the suffix of the generated sql files. 53 */ 54 public void setSuffix(String suffix) 55 { 56 this.suffix = suffix; 57 } 58 59 /** 60 * Returns the suffix of the generated sql files. 61 * 62 * @return the suffix of the generated sql files. 63 */ 64 public String getSuffix() 65 { 66 return suffix; 67 } 68 69 /** 70 * Returns the context properties for the Texen task. 71 * 72 * @return The PropertiesConfiguration containing all context properties, 73 * not null. 74 */ 75 protected PropertiesConfiguration getMojoContextProperties() 76 { 77 PropertiesConfiguration configuration = new PropertiesConfiguration(); 78 configuration.addProperty( 79 TARGET_DATABASE_CONTEXT_PROPERTY, 80 super.getTargetDatabase()); 81 return configuration; 82 } 83 84 /** 85 * Returns the path to the control template. 86 * 87 * @return "sql/Control.vm" 88 */ 89 protected String getControlTemplate() 90 { 91 return "sql/base/Control.vm"; 92 } 93 94 /** 95 * Configures the Texen task which is wrapped by this mojo. 96 * In this implementation, the context properties, useClasspath, 97 * the output directory, the control template, the schema Fileset, 98 * the target package, the target database and the suffix are set. 99 * 100 * @throws MojoExecutionException if an error occurs when setting the Tasks 101 * properties. 102 * 103 * @see TexenTaskMojo#configureTask() 104 */ 105 protected void configureTask() throws MojoExecutionException 106 { 107 super.configureTask(); 108 109 TorqueSQLTask task 110 = (TorqueSQLTask) super.getGeneratorTask(); 111 112 if (suffix != null) 113 { 114 getLog().debug("Adding suffix: " + suffix ); 115 task.setSuffix(suffix); 116 } 117 } 118 }