001 /**
002 * Copyright 2004-2012 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 * Runs a command that performs a single operation on a database (create,drop etc)
028 */
029 public abstract class SingleDBACommandMojo extends AbstractDBACommandMojo {
030
031 public abstract String getCommand();
032
033 @Override
034 protected void configureTransactions() throws MojoExecutionException {
035 Properties properties = getContextProperties();
036 SQLGenerator generator = new SQLGenerator(properties, url, DatabaseCommand.valueOf(getCommand().toUpperCase()));
037 try {
038 generator.setEncoding(getEncoding());
039 String sql = generator.getSQL();
040 Transaction t = new Transaction();
041 t.addText(sql);
042 t.setDescription(getTransactionDescription(DatabaseCommand.valueOf(getCommand().toUpperCase())));
043 transactions.add(t);
044 } catch (IOException e) {
045 throw new MojoExecutionException("Error configuring transactions", e);
046 }
047 }
048 }