1 /** 2 * Copyright 2004-2013 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.apache.torque.mojo; 17 18 import org.apache.maven.plugin.MojoExecutionException; 19 import org.apache.torque.util.ChangeDetector; 20 21 /** 22 * Generates platform specific SQL from database agnostic XML files.<br> 23 * <br> 24 * There are two types of SQL files created by this goal:<br> 25 * <br> 26 * Type 1: DDL statements for creating tables, primary keys, indexes, and unique constraints. Does not contain DDL for 27 * enforcing relationships between tables.<br> 28 * Type 2: DDL statements for creating and enforcing relationships between tables<br> 29 * <br> 30 * This allows data to be imported into multiple tables concurrently. Running the first type of SQL file will create the 31 * empty tables without any foreign key constraints. Data can then be loaded concurrently into the tables (using 32 * optimized high speed tools if desired) without needing to worry about the order in which the tables are loaded. After 33 * data has been loaded, the second type of SQL file can be run to add the relationships between the tables. As long as 34 * the data set is consistent and correct, all the relationships will get created correctly.<br> 35 * <br> 36 * The database platform to generate SQL for is determined by ${targetDatabase}. See also <code>impex:datasql</code> 37 * 38 * @goal schemasql 39 * @phase generate-sources 40 */ 41 public class SchemaSqlMojo extends SqlMojoBase { 42 43 /** 44 * The directory in which the SQL will be generated. 45 * 46 * @parameter property="outputDir" expression="${outputDir}" default-value="${project.build.directory}/classes/sql" 47 */ 48 @SuppressWarnings("unused") 49 private String dummy1; 50 51 /** 52 * The location where the report file will be generated. 53 * 54 * @parameter property="reportFile" expression="${reportFile}" default-value= 55 * "../../../reports/report.${project.artifactId}.sql.generation" 56 */ 57 @SuppressWarnings("unused") 58 private String dummy2; 59 60 /** 61 * The location where the context property file for velocity will be generated. 62 * 63 * @parameter property="contextPropertiesPath" expression="${contextPropertiesPath}" 64 * default-value="${project.build.directory}/reports/context.sql.properties" 65 */ 66 @SuppressWarnings("unused") 67 private String dummy3; 68 69 /** 70 * The suffix of the generated sql files. 71 * 72 * @parameter property="suffix" expression="${suffix}" 73 */ 74 @SuppressWarnings("unused") 75 private String dummy4; 76 77 protected void showConfig() { 78 getLog().info("Schema Dir: " + getSchemaDir()); 79 getLog().info("Includes: " + getSchemaIncludes()); 80 getLog().info("Excludes: " + getSchemaExcludes()); 81 } 82 83 /** 84 * Generate SQL from schema XML files 85 */ 86 @Override 87 public void executeMojo() throws MojoExecutionException { 88 updateConfiguration(); 89 validateConfiguration(); 90 generateContextProperties(); 91 configureTask(); 92 addTargetDatabaseToOutputDir(); 93 addTargetDatabaseToReportFile(); 94 showConfig(); 95 ChangeDetector detector = new ChangeDetector(getCanonicalReportFile(), getSchemaFiles()); 96 if (!detector.isChanged() && isRunOnlyOnSchemaChange()) { 97 getLog().info("Schema has not changed. Skipping generation"); 98 return; 99 } 100 getLog().info("------------------------------------------------------------------------"); 101 getLog().info("Generating SQL for " + getTargetDatabase() + " from schema XML files"); 102 getLog().info("------------------------------------------------------------------------"); 103 getAntTask().execute(); 104 } 105 }