From: <fg...@us...> - 2008-01-31 22:18:47
|
Revision: 579 http://openutils.svn.sourceforge.net/openutils/?rev=579&view=rev Author: fgiust Date: 2008-01-31 14:18:50 -0800 (Thu, 31 Jan 2008) Log Message: ----------- new utility method Modified Paths: -------------- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java trunk/openutils-testing/src/site/changes/changes.xml Modified: trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java =================================================================== --- trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-31 13:13:40 UTC (rev 578) +++ trunk/openutils-testing/src/main/java/it/openutils/testing/DbUnitUtils.java 2008-01-31 22:18:50 UTC (rev 579) @@ -29,6 +29,7 @@ import org.dbunit.dataset.FilteredDataSet; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.excel.XlsDataSet; +import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.dataset.xml.XmlDataSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,6 +97,38 @@ } /** + * Exports a full db saving a dataset for each table. + * @param connection dbunit connection + * @param directory export directory + * @param xls if <code>true</code> export will be done using excel datasets + * @param tableFilter optional table filter + * @throws SQLException sql exception + * @throws DataSetException dbunit exception + * @throws IOException IO exception + */ + public void exportTablesToDir(IDatabaseConnection connection, File directory, boolean xls, ITableFilter tableFilter) + throws SQLException, DataSetException, IOException + + { + directory.mkdirs(); + + IDataSet dataset = connection.createDataSet(); + if (tableFilter != null) + { + dataset = new FilteredDataSet(tableFilter, dataset); + } + + String[] tablenames = dataset.getTableNames(); + + for (String table : tablenames) + { + File exportFile = new File(directory, table + (xls ? ".xls" : ".xml")); + log.info("Exporting {}", table); + DbUnitUtils.exportDataset(connection, new String[]{table }, exportFile); + } + } + + /** * @param url dataset url (can be an xml or excel file) * @return loaded dataset * @throws IOException error reading the file Modified: trunk/openutils-testing/src/site/changes/changes.xml =================================================================== --- trunk/openutils-testing/src/site/changes/changes.xml 2008-01-31 13:13:40 UTC (rev 578) +++ trunk/openutils-testing/src/site/changes/changes.xml 2008-01-31 22:18:50 UTC (rev 579) @@ -17,6 +17,7 @@ truncate operation now defaults to DbUnitOperation.DELETE_ALL instead of DbUnitOperation.TRUNCATE. </action> <action type="fix" dev="fgiust">DbUnitUtils.exportDataset() doesn't close anymore the provided connection</action> + <action type="add" dev="fgiust">new DbUnitUtils.exportTablesToDir() utility method</action> </release> <release version="2.0.1" date="2008-01-30" description="2.0.1"> <action type="fix" dev="fgiust"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |