From: dion g. <dio...@us...> - 2004-08-01 11:43:17
|
diongillard 04/08/01 04:43:10 Modified: dbunit plugin.jelly dbunit/src/main/net/sourceforge/mavenplugins/dbunit DataSetTool.java Log: Basic xls importing Revision Changes Path 1.12 +14 -0 maven-plugins/dbunit/plugin.jelly Index: plugin.jelly =================================================================== RCS file: /cvsroot/maven-plugins/maven-plugins/dbunit/plugin.jelly,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- plugin.jelly 1 Aug 2004 11:15:02 -0000 1.11 +++ plugin.jelly 1 Aug 2004 11:43:10 -0000 1.12 @@ -105,4 +105,18 @@ <ant:echo>Spreadsheet generated to ${maven.build.dir}/dbunit/export.xls</ant:echo> </goal> + <goal name="dbunit:import-xls"> + <j:useBean var="tool" class="net.sourceforge.mavenplugins.dbunit.DataSetTool" + driverClassName="${maven.dbunit.driverClassName}" + url="${maven.dbunit.url}" + user="${maven.dbunit.user}" + password="${maven.dbunit.password}" + schema="${maven.dbunit.schema}" + fileName="${file}" + dataSetFormat="excel" + operation="${maven.dbunit.importType}" /> + ${tool.process()} + <ant:echo>Spreadsheet imported from ${file}</ant:echo> + </goal> + </project> 1.2 +17 -9 maven-plugins/dbunit/src/main/net/sourceforge/mavenplugins/dbunit/DataSetTool.java Index: DataSetTool.java =================================================================== RCS file: /cvsroot/maven-plugins/maven-plugins/dbunit/src/main/net/sourceforge/mavenplugins/dbunit/DataSetTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DataSetTool.java 1 Aug 2004 11:14:35 -0000 1.1 +++ DataSetTool.java 1 Aug 2004 11:43:10 -0000 1.2 @@ -56,20 +56,19 @@ * ==================================================================== */ -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.DatabaseUnitException; 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; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.sql.SQLException; + public class DataSetTool extends DbUnitTool { /** the type of data set being processed */ @@ -155,7 +154,7 @@ /** * Process a dataset using a DbUnit operation */ - public void process() throws ClassNotFoundException, SQLException, IOException, DataSetException + public void process() throws ClassNotFoundException, SQLException, IOException, DataSetException, DatabaseUnitException { if (getOperation().equalsIgnoreCase(EXPORT)) { @@ -174,7 +173,16 @@ else if (dbOperation != null) { // TODO create a dataset of the right type - // dbOperation.execute(getConnection(), dataset) + IDataSet dataset = null; + if ("EXCEL".equalsIgnoreCase(getDataSetFormat())) + { + dataset = new XlsDataSet(new File(getFileName())); + } + else + { + throw new IllegalArgumentException("dataSetFormat of '" + getDataSetFormat() + "' is not supported."); + } + dbOperation.execute(getConnection(), dataset); } } |