From: dion g. <dio...@us...> - 2004-07-19 00:41:31
|
diongillard 04/07/18 17:41:23 Modified: dbunit/src/main/org/apache/maven/dbunit DataSetTool.java Log: Refactoring and docs Revision Changes Path 1.3 +50 -10 maven-plugins/dbunit/src/main/org/apache/maven/dbunit/DataSetTool.java Index: DataSetTool.java =================================================================== RCS file: /cvsroot/maven-plugins/maven-plugins/dbunit/src/main/org/apache/maven/dbunit/DataSetTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DataSetTool.java 25 Apr 2004 18:55:42 -0000 1.2 +++ DataSetTool.java 19 Jul 2004 00:41:23 -0000 1.3 @@ -66,6 +66,7 @@ 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; @@ -84,19 +85,38 @@ /** 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; @@ -106,32 +126,52 @@ 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 + // database connection - close? IDatabaseConnection connection = getConnection(); // write file if (getDataSetFormat().equalsIgnoreCase("EXCEL")) { - if (getExportTables() == null) XlsDataSet.write(connection.createDataSet(), new FileOutputStream(getFileName())); - else - { - String[] tables = StringUtils.split(getExportTables(), ","); - XlsDataSet.write(connection.createDataSet(tables), new FileOutputStream(getFileName())); - } + XlsDataSet.write(getDataSet(connection), new FileOutputStream(getFileName())); } } + else if (dbOperation != null) + { + // TODO create a dataset of the right type + // dbOperation.execute(getConnection(), dataset) + } } } \ No newline at end of file |