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   * Runs a command that performs a single operation on a database (create,drop etc)
28   */
29  public abstract class SingleDBACommandMojo extends AbstractDBACommandMojo {
30  
31  	public abstract String getCommand();
32  
33  	@Override
34  	protected void configureTransactions() throws MojoExecutionException {
35  		Properties properties = getContextProperties();
36  		SQLGenerator generator = new SQLGenerator(properties, url, DatabaseCommand.valueOf(getCommand().toUpperCase()));
37  		try {
38  			generator.setEncoding(getEncoding());
39  			String sql = generator.getSQL();
40  			Transaction t = new Transaction();
41  			t.addText(sql);
42  			t.setDescription(getTransactionDescription(DatabaseCommand.valueOf(getCommand().toUpperCase())));
43  			transactions.add(t);
44  		} catch (IOException e) {
45  			throw new MojoExecutionException("Error configuring transactions", e);
46  		}
47  	}
48  }