From: dion g. <dio...@us...> - 2004-08-01 11:14:43
|
diongillard 04/08/01 04:14:36 Added: dbunit/src/main/net/sourceforge/mavenplugins/dbunit DTDGenerator.java DbUnitTool.java DataSetTool.java Removed: dbunit/src/main/org/apache/maven/dbunit DTDGenerator.java DbUnitTool.java DataSetTool.java Log: Rename source tree Revision Changes Path 1.1 maven-plugins/dbunit/src/main/net/sourceforge/mavenplugins/dbunit/DTDGenerator.java Index: DTDGenerator.java =================================================================== package net.sourceforge.mavenplugins.dbunit; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Maven" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * "Apache Maven", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ import java.io.FileOutputStream; import org.dbunit.database.IDatabaseConnection; import org.dbunit.dataset.xml.FlatDtdDataSet; public class DTDGenerator extends DbUnitTool { /** * Generate the DTD * * @throws Exception */ public void generate() throws Exception { // database connection IDatabaseConnection connection = getConnection(); // write DTD file FlatDtdDataSet.write(connection.createDataSet(), new FileOutputStream(getFileName())); } } 1.1 maven-plugins/dbunit/src/main/net/sourceforge/mavenplugins/dbunit/DbUnitTool.java Index: DbUnitTool.java =================================================================== package net.sourceforge.mavenplugins.dbunit; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Maven" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * "Apache Maven", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ import org.dbunit.database.IDatabaseConnection; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import org.dbunit.database.DatabaseConnection; /** * Base class for working with DbUnit * * @author Dion Gillard */ public class DbUnitTool { private String driverClassName; private String url; private String user; private String password; private String fileName; private String schema; public String getDriverClassName() { return driverClassName; } public void setDriverClassName(String name) { driverClassName = name; } public String getUrl() { return url; } public void setUrl(String newURL) { url = newURL; } public String getUser() { return user; } public void setUser(String newUser) { user = newUser; } public String getPassword() { return password; } public void setPassword(String newPassword) { password = newPassword; } public String getFileName() { return fileName; } public void setFileName(String newFileName) { fileName = newFileName; } public String getSchema() { return schema; } public void setSchema(String schema) { this.schema = schema; } protected IDatabaseConnection getConnection() throws SQLException, ClassNotFoundException { Class driverClass = Class.forName(getDriverClassName()); Connection jdbcConnection = DriverManager.getConnection( getUrl(), getUser(), getPassword()); IDatabaseConnection connection = null; if (getSchema() == null) { connection = new DatabaseConnection(jdbcConnection); } else { connection = new DatabaseConnection(jdbcConnection, getSchema()); } return connection; } } 1.1 maven-plugins/dbunit/src/main/net/sourceforge/mavenplugins/dbunit/DataSetTool.java Index: DataSetTool.java =================================================================== package net.sourceforge.mavenplugins.dbunit; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Maven" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * "Apache Maven", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ import java.io.FileOutputStream; import java.io.IOException; import java.sql.SQLException; import java.util.Map; import java.util.HashMap; import org.apache.commons.lang.StringUtils; import org.dbunit.database.IDatabaseConnection; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.excel.XlsDataSet; import org.dbunit.operation.DatabaseOperation; public class DataSetTool extends DbUnitTool { /** the type of data set being processed */ private String dataSetFormat; /** the operation to perform on the data set */ private String operation; /** dbunit database operation based on the string */ private DatabaseOperation dbOperation; /** list of comma separated table names to export */ private String exportTables; /** export psuedo operation */ private static final String EXPORT = "EXPORT"; /** format for excel files */ private static final String EXCEL = "EXCEL"; /** * @return the format of the data set. */ public String getDataSetFormat() { return dataSetFormat; } /** * TODO better document this * Set the format of the dataset, e.g. EXCEL * @param name the dbunit dataset format */ public void setDataSetFormat(String name) { dataSetFormat = name; } /** * The operation to perform on a dataset, e.g. * <code>INSERT</code>, <code>CLEAN_INSERT</code>, <code>DELETE</code> or * <code>EXPORT</code> */ public String getOperation() { return operation; } /** * @return the operation to perform on a dataset * @see #getOperation() */ public void setOperation(String name) { operation = name; if (operation == null) operation = "INSERT"; if (operation.equalsIgnoreCase("CLEAN_INSERT")) dbOperation = DatabaseOperation.CLEAN_INSERT; if (operation.equalsIgnoreCase("DELETE")) dbOperation = DatabaseOperation.DELETE; if (operation.equalsIgnoreCase("INSERT")) dbOperation = DatabaseOperation.INSERT; } /** * @return a comma separated list of table names */ public String getExportTables() { return exportTables; } /** * set the list of tables to be exported * @param tables a comma separated list of table names */ public void setExportTables(String tables) { exportTables = tables; } /** * @return the dataset to operate on from the given connection */ private IDataSet getDataSet(IDatabaseConnection connection) throws SQLException { if (getExportTables() == null) return connection.createDataSet(); else return connection.createDataSet(StringUtils.split(getExportTables(), ",")); } /** * Process a dataset using a DbUnit operation */ public void process() throws ClassNotFoundException, SQLException, IOException, DataSetException { if (getOperation().equalsIgnoreCase(EXPORT)) { // database connection - close? IDatabaseConnection connection = getConnection(); // write file if (getDataSetFormat().equalsIgnoreCase("EXCEL")) { XlsDataSet.write(getDataSet(connection), new FileOutputStream(getFileName())); } else { throw new IllegalArgumentException("operation of '" + getOperation() + "' is not supported."); } } else if (dbOperation != null) { // TODO create a dataset of the right type // dbOperation.execute(getConnection(), dataset) } } } |