View Javadoc

1   /**
2    * Copyright 2004-2012 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 java.io.IOException;
19  import java.util.Properties;
20  
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.kuali.db.DatabaseCommand;
23  import org.kuali.db.SQLGenerator;
24  import org.kuali.db.Transaction;
25  
26  /**
27   * Does a DROP->CREATE of a database and the corresponding default user. See also <code>impex:create</code> and
28   * <code>impex:drop</code>
29   * 
30   * @goal reset
31   */
32  public class ResetMojo extends AbstractDBACommandMojo {
33  
34  	protected Transaction getTransaction(Properties properties, DatabaseCommand command) throws IOException {
35  		SQLGenerator generator = new SQLGenerator(properties, url, command);
36  		generator.setEncoding(getEncoding());
37  		String sql = generator.getSQL();
38  		Transaction t = new Transaction();
39  		t.setDescription(getTransactionDescription(command));
40  		t.addText(sql);
41  		return t;
42  	}
43  
44  	@Override
45  	protected void configureTransactions() throws MojoExecutionException {
46  		Properties properties = getContextProperties();
47  		try {
48  			transactions.add(getTransaction(properties, DatabaseCommand.DROP));
49  			transactions.add(getTransaction(properties, DatabaseCommand.CREATE));
50  		} catch (IOException e) {
51  			throw new MojoExecutionException("Error generating SQL", e);
52  		}
53  	}
54  }