001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.torque.mojo; 017 018 import java.io.IOException; 019 import java.util.Properties; 020 021 import org.apache.maven.plugin.MojoExecutionException; 022 import org.kuali.db.DatabaseCommand; 023 import org.kuali.db.SQLGenerator; 024 import org.kuali.db.Transaction; 025 026 /** 027 * Does a DROP->CREATE of a database and the corresponding default user. See also <code>impex:create</code> and 028 * <code>impex:drop</code> 029 * 030 * @goal reset 031 */ 032 public class ResetMojo extends AbstractDBACommandMojo { 033 034 protected Transaction getTransaction(Properties properties, DatabaseCommand command) throws IOException { 035 SQLGenerator generator = new SQLGenerator(properties, url, command); 036 generator.setEncoding(getEncoding()); 037 String sql = generator.getSQL(); 038 Transaction t = new Transaction(); 039 t.setDescription(getTransactionDescription(command)); 040 t.addText(sql); 041 return t; 042 } 043 044 @Override 045 protected void configureTransactions() throws MojoExecutionException { 046 Properties properties = getContextProperties(); 047 try { 048 transactions.add(getTransaction(properties, DatabaseCommand.DROP)); 049 transactions.add(getTransaction(properties, DatabaseCommand.CREATE)); 050 } catch (IOException e) { 051 throw new MojoExecutionException("Error generating SQL", e); 052 } 053 } 054 }