You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(5) |
Jul
(7) |
Aug
(37) |
Sep
|
Oct
|
Nov
(1) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(8) |
Feb
(68) |
Mar
(72) |
Apr
(149) |
May
(32) |
Jun
(46) |
Jul
(26) |
Aug
(59) |
Sep
(25) |
Oct
(18) |
Nov
(4) |
Dec
(3) |
2004 |
Jan
(90) |
Feb
(19) |
Mar
(38) |
Apr
(41) |
May
(44) |
Jun
(2) |
Jul
(10) |
Aug
|
Sep
(14) |
Oct
|
Nov
(1) |
Dec
|
2005 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(15) |
Jun
(1) |
Jul
|
Aug
(9) |
Sep
|
Oct
(17) |
Nov
|
Dec
|
2006 |
Jan
(1) |
Feb
(16) |
Mar
|
Apr
(1) |
May
(48) |
Jun
|
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(29) |
2007 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
(23) |
Mar
(31) |
Apr
|
May
(26) |
Jun
(6) |
Jul
(1) |
Aug
|
Sep
(7) |
Oct
(1) |
Nov
(8) |
Dec
(8) |
2009 |
Jan
(5) |
Feb
(9) |
Mar
(1) |
Apr
|
May
(23) |
Jun
(3) |
Jul
|
Aug
(1) |
Sep
(9) |
Oct
(28) |
Nov
(18) |
Dec
(8) |
2010 |
Jan
(19) |
Feb
(24) |
Mar
(3) |
Apr
|
May
(5) |
Jun
(4) |
Jul
|
Aug
(1) |
Sep
(11) |
Oct
|
Nov
(2) |
Dec
(1) |
2011 |
Jan
|
Feb
(7) |
Mar
|
Apr
(6) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(32) |
Oct
(6) |
Nov
|
Dec
|
From: <fel...@us...> - 2006-02-18 04:23:22
|
Update of /cvsroot/dbunit/dbunit/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/xdocs Modified Files: faq.fml Log Message: 1273949: addde filtering by PK feature Index: faq.fml =================================================================== RCS file: /cvsroot/dbunit/dbunit/xdocs/faq.fml,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** faq.fml 28 Jun 2004 12:07:00 -0000 1.20 --- faq.fml 18 Feb 2006 04:23:02 -0000 1.21 *************** *** 1,538 **** ! <?xml version="1.0" encoding="UTF-8"?> ! <faqs title="Frequently Asked Questions"> ! ! <part id="general"> ! <title>General</title> ! <faq id="supportedvendors"> ! <question> ! Which relational database systems are supported? ! </question> ! <answer> [...1057 lines suppressed...] ! ! <faq id="UnsatisfiedLinkError"> ! <question> ! Why I get an "UnsatisfiedLinkError" ! with the DB2 driver? ! </question> ! <answer> ! <p>DbUnit uses JDBC 2.0 features (batch updates). By default, DB2 installs ! the JDBC 1.0 driver. You have to install the JDBC 2.0 driver in order ! for DbUnit to work or you will get an <a class="code">UnsatisfiedLinkError</a> ! from the DB2 JDBC 1.0 driver.</p> ! <p>The steps for installing the DB2 JDBC 2.0 driver are covered in the DB2 ! documentation.</p> ! </answer> ! </faq> ! ! ! </part> </faqs> \ No newline at end of file |
From: <fel...@us...> - 2006-02-18 04:23:21
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/search In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/java/org/dbunit/util/search Modified Files: SearchException.java Edge.java DepthFirstSearch.java Log Message: 1273949: addde filtering by PK feature Index: SearchException.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/search/SearchException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SearchException.java 18 Oct 2005 14:43:30 -0000 1.1 --- SearchException.java 18 Feb 2006 04:23:05 -0000 1.2 *************** *** 25,28 **** --- 25,30 ---- /** + * Base class for exceptions during the search. + * * @author Felipe Leme <db...@fe...> * @version $Revision$ *************** *** 30,36 **** */ public class SearchException extends DatabaseUnitException { ! /** ! * ! */ private static final long serialVersionUID = -8369726048539373231L; --- 32,36 ---- */ public class SearchException extends DatabaseUnitException { ! private static final long serialVersionUID = -8369726048539373231L; Index: Edge.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/search/Edge.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Edge.java 18 Oct 2005 14:43:30 -0000 1.1 --- Edge.java 18 Feb 2006 04:23:05 -0000 1.2 *************** *** 26,29 **** --- 26,30 ---- /** * Basic implementation of the IEdge interface. + * TODO: add test cases (specially for the equals/compare methods) * * @author Felipe Leme <db...@fe...> *************** *** 34,38 **** private final Comparable nodeFrom; - private final Comparable nodeTo; --- 35,38 ---- *************** *** 74,78 **** public int hashCode() { ! return HashCodeBuilder.reflectionHashCode(this); } --- 74,78 ---- public int hashCode() { ! return HashCodeBuilder.reflectionHashCode( this ); } Index: DepthFirstSearch.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/search/DepthFirstSearch.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DepthFirstSearch.java 18 Oct 2005 14:43:30 -0000 1.1 --- DepthFirstSearch.java 18 Feb 2006 04:23:05 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.dbunit.util.CollectionsHelper; /** *************** *** 64,114 **** /** - * Helper method, returns a Set from an array of objects. - * Note the Iterator returned by this Set mantains the order of the array. - * @param objects array of objects - * @return Set with the elements of the array - */ - public static Set objectsToSet( Object[] objects ) { - Set set = new ListOrderedSet(); - for (int i = 0; i < objects.length; i++) { - set.add(objects[i]); - } - return set; - } - - /** - * Helper method, returns an array of Objects from a Set. - * @param a Set - * @return array of Objects with the elements of the Set - */ - public static Object[] setToObjects( Set set ) { - Object[] objects = new Object[ set.size() ]; - int i=0; - for (Iterator iter = set.iterator(); iter.hasNext(); i++) { - objects[i] = iter.next(); - } - return objects; - } - - /** - * Helper method, returns an array of Strings from a Set. - * @param a Set of Strings - * @return array of Strings with the elements of the Set - */ - public static String[] setToStrings( Set set ) { - String[] strings = new String[ set.size() ]; - int i=0; - for (Iterator iter = set.iterator(); iter.hasNext(); i++) { - strings[i] = (String) iter.next(); - } - return strings; - } - - /** * Alternative option to search() that takes an array of nodes as input (instead of a Set) */ public Set search(Object[] nodesFrom, ISearchCallback callback) throws SearchException { ! return search(objectsToSet(nodesFrom), callback); } --- 65,73 ---- /** * Alternative option to search() that takes an array of nodes as input (instead of a Set) */ public Set search(Object[] nodesFrom, ISearchCallback callback) throws SearchException { ! return search(CollectionsHelper.objectsToSet(nodesFrom), callback); } *************** *** 196,201 **** } if (!this.callback.searchNode(node)) { ! if ( this.logger.isTraceEnabled() ) { ! this.logger.trace( "Callback handler blocked filtered out node " + node ); } return true; --- 155,160 ---- } if (!this.callback.searchNode(node)) { ! if ( this.logger.isDebugEnabled() ) { ! this.logger.debug( "Callback handler blocked search for node " + node ); } return true; *************** *** 220,224 **** // finally, add the node to the result ! this.logger.trace( "Adding node " + node + " to the final result" ); this.callback.nodeAdded(node); result.add(node); --- 179,186 ---- // finally, add the node to the result ! if ( this.logger.isDebugEnabled() ) { ! this.logger.debug( "Adding node " + node + " to the final result" ); ! } ! // notify the callback a node was added this.callback.nodeAdded(node); result.add(node); *************** *** 246,251 **** if (!this.callback.searchNode(node)) { ! if ( this.logger.isTraceEnabled() ) { ! this.logger.trace( "callback handler blocked filtered out node (reverse) " + node ); } return true; --- 208,213 ---- if (!this.callback.searchNode(node)) { ! if ( this.logger.isDebugEnabled() ) { ! this.logger.debug( "callback handler blocked reverse search for node " + node ); } return true; |
From: <fel...@us...> - 2006-02-18 04:23:21
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/test/org/dbunit Modified Files: AllTests.java Added Files: AbstractHSQLTestCase.java Log Message: 1273949: addde filtering by PK feature --- NEW FILE: AbstractHSQLTestCase.java --- package org.dbunit; import java.io.File; import java.sql.Connection; import java.util.Set; import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.dbunit.database.DatabaseConnection; import org.dbunit.database.IDatabaseConnection; import org.dbunit.util.CollectionsHelper; public abstract class AbstractHSQLTestCase extends TestCase { public static final String A = "A"; public static final String B = "B"; public static final String C = "C"; public static final String D = "D"; public static final String E = "E"; public static final String F = "F"; public static final String G = "G"; public static final String H = "H"; public static final String A1 = "A1"; public static final String B1 = "B1"; public static final String C1 = "C1"; public static final String D1 = "D1"; public static final String E1 = "E1"; public static final String F1 = "F1"; public static final String G1 = "G1"; public static final String H1 = "H1"; public static final String A2 = "A2"; public static final String B2 = "B2"; public static final String C2 = "C2"; public static final String D2 = "D2"; public static final String E2 = "E2"; public static final String F2 = "F2"; public static final String G2 = "G2"; public static final String H2 = "H2"; public static final String C3 = "C3"; public static final String E3 = "E3"; public static final String C4 = "C4"; public static final String E4 = "E4"; public static final String B3 = "B3"; public static final String B4 = "B4"; public static final String B5 = "B5"; public static final String B6 = "B6"; public static final String B7 = "B7"; public static final String B8 = "B8"; private Connection jdbcConnection; private final String sqlFile; private IDatabaseConnection connection; protected final Log logger = LogFactory.getLog(getClass()); public AbstractHSQLTestCase(String testName, String sqlFile) { super(testName); this.sqlFile = sqlFile; } protected void setUp() throws Exception { super.setUp(); this.jdbcConnection = HypersonicEnvironment.createJdbcConnection("mem:tempdb"); HypersonicEnvironment.executeDdlFile(new File( "src/sql/" + sqlFile), jdbcConnection); this.connection = new DatabaseConnection(jdbcConnection); } protected void tearDown() throws Exception { super.tearDown(); HypersonicEnvironment.shutdown(this.jdbcConnection); this.jdbcConnection.close(); } protected IDatabaseConnection getConnection() { return this.connection; } protected static String dump(String[] parent) { StringBuffer buffer = new StringBuffer("[ " + parent[0]); for (int i = 1; i < parent.length; i++) { buffer.append(", " + parent[i]); } buffer.append(" ]"); return buffer.toString(); } public static String dump(Set set) { String[] strings= CollectionsHelper.setToStrings(set); return dump(strings); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/AllTests.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** AllTests.java 18 Oct 2005 14:43:30 -0000 1.14 --- AllTests.java 18 Feb 2006 04:23:05 -0000 1.15 *************** *** 40,43 **** --- 40,44 ---- suite.addTest(org.dbunit.ext.AllTests.suite()); suite.addTest(org.dbunit.operation.AllTests.suite()); + suite.addTest(org.dbunit.util.AllTests.suite()); suite.addTest(org.dbunit.util.search.AllTests.suite()); suite.addTest(new TestSuite(AssertionTest.class)); |
From: <fel...@us...> - 2006-02-18 04:23:19
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/java/org/dbunit/util Added Files: CollectionsHelper.java SQLHelper.java Log Message: 1273949: addde filtering by PK feature --- NEW FILE: CollectionsHelper.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util; import java.util.Iterator; import java.util.Set; import org.apache.commons.collections.set.ListOrderedSet; /** * Helper for collections-related methods. * <br> * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Nov 5, 2005 * */ public class CollectionsHelper { // class is "static" private CollectionsHelper() {} /** * Returns a Set from an array of objects. * Note the Iterator returned by this Set mantains the order of the array. * @param objects array of objects * @return Set with the elements of the array or null if entry is null */ public static Set objectsToSet( Object[] objects ) { if ( objects == null ) { return null; } Set set = new ListOrderedSet(); for (int i = 0; i < objects.length; i++) { set.add(objects[i]); } return set; } /** * Returns an array of Objects from a Set. * @param a Set * @return array of Objects with the elements of the Set or null if set is null */ public static Object[] setToObjects( Set set ) { if ( set == null ) { return null; } Object[] objects = new Object[ set.size() ]; int i=0; for (Iterator iter = set.iterator(); iter.hasNext(); i++) { objects[i] = iter.next(); } return objects; } /** * Returns an array of Strings from a Set. * @param a Set of Strings * @return array of Strings with the elements of the Set or null if set is null */ public static String[] setToStrings( Set set ) { if ( set == null ) { return null; } String[] strings = new String[ set.size() ]; int i=0; for (Iterator iter = set.iterator(); iter.hasNext(); i++) { strings[i] = (String) iter.next(); } return strings; }; } --- NEW FILE: SQLHelper.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * Helper for SQL-related stuff. * <br> * TODO: testcases * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Nov 5, 2005 * */ public class SQLHelper { // class is "static" private SQLHelper() {} /** * Gets the primary column for a table. * @param conn connection with the database * @param table table name * @return name of primary column for a table (assuming it's just 1 column). * @throws SQLException raised while getting the meta data */ public static String getPrimaryKeyColumn( Connection conn, String table ) throws SQLException { DatabaseMetaData metadata = conn.getMetaData(); ResultSet rs = metadata.getPrimaryKeys( null, null, table ); rs.next(); String pkColumn = rs.getString(4); return pkColumn; } /** * Close a result set and a prepared statement, checking for null references. * @param rs result set to be closed * @param stmt prepared statement to be closed * @throws SQLException exception raised in either close() method */ public static void close(ResultSet rs, Statement stmt) throws SQLException { try { if ( rs != null ) { rs.close(); } } finally { close( stmt ); } } /** * Close a preparement statement, checking for null references. * @param rs result set to be closed * @param stmt statement to be closed * @throws SQLException exception raised while closing the statement */ public static void close(Statement stmt) throws SQLException { if ( stmt != null ) { stmt.close(); } } } |
From: <fel...@us...> - 2006-02-18 04:23:19
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/database/search In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/java/org/dbunit/database/search Modified Files: TablesDependencyHelper.java AbstractMetaDataBasedSearchCallback.java Added Files: ImportedKeysSearchCallbackFilteredByPKs.java ImportedAndExportedKeysSearchCallbackFilteredByPKs.java ForeignKeyRelationshipEdge.java Log Message: 1273949: addde filtering by PK feature --- NEW FILE: ImportedKeysSearchCallbackFilteredByPKs.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import java.sql.ResultSet; import java.util.Map; import org.dbunit.database.IDatabaseConnection; import org.dbunit.database.PrimaryKeyFilter; import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.util.search.IEdge; import org.dbunit.util.search.SearchException; /** * Extension of the ImportedKeysSearchCallback, where each new edge is added to a * PrimaryKeyFilter. * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 */ public class ImportedKeysSearchCallbackFilteredByPKs extends ImportedKeysSearchCallback { // primary key filter associated with the call back private final PrimaryKeyFilter pksFilter; /** * Default constructor. * @param connection database connection * @param allowedPKs map of allowed rows, based on the primary keys (key is the name * of a table; value is a Set with allowed primary keys for that table) */ public ImportedKeysSearchCallbackFilteredByPKs(IDatabaseConnection connection, Map allowedPKs) { super(connection); this.pksFilter = new PrimaryKeyFilter(connection, allowedPKs, false); } /** * Get the primary key filter associated with the call back * @return primary key filter associated with the call back */ public ITableFilter getFilter() { return this.pksFilter; } public void nodeAdded(Object node) throws SearchException { this.pksFilter.nodeAdded( node ); } protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException { ForeignKeyRelationshipEdge edge = createFKEdge( rs, type, from, to, fkColumn, pkColumn ); this.pksFilter.edgeAdded( edge ); return edge; } } --- NEW FILE: ImportedAndExportedKeysSearchCallbackFilteredByPKs.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import java.sql.ResultSet; import java.util.Map; import org.dbunit.database.IDatabaseConnection; import org.dbunit.database.PrimaryKeyFilter; import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.util.search.IEdge; import org.dbunit.util.search.SearchException; /** * Extension of the ImportedAndExportedKeysSearchCallback, where each new edge is * added to a PrimaryKeyFilter. * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 */ public class ImportedAndExportedKeysSearchCallbackFilteredByPKs extends ImportedAndExportedKeysSearchCallback { // primary key filter associated with the call back private final PrimaryKeyFilter pksFilter; /** * Default constructor. * @param connection database connection * @param allowedPKs map of allowed rows, based on the primary keys (key is the name * of a table; value is a Set with allowed primary keys for that table) */ public ImportedAndExportedKeysSearchCallbackFilteredByPKs(IDatabaseConnection connection, Map allowedPKs) { super(connection); this.pksFilter = new PrimaryKeyFilter(connection, allowedPKs, true ); } /** * Get the primary key filter associated with the call back * @return primary key filter associated with the call back */ public ITableFilter getFilter() { return this.pksFilter; } public void nodeAdded(Object node) throws SearchException { this.pksFilter.nodeAdded( node ); } protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException { ForeignKeyRelationshipEdge edge = createFKEdge( rs, type, from, to, fkColumn, pkColumn ); this.pksFilter.edgeAdded( edge ); return edge; } } --- NEW FILE: ForeignKeyRelationshipEdge.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import org.dbunit.util.search.Edge; /** * Implementation of an edge representing a foreign key (FK) relationship between two * tables.<br> * The <code>from</code> node is the table which have the FK, while the * <code>to</code> node is the table with the PK. In other words, the edge * A->B means FK(A) = PK(B).<br> * * <strong>NOTE:</strong> only single-column PKs are supported at this moment * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 */ public class ForeignKeyRelationshipEdge extends Edge { private String fkColumn; private String pkColumn; /** * Creates an edge representing a FK. * @param tableFrom table that has the FK * @param tableTo table that has the PK * @param fkColumn name of the FK column on tableFrom * @param pkColumn name of the PK column on tableTo */ public ForeignKeyRelationshipEdge(String tableFrom, String tableTo, String fkColumn, String pkColumn) { super(tableFrom, tableTo); this.fkColumn = fkColumn; this.pkColumn = pkColumn; } /** * Gets the name of the foreign key column in the relationship. * @return name of the foreign key column in the relationship. */ public String getFKColumn() { return fkColumn; } /** * Gets the name of the primary key column in the relationship. * @return name of the primary key column in the relationship. */ public String getPKColumn() { return pkColumn; } public String toString() { return getFrom() + "(" + getFKColumn() + ")->" + getTo() + "(" + getPKColumn() + ")"; } } Index: TablesDependencyHelper.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/database/search/TablesDependencyHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TablesDependencyHelper.java 18 Oct 2005 14:43:30 -0000 1.1 --- TablesDependencyHelper.java 18 Feb 2006 04:23:04 -0000 1.2 *************** *** 21,34 **** package org.dbunit.database.search; ! //import java.sql.SQLException; ! //import java.util.HashMap; ! //import java.util.Map; import java.util.Set; import org.dbunit.database.IDatabaseConnection; ! //import org.dbunit.dataset.FilteredDataSet; ! //import org.dbunit.dataset.IDataSet; ! //import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.util.search.DepthFirstSearch; import org.dbunit.util.search.SearchException; --- 21,35 ---- package org.dbunit.database.search; ! import java.sql.SQLException; ! import java.util.HashMap; ! import java.util.Map; import java.util.Set; import org.dbunit.database.IDatabaseConnection; ! import org.dbunit.dataset.FilteredDataSet; ! import org.dbunit.dataset.IDataSet; ! import org.dbunit.dataset.filter.ITableFilter; + import org.dbunit.util.CollectionsHelper; import org.dbunit.util.search.DepthFirstSearch; import org.dbunit.util.search.SearchException; *************** *** 75,79 **** DepthFirstSearch search = new DepthFirstSearch(); Set tables = search.search( rootTables, callback ); ! return (String[]) DepthFirstSearch.setToStrings( tables ); } --- 76,80 ---- DepthFirstSearch search = new DepthFirstSearch(); Set tables = search.search( rootTables, callback ); ! return (String[]) CollectionsHelper.setToStrings( tables ); } *************** *** 106,113 **** DepthFirstSearch search = new DepthFirstSearch(); Set tables = search.search( rootTables, callback ); ! return (String[]) DepthFirstSearch.setToStrings( tables ); } ! /* TODO: not used yet (but will on second patch) public static IDataSet getDataset( IDatabaseConnection connection, String rootTable, Set allowedIds ) throws SearchException, SQLException { HashMap map = new HashMap(1); --- 107,115 ---- DepthFirstSearch search = new DepthFirstSearch(); Set tables = search.search( rootTables, callback ); ! return (String[]) CollectionsHelper.setToStrings( tables ); } ! // TODO: javadoc (and unit tests) from down here... ! public static IDataSet getDataset( IDatabaseConnection connection, String rootTable, Set allowedIds ) throws SearchException, SQLException { HashMap map = new HashMap(1); *************** *** 120,126 **** ITableFilter filter = callback.getFilter(); DepthFirstSearch search = new DepthFirstSearch(); ! String[] tableNames = DepthFirstSearch.setToStrings( rootTables.keySet() ); Set tmpTables = search.search( tableNames, callback ); ! String[] dependentTables = DepthFirstSearch.setToStrings( tmpTables ); IDataSet tmpDataset = connection.createDataSet( dependentTables ); FilteredDataSet dataset = new FilteredDataSet(filter, tmpDataset); --- 122,128 ---- ITableFilter filter = callback.getFilter(); DepthFirstSearch search = new DepthFirstSearch(); ! String[] tableNames = CollectionsHelper.setToStrings( rootTables.keySet() ); Set tmpTables = search.search( tableNames, callback ); ! String[] dependentTables = CollectionsHelper.setToStrings( tmpTables ); IDataSet tmpDataset = connection.createDataSet( dependentTables ); FilteredDataSet dataset = new FilteredDataSet(filter, tmpDataset); *************** *** 128,134 **** } ! public static IDataSet getAllDataset( IDatabaseConnection connection, String rootTable, Set allowedIds ) throws SearchException, SQLException { HashMap map = new HashMap(1); ! map.put( rootTable, allowedIds ); return getAllDataset( connection, map ); } --- 130,136 ---- } ! public static IDataSet getAllDataset( IDatabaseConnection connection, String rootTable, Set allowedPKs ) throws SearchException, SQLException { HashMap map = new HashMap(1); ! map.put( rootTable, allowedPKs ); return getAllDataset( connection, map ); } *************** *** 138,150 **** ITableFilter filter = callback.getFilter(); DepthFirstSearch search = new DepthFirstSearch(); ! String[] tableNames = DepthFirstSearch.setToStrings( rootTables.keySet() ); Set tmpTables = search.search( tableNames, callback ); ! String[] dependentTables = DepthFirstSearch.setToStrings( tmpTables ); IDataSet tmpDataset = connection.createDataSet( dependentTables ); FilteredDataSet dataset = new FilteredDataSet(filter, tmpDataset); return dataset; } - */ - --- 140,150 ---- ITableFilter filter = callback.getFilter(); DepthFirstSearch search = new DepthFirstSearch(); ! String[] tableNames = CollectionsHelper.setToStrings( rootTables.keySet() ); Set tmpTables = search.search( tableNames, callback ); ! String[] dependentTables = CollectionsHelper.setToStrings( tmpTables ); IDataSet tmpDataset = connection.createDataSet( dependentTables ); FilteredDataSet dataset = new FilteredDataSet(filter, tmpDataset); return dataset; } Index: AbstractMetaDataBasedSearchCallback.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/database/search/AbstractMetaDataBasedSearchCallback.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AbstractMetaDataBasedSearchCallback.java 18 Oct 2005 14:43:30 -0000 1.1 --- AbstractMetaDataBasedSearchCallback.java 18 Feb 2006 04:23:04 -0000 1.2 *************** *** 137,142 **** throws SearchException { ! if ( super.logger.isTraceEnabled() ) { ! super.logger.trace("Getting edges for node " + node); } try { --- 137,142 ---- throws SearchException { ! if ( super.logger.isDebugEnabled() ) { ! super.logger.debug("Getting edges for node " + node); } try { *************** *** 161,166 **** String fkColumn = rs.getString( FK_INDEXES[type] ); IEdge edge = newEdge(rs, type, tableName, dependentTableName, fkColumn, pkColumn ); ! if ( super.logger.isTraceEnabled() ) { ! super.logger.trace("Adding edge " + edge); } edges.add(edge); --- 161,166 ---- String fkColumn = rs.getString( FK_INDEXES[type] ); IEdge edge = newEdge(rs, type, tableName, dependentTableName, fkColumn, pkColumn ); ! if ( super.logger.isDebugEnabled() ) { ! super.logger.debug("Adding edge " + edge); } edges.add(edge); *************** *** 172,180 **** } ! protected FKRelationshipEdge createFKEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException { return type == IMPORT ? ! new FKRelationshipEdge( from, to, fkColumn, pkColumn ) : ! new FKRelationshipEdge( to, from, fkColumn, pkColumn ); } --- 172,193 ---- } ! /** ! * Creates an edge representing a foreign key relationship between 2 tables.<br> ! * @param rs database meta-data result set ! * @param type type of relationship (IMPORT or EXPORT) ! * @param from name of the table representing the 'from' node ! * @param to name of the table representing the 'to' node ! * @param fkColumn name of the foreign key column ! * @param pkColumn name of the primary key column ! * @return edge representing the relationship between the 2 tables, according to ! * the type ! * @throws SearchException not thrown in this method (but might on sub-classes) ! */ ! protected static ForeignKeyRelationshipEdge createFKEdge(ResultSet rs, int type, ! String from, String to, String fkColumn, String pkColumn) throws SearchException { return type == IMPORT ? ! new ForeignKeyRelationshipEdge( from, to, fkColumn, pkColumn ) : ! new ForeignKeyRelationshipEdge( to, from, fkColumn, pkColumn ); } *************** *** 184,189 **** * the edge (for instance, providing an Edge that contains the primary and * foreign keys used). ! * ! * @throws SearchException exception wrapper */ protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) --- 197,209 ---- * the edge (for instance, providing an Edge that contains the primary and * foreign keys used). ! * @param rs database meta-data result set ! * @param type type of relationship (IMPORT or EXPORT) ! * @param from name of the table representing the 'from' node ! * @param to name of the table representing the 'to' node ! * @param fkColumn name of the foreign key column ! * @param pkColumn name of the primary key column ! * @return edge representing the relationship between the 2 tables, according to ! * the type ! * @throws SearchException not thrown in this method (but might on sub-classes) */ protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) |
From: <fel...@us...> - 2006-02-18 04:23:18
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/java/org/dbunit/database Added Files: PrimaryKeyFilteredTableWrapper.java PrimaryKeyFilter.java Log Message: 1273949: addde filtering by PK feature --- NEW FILE: PrimaryKeyFilteredTableWrapper.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITable; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.RowOutOfBoundsException; /** * This class is a wrapper for another table with the condition that only a subset * of the original table will be available - the subset is defined by the set of * primary keys that are allowed in the new table. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 */ public class PrimaryKeyFilteredTableWrapper implements ITable { /** reference to the original table being wrapped */ private final ITable originalTable; /** mapping of filtered rows, i.e, each entry on this list has the value of the index on the original table corresponding to the desired index. For instance, if the original table is: row PK Value 0 pk1 v1 1 pk2 v2 2 pk3 v3 3 pk4 v4 And the allowed PKs are pk2 and pk4, the new table should be: row PK Value 0 pk2 v2 1 pk4 v4 Consequently, the mapping will be {1, 3} */ private final List filteredRowsMapping; /** logger */ protected final Log logger = LogFactory.getLog(getClass()); /** * Creates a PKFilteredTable given an original table and the allowed primary keys * for that table. * @param table original table * @param allowedPKs primary keys allowed on the new table * @throws DataSetException if something happened while getting the information */ public PrimaryKeyFilteredTableWrapper(ITable table, Set allowedPKs) throws DataSetException { if ( table == null || allowedPKs == null ) { throw new IllegalArgumentException( "Constructor cannot receive null arguments" ); } this.originalTable = table; // sets the rows for the new table // NOTE: this conversion might be an issue for long tables, as it iterates for // all values of the original table and that might take time and memory leaks. // So, this mapping mechanism is a candidate for improvement: another alternative // would be to calculate the mapping on the fly, as getValue() is called (and in // this case, getRowCount() would be simply the sise of allowedPKs) this.filteredRowsMapping = setRows( allowedPKs ); } /** * This method is used to calculate the mapping between the rows of the original * and the filtered tables. * @param allowedPKs primary keys allowed in the new table * @return list of rows for the new table * @throws DataSetException */ private List setRows(Set allowedPKs) throws DataSetException { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "Setting rows for table " + this.originalTable.getTableMetaData().getTableName() ); } int allowedSize = allowedPKs.size(); int fullSize = this.originalTable.getRowCount(); List mapping = new ArrayList( allowedSize ); // TODO: support multi-columns PKs String pkColumn = this.originalTable.getTableMetaData().getPrimaryKeys()[0].getColumnName(); for ( int row=0; row<fullSize; row++ ) { Object pk = this.originalTable.getValue( row, pkColumn ); if ( allowedPKs.contains(pk) ) { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "Adding row " + row + " (pk=" + pk + ")" ); } mapping.add( new Integer(row) ); } else { if ( this.logger.isDebugEnabled() ) { this.logger.debug("Discarding row " + row + " (pk=" + pk + ")" ); } } } return mapping; } // ITable methods public ITableMetaData getTableMetaData() { return this.originalTable.getTableMetaData(); } public int getRowCount() { return this.filteredRowsMapping.size(); } public Object getValue(int row, String column) throws DataSetException { int max = this.filteredRowsMapping.size(); if ( row < max ) { int realRow = ((Integer) this.filteredRowsMapping.get( row )).intValue(); Object value = this.originalTable.getValue(realRow, column); return value; } else { throw new RowOutOfBoundsException( "tried to access row " + row + " but rowCount is " + max ); } } } --- NEW FILE: PrimaryKeyFilter.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; //TODO: should not have dependency on sub-package! import org.dbunit.database.search.ForeignKeyRelationshipEdge; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.ITable; import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.filter.AbstractTableFilter; import org.dbunit.util.SQLHelper; /** * Filter a table given a map of the allowed rows based on primary key values.<br> * It uses a depth-first algorithm (although not recursive - it might be refactored * in the future) to define which rows are allowed, as well which rows are necessary * (and hence allowed) because of dependencies with the allowed rows.<br> * <strong>NOTE:</strong> multi-column primary keys are not supported at the moment. * TODO: test cases * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 */ public class PrimaryKeyFilter extends AbstractTableFilter { private final IDatabaseConnection connection; private final Map allowedPKsPerTable; private final Map allowedPKsInput; private final Map pksToScanPerTable; private final boolean reverseScan; protected final Log logger = LogFactory.getLog(getClass()); // cache de primary keys private final Map pkColumnPerTable = new HashMap(); private final Map fkEdgesPerTable = new HashMap(); private final Map fkReverseEdgesPerTable = new HashMap(); // name of the tables, in reverse order of depedency private final List tableNames = new ArrayList(); /** * Default constructor, it takes as input a map with desired rows in a final * dataset; the filter will ensure that the rows necessary by these initial rows * are also allowed (and so on...). * @param connection database connection * @param allowedPKs map of allowed rows, based on the primary keys (key is the name * of a table; value is a Set with allowed primary keys for that table) * @param reverseDependency flag indicating if the rows that depend on a row should * also be allowed by the filter */ public PrimaryKeyFilter(IDatabaseConnection connection, Map allowedPKs, boolean reverseDependency) { this.connection = connection; this.allowedPKsPerTable = new HashMap(); this.allowedPKsInput = allowedPKs; this.reverseScan = reverseDependency; // we need a deep copy here // this.idsToScanPerTable = new HashMap(allowedIds); this.pksToScanPerTable = new HashMap(allowedPKs.size()); Iterator iterator = allowedPKs.entrySet().iterator(); while ( iterator.hasNext() ) { Map.Entry entry = (Map.Entry) iterator.next(); Object table = entry.getKey(); Set inputSet = (Set) entry.getValue(); Set newSet = new HashSet( inputSet ); this.pksToScanPerTable.put( table, newSet ); } } public void nodeAdded(Object node) { this.tableNames.add( node ); if ( this.logger.isDebugEnabled() ) { this.logger.debug("nodeAdded: " + node ); } } public void edgeAdded(ForeignKeyRelationshipEdge edge) { if ( this.logger.isDebugEnabled() ) { this.logger.debug("edgeAdded: " + edge ); } // first add it to the "direct edges" String from = (String) edge.getFrom(); Set edges = (Set) this.fkEdgesPerTable.get(from); if ( edges == null ) { edges = new HashSet(); this.fkEdgesPerTable.put( from, edges ); } if ( ! edges.contains(edge) ) { edges.add(edge); } // then add it to the "reverse edges" String to = (String) edge.getTo(); edges = (Set) this.fkReverseEdgesPerTable.get(to); if ( edges == null ) { edges = new HashSet(); this.fkReverseEdgesPerTable.put( to, edges ); } if ( ! edges.contains(edge) ) { edges.add(edge); } // finally, update the PKs cache Object pkTo = this.pkColumnPerTable.get( to ); if ( pkTo == null ) { Object pk = edge.getPKColumn(); this.pkColumnPerTable.put( to, pk ); } } /** * @see AbstractTableFilter */ public boolean isValidName(String tableName) throws DataSetException { // boolean isValid = this.allowedIds.containsKey(tableName); // return isValid; return true; } public ITableIterator iterator(IDataSet dataSet, boolean reversed) throws DataSetException { if ( this.logger.isDebugEnabled() ) { this.logger.debug("Filter.iterator()" ); } try { searchPKs(dataSet); } catch (SQLException e) { throw new DataSetException( e ); } return new FilterIterator(reversed ? dataSet.reverseIterator() : dataSet .iterator()); } private void searchPKs(IDataSet dataSet) throws DataSetException, SQLException { int counter = 0; while ( ! this.pksToScanPerTable.isEmpty() ) { counter ++; if ( this.logger.isDebugEnabled() ) { this.logger.debug( "RUN # " + counter ); } for ( int i=this.tableNames.size()-1; i>=0; i-- ) { String tableName = (String) this.tableNames.get(i); // TODO: support multi-column PKs String pkColumn = dataSet.getTable(tableName).getTableMetaData().getPrimaryKeys()[0].getColumnName(); Set tmpSet = (Set) this.pksToScanPerTable.get( tableName ); if ( tmpSet != null && ! tmpSet.isEmpty() ) { Set pksToScan = new HashSet( tmpSet ); if ( this.logger.isDebugEnabled() ) { this.logger.debug( "before search: "+ tableName + "=>" + pksToScan ); } scanPKs( tableName, pkColumn, pksToScan ); scanReversePKs( tableName, pksToScan ); allowPKs( tableName, pksToScan ); removePKsToScan( tableName, pksToScan ); } // if } // for removeScannedTables(); } // while if ( this.logger.isDebugEnabled() ) { this.logger.debug( "Finished searchIds()" ); } } private void removeScannedTables() { Iterator iterator = this.pksToScanPerTable.entrySet().iterator(); List tablesToRemove = new ArrayList(); while ( iterator.hasNext() ) { Map.Entry entry = (Map.Entry) iterator.next(); String table = (String) entry.getKey(); Set pksToScan = (Set) entry.getValue(); boolean removeIt = pksToScan.isEmpty(); if ( ! this.tableNames.contains(table) ) { if ( this.logger.isWarnEnabled() ) { this.logger.warn("Discarding ids " + pksToScan + " of table " + table + "as this table has not been passed as input" ); } removeIt = true; } if ( removeIt ) { tablesToRemove.add( table ); } } iterator = tablesToRemove.iterator(); while ( iterator.hasNext() ) { this.pksToScanPerTable.remove( iterator.next() ); } } private void allowPKs(String table, Set newAllowedPKs) { // first, obtain the current allowed ids for that table Set currentAllowedIds = (Set) this.allowedPKsPerTable.get( table ); if ( currentAllowedIds == null ) { currentAllowedIds = new HashSet(); this.allowedPKsPerTable.put( table, currentAllowedIds ); } // then, add the new ids, but checking if it should be allowed to add them Set forcedAllowedPKs = (Set) this.allowedPKsInput.get( table ); if ( forcedAllowedPKs == null || forcedAllowedPKs.isEmpty() ) { currentAllowedIds.addAll( newAllowedPKs ); } else { Iterator iterator = newAllowedPKs.iterator(); while ( iterator.hasNext() ) { Object id = iterator.next(); if ( forcedAllowedPKs.contains(id) ) { currentAllowedIds.add(id); } else { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "Discarding id " + id + " of table " + table + " as it was not included in the input!" ); } } } } } private void scanPKs( String table, String pkColumn, Set allowedIds ) throws SQLException { Set fkEdges = (Set) this.fkEdgesPerTable.get( table ); if ( fkEdges == null || fkEdges.isEmpty() ) { return; } // we need a temporary list as there is no warranty about the set order... List fkTables = new ArrayList( fkEdges.size() ); Iterator iterator = fkEdges.iterator(); StringBuffer colsBuffer = new StringBuffer(); while ( iterator.hasNext() ) { ForeignKeyRelationshipEdge edge = (ForeignKeyRelationshipEdge) iterator.next(); fkTables.add( edge.getTo() ); colsBuffer.append( edge.getFKColumn() ); if ( iterator.hasNext() ) { colsBuffer.append( ", " ); } } // NOTE: make sure the query below is compatible standard SQL String sql = "SELECT " + colsBuffer + " FROM " + table + " WHERE " + pkColumn + " = ? "; if ( this.logger.isDebugEnabled() ) { this.logger.debug( "SQL: " + sql ); } PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = this.connection.getConnection().prepareStatement( sql ); iterator = allowedIds.iterator(); while( iterator.hasNext() ) { Object pk = iterator.next(); // id being scanned if ( this.logger.isDebugEnabled() ) { this.logger.debug("Executing sql for ? = " + pk ); } pstmt.setObject( 1, pk ); rs = pstmt.executeQuery(); while( rs.next() ) { for ( int i=0; i<fkTables.size(); i++ ) { String newTable = (String) fkTables.get(i); Object fk = rs.getObject(i+1); if ( fk != null ) { if ( this.logger.isDebugEnabled() ) { this.logger.debug("New ID: " + newTable + "->" + fk ); } addPKToScan( newTable, fk ); } else { this.logger.warn( "Found null FK for relationship " + table + "=>" + newTable ); } } } } } catch (SQLException e) { SQLHelper.close( rs, pstmt ); } } private void scanReversePKs(String table, Set pksToScan) throws SQLException { if ( ! this.reverseScan ) { return; } Set fkReverseEdges = (Set) this.fkReverseEdgesPerTable.get( table ); if ( fkReverseEdges == null || fkReverseEdges.isEmpty() ) { return; } Iterator iterator = fkReverseEdges.iterator(); while ( iterator.hasNext() ) { ForeignKeyRelationshipEdge edge = (ForeignKeyRelationshipEdge) iterator.next(); addReverseEdge( edge, pksToScan ); } } private void addReverseEdge(ForeignKeyRelationshipEdge edge, Set idsToScan) throws SQLException { String fkTable = (String) edge.getFrom(); String fkColumn = edge.getFKColumn(); String pkColumn = getPKColumn( fkTable ); // NOTE: make sure the query below is compatible standard SQL String sql = "SELECT " + pkColumn + " FROM " + fkTable + " WHERE " + fkColumn + " = ? "; PreparedStatement pstmt = null; try { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "Preparing SQL query '" + sql + "'" ); } pstmt = this.connection.getConnection().prepareStatement( sql ); } catch (SQLException e) { SQLHelper.close( pstmt ); } ResultSet rs = null; Iterator iterator = idsToScan.iterator(); try { while ( iterator.hasNext() ) { Object pk = iterator.next(); if ( this.logger.isDebugEnabled() ) { this.logger.debug( "executing query '" + sql + "' for ? = " + pk ); } pstmt.setObject( 1, pk ); rs = pstmt.executeQuery(); while( rs.next() ) { Object fk = rs.getObject(1); addPKToScan( fkTable, fk ); } } } finally { SQLHelper.close( rs, pstmt ); } } // TODO: support PKs with multiple values private String getPKColumn( String table ) throws SQLException { String pkColumn = (String) this.pkColumnPerTable.get( table ); if ( pkColumn == null ) { pkColumn = SQLHelper.getPrimaryKeyColumn( this.connection.getConnection(), table ); this.pkColumnPerTable.put( table, pkColumn ); } return pkColumn; } private void removePKsToScan(String table, Set ids) { Set pksToScan = (Set) this.pksToScanPerTable.get(table); if ( pksToScan != null ) { if ( pksToScan == ids ) { throw new RuntimeException( "INTERNAL ERROR on removeIdsToScan() for table " + table ); } else { pksToScan.removeAll( ids ); } } } private void addPKToScan(String table, Object pk) { // first, check if it wasn't added yet Set scannedIds = (Set) this.allowedPKsPerTable.get( table ); if ( scannedIds != null && scannedIds.contains(pk)) { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "Discarding already scanned id=" + pk + " for table " + table ); } return; } Set pksToScan = (Set) this.pksToScanPerTable.get(table); if ( pksToScan == null ) { pksToScan = new HashSet(); this.pksToScanPerTable.put( table, pksToScan ); } pksToScan.add( pk ); } private class FilterIterator implements ITableIterator { private final ITableIterator _iterator; public FilterIterator(ITableIterator iterator) { _iterator = iterator; } //////////////////////////////////////////////////////////////////////////// // ITableIterator interface public boolean next() throws DataSetException { if ( logger.isDebugEnabled() ) { logger.debug("Iterator.next()" ); } while (_iterator.next()) { if (accept(_iterator.getTableMetaData().getTableName())) { return true; } } return false; } public ITableMetaData getTableMetaData() throws DataSetException { if ( logger.isDebugEnabled() ) { logger.debug("Iterator.getTableMetaData()" ); } return _iterator.getTableMetaData(); } public ITable getTable() throws DataSetException { if ( logger.isDebugEnabled() ) { logger.debug("Iterator.getTable()" ); } ITable table = _iterator.getTable(); String tableName = table.getTableMetaData().getTableName(); Set allowedPKs = (Set) allowedPKsPerTable.get( tableName ); if ( allowedPKs != null ) { return new PrimaryKeyFilteredTableWrapper(table, allowedPKs); } return table; } } } |
From: <fel...@us...> - 2006-02-18 04:23:17
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/test/org/dbunit/util Added Files: CollectionsHelperTest.java AllTests.java SQLHelperTest.java Log Message: 1273949: addde filtering by PK feature --- NEW FILE: CollectionsHelperTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; import org.apache.commons.collections.set.ListOrderedSet; import junit.framework.TestCase; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Nov 5, 2005 * */ public class CollectionsHelperTest extends TestCase { public static final String A = "A"; public static final String B = "B"; public static final String C = "C"; public CollectionsHelperTest( String testName ) { super( testName ); } public void testObjectsToSetNullEntry() { Set output = CollectionsHelper.objectsToSet( null ); assertNull( "set should be null", output ); } public void testObjectsToSetEmptyEntry() { Set output = CollectionsHelper.objectsToSet( new Object[0] ); assertNotNull( "set should not be null", output ); assertEquals( "set should be empty", 0, output.size() ); } public void testObjectsToSetSingleInput() { Object[] input = { A }; Set output = CollectionsHelper.objectsToSet( input ); assertNotNull( "set should not be null", output ); Iterator i = output.iterator(); assertTrue( "iterator is empty", i.hasNext() ); assertEquals( "element 0 match", A, i.next() ); assertFalse( "iterator is not empty", i.hasNext() ); } public void testObjectsToSetSequence() { Object[] input = { A, C, B }; Set output = CollectionsHelper.objectsToSet( input ); assertNotNull( "set should not be null", output ); Iterator i = output.iterator(); assertTrue( "iterator is empty", i.hasNext() ); assertEquals( "element 0 match", A, i.next() ); assertEquals( "element 1 match", C, i.next() ); assertEquals( "element 2 match", B, i.next() ); assertFalse( "iterator is not empty", i.hasNext() ); } public void testSetToObjectsNullEntry() { Object[] output = CollectionsHelper.setToObjects( null ); assertNull( "array should be null", output ); } public void testSetToObjectsEmptyEntry() { Set input = new HashSet(); Object[] output = CollectionsHelper.setToObjects( input ); assertNotNull( "array should not be null", output ); assertEquals( "array should be empty", 0, output.length ); } public void testSetToObjectsSingle() { Set input = new HashSet(); input.add( A ); Object[] output = CollectionsHelper.setToObjects( input ); assertNotNull( "array should not be null", output ); assertEquals( "array size does not match", 1, output.length ); assertEquals( "element 0 does not match", A, output[0] ); } public void testSetToObjectsOrderedSet() { Set input = new TreeSet(); input.add( A ); input.add( C ); input.add( B ); Object[] output = CollectionsHelper.setToObjects( input ); assertNotNull( "array should not be null", output ); assertEquals( "array size does not match", 3, output.length ); assertEquals( "element 0 does not match", A, output[0] ); assertEquals( "element 1 does not match", B, output[1] ); assertEquals( "element 2 does not match", C, output[2] ); } public void testSetToObjectsSequencialSet() { Set input = new ListOrderedSet(); input.add( A ); input.add( C ); input.add( B ); Object[] output = CollectionsHelper.setToObjects( input ); assertNotNull( "array should not be null", output ); assertEquals( "array size does not match", 3, output.length ); assertEquals( "element 0 does not match", A, output[0] ); assertEquals( "element 1 does not match", C, output[1] ); assertEquals( "element 2 does not match", B, output[2] ); } public void testSetToStringsNullEntry() { Object[] output = CollectionsHelper.setToStrings( null ); assertNull( "array should be null", output ); } public void testSetToStringsEmptyEntry() { Set input = new HashSet(); Object[] output = CollectionsHelper.setToStrings( input ); assertNotNull( "array should not be null", output ); assertEquals( "array should be empty", 0, output.length ); } public void testSetToStringsSingle() { Set input = new HashSet(); input.add( A ); String[] output = CollectionsHelper.setToStrings( input ); assertNotNull( "array should not be null", output ); assertEquals( "array size does not match", 1, output.length ); assertEquals( "element 0 does not match", A, output[0] ); } public void testSetToStringsOrderedSet() { Set input = new TreeSet(); input.add( A ); input.add( C ); input.add( B ); String[] output = CollectionsHelper.setToStrings( input ); assertNotNull( "array should not be null", output ); assertEquals( "array size does not match", 3, output.length ); assertEquals( "element 0 does not match", A, output[0] ); assertEquals( "element 1 does not match", B, output[1] ); assertEquals( "element 2 does not match", C, output[2] ); } public void testSetToStringsSequencialSet() { Set input = new ListOrderedSet(); input.add( A ); input.add( C ); input.add( B ); String[] output = CollectionsHelper.setToStrings( input ); assertNotNull( "array should not be null", output ); assertEquals( "array size does not match", 3, output.length ); assertEquals( "element 0 does not match", A, output[0] ); assertEquals( "element 1 does not match", C, output[1] ); assertEquals( "element 2 does not match", B, output[2] ); } } --- NEW FILE: AllTests.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util; import junit.framework.Test; import junit.framework.TestSuite; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Nov 5, 2005 * */ public class AllTests { public static Test suite() throws Exception { TestSuite suite = new TestSuite(); suite.addTest(new TestSuite(CollectionsHelperTest.class)); return suite; } } --- NEW FILE: SQLHelperTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util; import java.sql.Connection; import java.sql.SQLException; import org.dbunit.AbstractHSQLTestCase; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Nov 5, 2005 */ public class SQLHelperTest extends AbstractHSQLTestCase { public SQLHelperTest( String name ) { super( name, "hypersonic_dataset.sql" ); } public void testGetPrimaryKeyColumn() throws SQLException { String[] tables = { "A", "B", "C", "D", "E", "F", "G", "H" }; Connection conn = getConnection().getConnection(); assertNotNull( "didn't get a connection", conn ); for (int i = 0; i < tables.length; i++) { String table = tables[i]; String expectedPK = "PK" + table; String actualPK = SQLHelper.getPrimaryKeyColumn( conn, table ); assertNotNull( actualPK ); assertEquals( "primary key column for table " + table + " does not match", expectedPK, actualPK ); } } } |
From: <fel...@us...> - 2006-02-18 04:23:17
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/test/org/dbunit/database Modified Files: AllTests.java Added Files: AbstractImportedAndExportedKeysFilteredByPKsTestCase.java AbstractImportedKeysFilteredByPKsTestCase.java AbstractSearchCallbackFilteredByPKsTestCase.java PrimaryKeyFilteredTableWrapperTest.java Log Message: 1273949: addde filtering by PK feature --- NEW FILE: AbstractImportedAndExportedKeysFilteredByPKsTestCase.java --- package org.dbunit.database; import java.sql.SQLException; import org.dbunit.database.search.TablesDependencyHelper; import org.dbunit.dataset.IDataSet; import org.dbunit.util.search.SearchException; public abstract class AbstractImportedAndExportedKeysFilteredByPKsTestCase extends AbstractSearchCallbackFilteredByPKsTestCase { public AbstractImportedAndExportedKeysFilteredByPKsTestCase(String testName, String sqlFile) { super(testName, sqlFile); } protected IDataSet getDataset() throws SQLException, SearchException { IDataSet dataset = TablesDependencyHelper.getAllDataset( getConnection(), getInput() ); return dataset; } } --- NEW FILE: AbstractImportedKeysFilteredByPKsTestCase.java --- package org.dbunit.database; import java.sql.SQLException; import org.dbunit.dataset.IDataSet; import org.dbunit.database.search.TablesDependencyHelper; import org.dbunit.util.search.SearchException; public abstract class AbstractImportedKeysFilteredByPKsTestCase extends AbstractSearchCallbackFilteredByPKsTestCase { public AbstractImportedKeysFilteredByPKsTestCase(String testName, String sqlFile) { super(testName, sqlFile); } protected IDataSet getDataset() throws SQLException, SearchException { //TODO IDataSet dataset = TablesDependencyHelper.getAllDataset( getConnection(), getInput() ); IDataSet dataset = TablesDependencyHelper.getDataset( getConnection(), getInput() ); return dataset; } } --- NEW FILE: AbstractSearchCallbackFilteredByPKsTestCase.java --- package org.dbunit.database; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import junitx.framework.ListAssert; import org.dbunit.database.IDatabaseConnection; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.ITable; import org.dbunit.dataset.ITableIterator; import org.dbunit.AbstractHSQLTestCase; import org.dbunit.util.CollectionsHelper; import org.dbunit.util.search.SearchException; public abstract class AbstractSearchCallbackFilteredByPKsTestCase extends AbstractHSQLTestCase { private static final char FIRST_TABLE = 'A'; private Map fInput = new HashMap(); private Map fOutput = new HashMap(); public AbstractSearchCallbackFilteredByPKsTestCase(String testName, String sqlFile) { super(testName, sqlFile); } protected abstract int[] setupTablesSizeFixture(); protected IDataSet setupTablesDataSetFixture() throws SQLException { IDatabaseConnection connection = getConnection(); IDataSet allDataSet = connection.createDataSet(); return allDataSet; } protected void addInput(String tableName, String[] ids) { Set idsSet = CollectionsHelper.objectsToSet( ids ); this.fInput.put( tableName, idsSet ); } protected void addOutput(String tableName, String[] ids) { List idsList = Arrays.asList( ids ); this.fOutput.put( tableName, idsList ); } protected abstract IDataSet getDataset() throws SQLException, SearchException; protected void doIt() throws SQLException, DataSetException, SearchException { IDataSet dataset = getDataset(); assertNotNull( dataset ); // primeiro, checa se somente as tabelas corretas foram geradas String[] outputTables = dataset.getTableNames(); assertTablesSize( outputTables ); assertTablesName( outputTables ); assertRows( dataset ); } protected void assertTablesSize(String[] actualTables) { int expectedSize = this.fOutput.size(); int actualSize = actualTables.length; if ( expectedSize != actualSize ) { super.logger.error( "Tabelas esperadas: " + dump(this.fOutput.keySet()) ); super.logger.error( "Tabelas retornadas: " + dump(actualTables) ); fail( "numero de tabelas retornadas nao bateu: " + actualSize + " em vez de " + expectedSize ); } } protected void assertTablesName(String[] outputTables) { Set expectedTables = new HashSet(this.fOutput.keySet()); Set notExpectedTables = new HashSet(); boolean ok = true; // primeiro ve quais estao faltando for (int i = 0; i < outputTables.length; i++) { String table = outputTables[i]; if ( expectedTables.contains(table) ) { expectedTables.remove(table); } else { notExpectedTables.add(table); } } if ( ! notExpectedTables.isEmpty() ) { ok = false; super.logger.error( "Tabelas retornadas nao esperadas: " + dump(notExpectedTables) ); } if ( ! expectedTables.isEmpty() ) { ok = false; super.logger.error( "Tabelas esperadas nao retornadas: " + dump(expectedTables) ); } if ( ! ok ) { fail( "Tabelas retornadas nao batem com a expectativa; check o error output" ); } } protected void assertRows(IDataSet dataset) throws DataSetException { ITableIterator iterator = dataset.iterator(); while (iterator.next()) { ITable table = iterator.getTable(); String tableName = table.getTableMetaData().getTableName(); String idField = "PK" + tableName; List expectedIds = (List) this.fOutput.get( tableName ); List actualIds = new ArrayList(); int rowCount = table.getRowCount(); for( int row=0; row<rowCount; row++ ) { String id = (String) table.getValue( row, idField ); actualIds.add( id ); if ( super.logger.isDebugEnabled() ) { super.logger.debug( "T:" + tableName + " row: " + row + " id: " + id ); } } Collections.sort( expectedIds ); Collections.sort( actualIds ); ListAssert.assertEquals( "ids para tabela " + tableName + " nao batem", expectedIds, actualIds ); } } public void testSetupTables() throws SQLException, DataSetException { int[] sizes = setupTablesSizeFixture(); IDataSet allDataSet = setupTablesDataSetFixture(); assertNotNull( allDataSet ); for (short i = 0; i < sizes.length; i++) { char table = (char) (FIRST_TABLE + i); if ( super.logger.isDebugEnabled() ) { super.logger.debug( "Obtendo tabela " + table ); } ITable itable = allDataSet.getTable( ""+table ); assertNotNull( "nao encontrou tabela " + table, itable ); assertEquals( "tamanho nao bateu para tabela " + table, sizes[i], itable.getRowCount()); } } protected Map getInput() { return this.fInput; } protected Map getOutput() { return this.fOutput; } } --- NEW FILE: PrimaryKeyFilteredTableWrapperTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database; import java.util.HashSet; import java.util.Set; import org.dbunit.AbstractHSQLTestCase; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.ITable; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.RowOutOfBoundsException; import org.dbunit.util.CollectionsHelper; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Sep 9, 2005 */ public class PrimaryKeyFilteredTableWrapperTest extends AbstractHSQLTestCase { private ITable fTable; //fixture private IDataSet fDataSet; //fixture public PrimaryKeyFilteredTableWrapperTest( String name ) { super( name, "hypersonic_dataset.sql" ); } protected void setUp() throws Exception { super.setUp(); this.fDataSet = super.getConnection().createDataSet(); this.fTable = this.fDataSet.getTable(E); } public void testConstructorNullTable() throws DataSetException { try { PrimaryKeyFilteredTableWrapper table = new PrimaryKeyFilteredTableWrapper( null, new HashSet() ); fail( "constructor accepted null argument and returned " + table ); } catch( IllegalArgumentException e ) { assertNotNull( e.getMessage() ); } } public void testConstructorNullSet() throws DataSetException { try { PrimaryKeyFilteredTableWrapper table = new PrimaryKeyFilteredTableWrapper( this.fTable, null ); fail( "constructor accepted null argument and returned " + table ); } catch( IllegalArgumentException e ) { assertNotNull( e.getMessage() ); } } public void testDenyEverything() throws DataSetException { PrimaryKeyFilteredTableWrapper table = new PrimaryKeyFilteredTableWrapper( this.fTable, new HashSet() ); assertMetaInformationEquals( this.fTable, table ); assertEquals( "table not empty", 0, table.getRowCount() ); assertSecondTableIsEmpty( this.fTable, table ); } public void testAllowEverything() throws DataSetException { Set allowedPKs = getPKs( this.fTable ); allowEveryThingTest( allowedPKs ); } public void testAllowEverythingWithClonedSet() throws DataSetException { Set allowedPKs = getPKs( this.fTable ); Set newSet = new HashSet( allowedPKs ); allowEveryThingTest( newSet ); } public void testFilterLast() throws DataSetException { doFilter( new String[] { E1, E2, E3 } ); } public void testFilterFirst() throws DataSetException { doFilter( new String[] { E2, E3, E4 } ); } public void testFilterMiddle() throws DataSetException { doFilter( new String[] { E1, E4 } ); } private void doFilter( String[] ids) throws DataSetException { Set allowedIds = CollectionsHelper.objectsToSet(ids); ITable table = new PrimaryKeyFilteredTableWrapper( this.fTable, allowedIds ); assertEquals( "size of table does not match", ids.length, table.getRowCount() ); String pkColumn = table.getTableMetaData().getPrimaryKeys()[0].getColumnName(); int size = table.getRowCount(); for ( int i=0; i<size; i++ ) { Object pk = table.getValue( i, pkColumn ); assertEquals( "id didn't match at index " + i, ids[i], pk ); } } private void allowEveryThingTest( Set set ) throws DataSetException { PrimaryKeyFilteredTableWrapper table = new PrimaryKeyFilteredTableWrapper( this.fTable, new HashSet(set) ); assertTableSize( this.fTable, set.size() ); assertMetaInformationEquals( this.fTable, table ); assertTrue( "table is empty", table.getRowCount() > 0 ); assertContentIsSame( this.fTable, table ); } private void assertTableSize(ITable table, int i) { int size = table.getRowCount(); assertEquals( "getRowCount() didn't match", i, size ); } private Set getPKs(ITable table) throws DataSetException { String pkColumn = table.getTableMetaData().getPrimaryKeys()[0].getColumnName(); HashSet set = new HashSet(); int size = table.getRowCount(); for ( int i=0; i<size; i++ ) { Object pk = table.getValue( i, pkColumn ); set.add( pk ); } return set; } private void assertSecondTableIsEmpty(ITable t1, ITable t2) throws DataSetException { int size = t1.getRowCount(); Column[] cols = t1.getTableMetaData().getColumns(); for ( int i=0; i<size; i++ ) { for ( int j=0; j<cols.length; j++ ) { String col = cols[j].getColumnName(); try { Object o = t2.getValue( j, col ); fail( "there is an element at (" + i + ", " + col + ")" + o); } catch ( RowOutOfBoundsException e ) { assertNotNull( e.getMessage() ); } } } } private void assertContentIsSame(ITable t1, ITable t2) throws DataSetException { int size = t1.getRowCount(); Column[] cols = t1.getTableMetaData().getColumns(); for ( int i=0; i<size; i++ ) { for ( int j=0; j<cols.length; j++ ) { String col = cols[j].getColumnName(); Object o1 = t1.getValue( j, col ); Object o2 = t2.getValue( j, col ); assertEquals( "element at (" + i + ", " + col + ") is not the same: ", o1, o2); } } } private void assertMetaInformationEquals(ITable t1, ITable t2) { ITableMetaData metaData1 = t1.getTableMetaData(); ITableMetaData metaData2 = t2.getTableMetaData(); assertEquals( "metadata are not equal", metaData1, metaData2 ); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/database/AllTests.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** AllTests.java 10 May 2004 23:33:44 -0000 1.15 --- AllTests.java 18 Feb 2006 04:23:04 -0000 1.16 *************** *** 24,27 **** --- 24,28 ---- import junit.framework.Test; import junit.framework.TestSuite; + import org.dbunit.DatabaseEnvironment; import org.dbunit.TestFeature; *************** *** 45,48 **** --- 46,50 ---- suite.addTest(new TestSuite(ForwardOnlyResultSetTableTest.class)); suite.addTest(new TestSuite(QueryDataSetTest.class)); + suite.addTest(new TestSuite(PrimaryKeyFilteredTableWrapperTest.class)); DatabaseEnvironment environment = DatabaseEnvironment.getInstance(); |
Update of /cvsroot/dbunit/dbunit/src/sql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6160/src/sql Added Files: hypersonic_cyclic_dataset.sql hypersonic_dataset.sql hypersonic_simple_input_dataset.sql hypersonic_simple_dataset.sql Log Message: 1273949: addde filtering by PK feature --- NEW FILE: hypersonic_cyclic_dataset.sql --- CREATE TABLE A (PKA CHAR(2), FKB CHAR(2), PRIMARY KEY (PKA)); CREATE TABLE B (PKB CHAR(2), FKC CHAR(2), PRIMARY KEY (PKB)); CREATE TABLE C (PKC CHAR(2), FKA CHAR(2), PRIMARY KEY (PKC)); INSERT INTO A VALUES ( 'A1', 'B1' ); INSERT INTO A VALUES ( 'A2', 'B1' ); INSERT INTO B VALUES ( 'B1', 'C1' ); INSERT INTO C VALUES ( 'C1', 'A2' ); ALTER TABLE A ADD CONSTRAINT AB FOREIGN KEY (FKB) REFERENCES B (PKB); ALTER TABLE C ADD CONSTRAINT CA FOREIGN KEY (FKA) REFERENCES A (PKA); ALTER TABLE B ADD CONSTRAINT BC FOREIGN KEY (FKC) REFERENCES C (PKC); --- NEW FILE: hypersonic_dataset.sql --- CREATE TABLE A (PKA CHAR(2), FKD CHAR(2), PRIMARY KEY (PKA)); CREATE TABLE B (PKB CHAR(2), FKC CHAR(2), FKE CHAR(2), FKH CHAR(2), PRIMARY KEY (PKB)); CREATE TABLE C (PKC CHAR(2), FKA CHAR(2), FKF CHAR(2), PRIMARY KEY (PKC)); CREATE TABLE D (PKD CHAR(2), FKD CHAR(2), PRIMARY KEY (PKD)); CREATE TABLE E (PKE CHAR(2), FKA CHAR(2), FKG CHAR(2), PRIMARY KEY (PKE)); CREATE TABLE F (PKF CHAR(2), FKD CHAR(2), PRIMARY KEY (PKF)); CREATE TABLE G (PKG CHAR(2), FKA CHAR(2), PRIMARY KEY (PKG)); CREATE TABLE H (PKH CHAR(2), PRIMARY KEY (PKH)); ALTER TABLE A ADD CONSTRAINT AD FOREIGN KEY (FKD) REFERENCES D (PKD); ALTER TABLE B ADD CONSTRAINT BC FOREIGN KEY (FKC) REFERENCES C (PKC); ALTER TABLE B ADD CONSTRAINT BE FOREIGN KEY (FKE) REFERENCES E (PKE); ALTER TABLE B ADD CONSTRAINT BH FOREIGN KEY (FKH) REFERENCES H (PKH); ALTER TABLE C ADD CONSTRAINT CA FOREIGN KEY (FKA) REFERENCES A (PKA); ALTER TABLE C ADD CONSTRAINT CF FOREIGN KEY (FKF) REFERENCES F (PKF); ALTER TABLE D ADD CONSTRAINT DD FOREIGN KEY (FKD) REFERENCES D (PKD); ALTER TABLE E ADD CONSTRAINT EA FOREIGN KEY (FKA) REFERENCES A (PKA); ALTER TABLE E ADD CONSTRAINT EG FOREIGN KEY (FKG) REFERENCES G (PKG); ALTER TABLE F ADD CONSTRAINT FD FOREIGN KEY (FKD) REFERENCES D (PKD); ALTER TABLE G ADD CONSTRAINT GA FOREIGN KEY (FKA) REFERENCES A (PKA); INSERT INTO D VALUES ('D1', 'D1'); INSERT INTO D VALUES ('D2', 'D1'); INSERT INTO A VALUES ('A1','D1'); INSERT INTO A VALUES ('A2','D2'); INSERT INTO F VALUES ('F1','D1'); INSERT INTO F VALUES ('F2','D2'); INSERT INTO C VALUES ('C1','A1','F1'); INSERT INTO C VALUES ('C2','A1','F2'); INSERT INTO C VALUES ('C3','A2','F1'); INSERT INTO C VALUES ('C4','A2','F2'); INSERT INTO G VALUES ('G1','A1'); INSERT INTO G VALUES ('G2','A2'); INSERT INTO E VALUES ('E1','A1','G1'); INSERT INTO E VALUES ('E2','A1','G2'); INSERT INTO E VALUES ('E3','A2','G1'); INSERT INTO E VALUES ('E4','A2','G2'); INSERT INTO H VALUES ('H1'); INSERT INTO H VALUES ('H2'); INSERT INTO B VALUES ('B1','C1','E1','H1'); INSERT INTO B VALUES ('B2','C1','E1','H2'); INSERT INTO B VALUES ('B3','C1','E2','H1'); INSERT INTO B VALUES ('B4','C1','E2','H2'); INSERT INTO B VALUES ('B5','C2','E1','H1'); INSERT INTO B VALUES ('B6','C2','E1','H2'); INSERT INTO B VALUES ('B7','C2','E2','H1'); INSERT INTO B VALUES ('B8','C2','E2','H2'); /* Tabelas para testar o filtro de datasets. Dependencias diretas: B1 => C1, E1, H1 C1 => A1, F1 E1 => A1, G1 H1 => none A1 => D1 D1 => D1 G1 => A1 F1 => D1 */ --- NEW FILE: hypersonic_simple_input_dataset.sql --- CREATE TABLE A (PKA CHAR(2), FKB CHAR(2), PRIMARY KEY (PKA)); CREATE TABLE B (PKB CHAR(2), PRIMARY KEY (PKB)); ALTER TABLE A ADD CONSTRAINT AB FOREIGN KEY (FKB) REFERENCES B (PKB); INSERT INTO B VALUES ('B1'); INSERT INTO A VALUES ('A1','B1'); INSERT INTO A VALUES ('A2','B1'); --- NEW FILE: hypersonic_simple_dataset.sql --- CREATE TABLE A (PKA CHAR(2), FKB CHAR(2), FKC CHAR(2), PRIMARY KEY (PKA)); CREATE TABLE B (PKB CHAR(2), FKC CHAR(2), PRIMARY KEY (PKB)); CREATE TABLE C (PKC CHAR(2), PRIMARY KEY (PKC)); ALTER TABLE A ADD CONSTRAINT AB FOREIGN KEY (FKB) REFERENCES B (PKB); ALTER TABLE A ADD CONSTRAINT AC FOREIGN KEY (FKC) REFERENCES C (PKC); ALTER TABLE B ADD CONSTRAINT BC FOREIGN KEY (FKC) REFERENCES C (PKC); INSERT INTO C VALUES ('C1'); INSERT INTO C VALUES ('C2'); INSERT INTO B VALUES ('B1', 'C2'); INSERT INTO A VALUES ('A1','B1', 'C1'); |
From: <fel...@us...> - 2006-02-17 20:22:57
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv670/src/java/org/dbunit/dataset/xml Modified Files: XmlDataSetWriter.java Log Message: XmlDataSetWriter now has a flag to include column's name as comment Index: XmlDataSetWriter.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/XmlDataSetWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** XmlDataSetWriter.java 15 Mar 2004 16:44:18 -0000 1.5 --- XmlDataSetWriter.java 17 Feb 2006 20:22:52 -0000 1.6 *************** *** 2,6 **** * * The DbUnit Database Testing Framework ! * Copyright (C)2002-2004, DbUnit.org * * This library is free software; you can redistribute it and/or --- 2,6 ---- * * The DbUnit Database Testing Framework ! * Copyright (C)2002-2006, DbUnit.org * * This library is free software; you can redistribute it and/or *************** *** 172,176 **** String columnName = columns[i].getColumnName(); Object value = values[i]; ! // null if (value == null) --- 172,176 ---- String columnName = columns[i].getColumnName(); Object value = values[i]; ! // null if (value == null) *************** *** 197,201 **** else if (stringValue.length() > 0) { ! _xmlWriter.writeText(stringValue); } _xmlWriter.endElement(); --- 197,201 ---- else if (stringValue.length() > 0) { ! _xmlWriter.writeText( stringValue ); } _xmlWriter.endElement(); *************** *** 209,214 **** } } } - _xmlWriter.endElement(); } --- 209,216 ---- } } + if ( this.includeColumnComments ) { + _xmlWriter.writeComment( columnName ); + } } _xmlWriter.endElement(); } *************** *** 218,220 **** --- 220,228 ---- } } + + private boolean includeColumnComments = false; + + public void setIncludeColumnComments(boolean b) { + this.includeColumnComments = b; + } } |
From: <fel...@us...> - 2006-02-17 20:22:56
|
Update of /cvsroot/dbunit/dbunit/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv670/xdocs Modified Files: changes.xml Log Message: XmlDataSetWriter now has a flag to include column's name as comment Index: changes.xml =================================================================== RCS file: /cvsroot/dbunit/dbunit/xdocs/changes.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** changes.xml 18 Oct 2005 14:43:30 -0000 1.22 --- changes.xml 17 Feb 2006 20:22:52 -0000 1.23 *************** *** 8,16 **** <body> ! <release version="2.2" date="IN CVS" description=""> ! <action dev="dep4b" type="remove" issue="1273949">Remove deprecated org.dbunit.operation.mssqlserver.InsertIdentityOperation. Please use o.d.ext.mssql.InsertIdentityOperation</action> ! <action dev="dep4b" due-to="Felipe Leme" type="fix" issue="1273949">Refactor <code>DatabaseSequenceFilter</code> to use the new depth-first algorithm - fixed the cyclic dependencies issue.</action> ! <action dev="dep4b" due-to="Felipe Leme" type="add" issue="1273949">Add packages <code>org.dbunit.util.search</code> and <code>org.dbunit.database.search</code>, which provides a depth-first algorithm which is used to find the dependency on tables relationshipts</action> ! <action dev="dep4b" due-to="Reuben Firmin" type="fix" issue="1328956">NPE In InsertIdentityOperation.</action> <action dev="dep4b" due-to="John Lewis" type="add" issue="1264212">Add "transaction" attribute to ant tasks to wrap operations in a single transaction. Can make operations faster.</action> <action dev="dep4b" due-to="Jeremy Frens" type="fix">Typo in howto example</action> --- 8,13 ---- <body> ! <release version="2.2" date="IN CVS" description=""> ! <action dev="felipeal" type="add"><code>XmlDataSetWriter</code> now has a flag to include column's name as comment.</action> <action dev="dep4b" due-to="John Lewis" type="add" issue="1264212">Add "transaction" attribute to ant tasks to wrap operations in a single transaction. Can make operations faster.</action> <action dev="dep4b" due-to="Jeremy Frens" type="fix">Typo in howto example</action> *************** *** 154,158 **** </action> <action dev="" type="update"> ! Moved `Operation to "org.dbunit.ext.mssql" package to be consistent with other vendor extensions. Temporary keep a deprecated copy in "org.dbunit.operation.mssqlserver" to ease transition to DbUnit 2. </action> </release> --- 151,155 ---- </action> <action dev="" type="update"> ! Moved InsertIdentityOperation to "org.dbunit.ext.mssql" package to be consistent with other vendor extensions. Temporary keep a deprecated copy in "org.dbunit.operation.mssqlserver" to ease transition to DbUnit 2. </action> </release> |
From: <fel...@us...> - 2006-02-17 20:22:56
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv670/src/test/org/dbunit/dataset/xml Modified Files: AllTests.java XmlDataSetWriterTest.java Log Message: XmlDataSetWriter now has a flag to include column's name as comment Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml/AllTests.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** AllTests.java 17 Feb 2006 20:05:23 -0000 1.11 --- AllTests.java 17 Feb 2006 20:22:52 -0000 1.12 *************** *** 2,6 **** * * The DbUnit Database Testing Framework ! * Copyright (C)2002-2004, DbUnit.org * * This library is free software; you can redistribute it and/or --- 2,6 ---- * * The DbUnit Database Testing Framework ! * Copyright (C)2002-2006, DbUnit.org * * This library is free software; you can redistribute it and/or Index: XmlDataSetWriterTest.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml/XmlDataSetWriterTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XmlDataSetWriterTest.java 17 Feb 2006 20:05:23 -0000 1.1 --- XmlDataSetWriterTest.java 17 Feb 2006 20:22:52 -0000 1.2 *************** *** 2,6 **** * * The DbUnit Database Testing Framework ! * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or --- 2,6 ---- * * The DbUnit Database Testing Framework ! * Copyright (C)2005-2006, DbUnit.org * * This library is free software; you can redistribute it and/or *************** *** 98,101 **** --- 98,135 ---- } + public void testWriteWithComments() throws Exception + { + String expectedOutput = + "<dataset>\n" + + " <table name=\"TABLE1\">\n" + + " <column>COL0</column>\n" + + " <column>COL1</column>\n" + + " <row>\n" + + " <value>t1v1</value>\n" + + " <!-- COL0 -->\n" + + " <value>t1v2</value>\n" + + " <!-- COL1 -->\n" + + " </row>\n" + + " </table>\n" + + " <table name=\"TABLE2\">\n" + + " <column>COL0</column>\n" + + " <column>COL1</column>\n" + + " <row>\n" + + " <value>t2v1</value>\n" + + " <!-- COL0 -->\n" + + " <value>t2v2</value>\n" + + " <!-- COL1 -->\n" + + " </row>\n" + + " </table>\n" + + "</dataset>\n"; + StringWriter stringWriter = new StringWriter(); + XmlDataSetWriter xmlWriter = new XmlDataSetWriter(stringWriter); + xmlWriter.setIncludeColumnComments(true); + IDataSet dataSet = getDefaultDataSet(); + xmlWriter.write( dataSet ); + + String actualOutput = stringWriter.toString(); + assertEquals("output", expectedOutput, actualOutput); + } } |
From: <fel...@us...> - 2006-02-17 20:05:30
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24996/src/test/org/dbunit/dataset/xml Modified Files: AllTests.java Added Files: XmlDataSetWriterTest.java Log Message: added test cases --- NEW FILE: XmlDataSetWriterTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import java.io.StringWriter; import junit.framework.TestCase; import org.dbunit.dataset.Column; import org.dbunit.dataset.DefaultDataSet; import org.dbunit.dataset.DefaultTable; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.datatype.DataType; /** * * @author Felipe Leme * @version $Id: XmlDataSetWriterTest.java,v 1.1 2006/02/17 20:05:23 felipeal Exp $ * @since Sep 9, 2005$ */ public class XmlDataSetWriterTest extends TestCase { public XmlDataSetWriterTest(String name) { super(name); } protected IDataSet getDefaultDataSet() throws Exception { String col0 = "COL0"; String col1 = "COL1"; Column[] columns = new Column[]{ new Column(col0, DataType.UNKNOWN), new Column(col1, DataType.UNKNOWN) }; DefaultTable table1 = new DefaultTable("TABLE1", columns); table1.addRow(); table1.setValue(0, col0, "t1v1"); table1.setValue(0, col1, "t1v2"); DefaultTable table2 = new DefaultTable("TABLE2", columns); table2.addRow(); table2.setValue(0, col0, "t2v1"); table2.setValue(0, col1, "t2v2"); IDataSet dataSet = new DefaultDataSet(table1, table2); return dataSet; } public void testWrite() throws Exception { String expectedOutput = "<dataset>\n" + " <table name=\"TABLE1\">\n" + " <column>COL0</column>\n" + " <column>COL1</column>\n" + " <row>\n" + " <value>t1v1</value>\n" + " <value>t1v2</value>\n" + " </row>\n" + " </table>\n" + " <table name=\"TABLE2\">\n" + " <column>COL0</column>\n" + " <column>COL1</column>\n" + " <row>\n" + " <value>t2v1</value>\n" + " <value>t2v2</value>\n" + " </row>\n" + " </table>\n" + "</dataset>\n"; StringWriter stringWriter = new StringWriter(); XmlDataSetWriter xmlWriter = new XmlDataSetWriter(stringWriter); IDataSet dataSet = getDefaultDataSet(); xmlWriter.write( dataSet ); String actualOutput = stringWriter.toString(); assertEquals("output", expectedOutput, actualOutput); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml/AllTests.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AllTests.java 26 Jan 2004 23:37:49 -0000 1.10 --- AllTests.java 17 Feb 2006 20:05:23 -0000 1.11 *************** *** 43,46 **** --- 43,47 ---- suite.addTest(new TestSuite(FlatXmlWriterTest.class)); suite.addTest(new TestSuite(XmlDataSetTest.class)); + suite.addTest(new TestSuite(XmlDataSetWriterTest.class)); suite.addTest(new TestSuite(XmlTableTest.class)); suite.addTest(new TestSuite(XmlTableWriteTest.class)); |
From: <fel...@us...> - 2006-02-17 19:25:35
|
Update of /cvsroot/dbunit/dbunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5377 Modified Files: project.xml Log Message: added myself as developer Index: project.xml =================================================================== RCS file: /cvsroot/dbunit/dbunit/project.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** project.xml 3 Jan 2006 13:46:50 -0000 1.24 --- project.xml 17 Feb 2006 19:25:23 -0000 1.25 *************** *** 122,125 **** --- 122,135 ---- </roles> </developer> + <developer> + <name>Felipe Leme</name> + <id>felipeal</id> + <email>db...@fe...</email> + <organization>Falcon Informatica</organization> + <timezone>-3</timezone> + <roles> + <role>Java Developer</role> + </roles> + </developer> </developers> *************** *** 165,171 **** --> </contributor> - <contributor> - <name>Felipe Leme</name> - </contributor> </contributors> --- 175,178 ---- |
From: <de...@us...> - 2006-02-05 00:27:22
|
Update of /cvsroot/dbunit/dbunit/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30014/xdocs Modified Files: index.xml Log Message: Update news about Felipe Leme joining DBUnit Index: index.xml =================================================================== RCS file: /cvsroot/dbunit/dbunit/xdocs/index.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** index.xml 19 Aug 2005 21:21:29 -0000 1.11 --- index.xml 5 Feb 2006 00:27:14 -0000 1.12 *************** *** 26,29 **** --- 26,33 ---- <table border="1"> <tr> + <td>2006-02-04</td> + <td>Felipe Leme joined the DbUnit developement team.</td> + </tr> + <tr> <td>2005-08-19</td> <td><b>Website Updated!</b> Link to wiki has been removed. Many fixes in CVS for 2.2-dev, see <a href="changes-report.html#2.2">changes</a>.</td> |
From: <de...@us...> - 2006-01-03 13:47:06
|
Update of /cvsroot/dbunit/dbunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14643 Modified Files: project.xml Log Message: fix URL for anonymous CVS access! Index: project.xml =================================================================== RCS file: /cvsroot/dbunit/dbunit/project.xml,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** project.xml 18 Oct 2005 14:43:30 -0000 1.23 --- project.xml 3 Jan 2006 13:46:50 -0000 1.24 *************** *** 48,52 **** scm:<system>:<system specific connection string> --> <repository> ! <connection>scm:cvs:pserver:ano...@cv...:/cvsroot/dbunit:dbunit</connection> <developerConnection>scm:cvs:ext:${maven.username}@cvs.sourceforge.net:/cvsroot/dbunit:dbunit</developerConnection> <url>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dbunit/dbunit</url> --- 48,52 ---- scm:<system>:<system specific connection string> --> <repository> ! <connection>scm:cvs:pserver:ano...@cv...:/cvsroot/dbunit:dbunit</connection> <developerConnection>scm:cvs:ext:${maven.username}@cvs.sourceforge.net:/cvsroot/dbunit:dbunit</developerConnection> <url>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dbunit/dbunit</url> |
From: <de...@us...> - 2005-10-18 14:44:47
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/util/search In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/test/org/dbunit/util/search Added Files: ExcludeNodesSearchCallbackTest.java IncludeNodesSearchCallbackTest.java DepthFirstSearchTest.java AbstractSearchTestCase.java AllTests.java BiDirectionalEdgesDepthFirstSearchTest.java Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. --- NEW FILE: ExcludeNodesSearchCallbackTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.SortedSet; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class ExcludeNodesSearchCallbackTest extends AbstractSearchTestCase { private ISearchCallback callback; protected ISearchCallback getCallback() { return this.callback; } protected void setDenied( Object[] deniedNodes ) { this.callback = new AbstractExcludeNodesSearchCallback( deniedNodes ) { public SortedSet getEdges(Object fromNode) throws SearchException { return getEdgesFromNode(fromNode); } }; } public void testSingleNode() throws Exception { setInput(new String[] { A }); setDenied( new String[] { A } ); doIt(); } public void testSingleEdgeDeniedA() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); setDenied( new String[] { A } ); doIt(); } public void testSingleEdgeDeniedB() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); setDenied( new String[] { B } ); setOutput(new String[] { A }); doIt(); } public void testSingleEdgeMultipleInputDeniedB() throws Exception { setInput(new String[] { A, B }); addEdges(A, new String[] { B }); setDenied( new String[] { B } ); setOutput(new String[] { A }); doIt(); } public void testSingleEdgeMultipleInputDeniedA() throws Exception { setInput(new String[] { A, B }); addEdges(A, new String[] { B }); setDenied( new String[] { A } ); setOutput(new String[] { B }); doIt(); } public void testDisconnected() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); setDenied( new String[] { B, A } ); setOutput(new String[] { C }); doIt(); } public void testDisconnectedAllowedC() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); setDenied( new String[] { C } ); setOutput(new String[] { B, A }); doIt(); } } --- NEW FILE: IncludeNodesSearchCallbackTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.SortedSet; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class IncludeNodesSearchCallbackTest extends AbstractSearchTestCase { private ISearchCallback callback; protected ISearchCallback getCallback() { return this.callback; } protected void setAllowed( Object[] allowedNodes ) { this.callback = new AbstractIncludeNodesSearchCallback( allowedNodes ) { public SortedSet getEdges(Object fromNode) throws SearchException { return getEdgesFromNode(fromNode); } }; } public void testSingleNode() throws Exception { setInput(new String[] { A }); setAllowed( new String[] { A } ); setOutput(new String[] { A }); doIt(); } public void testSingleEdgeAllowedA() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); setAllowed( new String[] { A } ); setOutput(new String[] { A }); doIt(); } public void testSingleEdgeAllowedB() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); setAllowed( new String[] { B } ); doIt(); } public void testSingleEdgeMultipleInputAllowedB() throws Exception { setInput(new String[] { A, B }); addEdges(A, new String[] { B }); setAllowed( new String[] { B } ); setOutput(new String[] { B }); doIt(); } public void testDisconnected() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); setAllowed( new String[] { B, A } ); setOutput(new String[] { B, A }); doIt(); } public void testDisconnectedAllowedC() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); setAllowed( new String[] { C } ); setOutput(new String[] { C }); doIt(); } } --- NEW FILE: DepthFirstSearchTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class DepthFirstSearchTest extends AbstractSearchTestCase { public void testEmptyGraph() throws Exception { doIt(); } public void testSingleNode() throws Exception { setInput(new String[] { A }); setOutput(new String[] { A }); doIt(); } public void testSingleEdge() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A }); doIt(); } public void testSingleEdgeMultipleInput() throws Exception { setInput(new String[] { A, B }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A }); doIt(); } public void testSingleEdgeRepeatedInput() throws Exception { setInput(new String[] { A, B, B, A, B }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A }); doIt(); } public void testDisconnected() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A, C }); doIt(); } public void testDisconnectedInverseOrder() throws Exception { setInput(new String[] { C, A }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A, C }); doIt(); } public void testMultipleEdgesOneSource() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B, C }); setOutput(new String[] { B, C, A }); doIt(); } public void testMultipleEdgesMultipleSources() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B, C }); addEdges(B, new String[] { D, C }); setOutput(new String[] { C, D, B, A }); doIt(); } public void testMultipleEdgesCycleFromA() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { C, B, A }); doIt(); } public void testMultipleEdgesCycleFromB() throws Exception { setInput(new String[] { B }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { A, C, B }); doIt(); } public void testMultipleEdgesCycleFromBA() throws Exception { setInput(new String[] { B, A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { C, B, A }); doIt(); } public void testSelfCyclic() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { A }); setOutput(new String[] { A }); doIt(); } public void testCyclicAndSelfCyclic() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { A, B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { C, B, A }); doIt(); } public void testDisconnectedCycles() throws Exception { setInput(new String[] { A, D }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); addEdges(D, new String[] { E }); addEdges(E, new String[] { F }); addEdges(F, new String[] { D }); setOutput(new String[] { F, E, D, C, B, A }); doIt(); } public void testConnectedCycle() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A, D }); addEdges(D, new String[] { E }); addEdges(E, new String[] { C }); setOutput(new String[] { E, D, C, B, A }); doIt(); } public void testBigConnectedCycle() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A, D }); addEdges(D, new String[] { E, B }); addEdges(E, new String[] { C }); setOutput(new String[] { E, D, C, B, A }); doIt(); } public void testMerge() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); addEdges(C, new String[] { A }); setOutput(new String[] { B, A, C }); doIt(); } } --- NEW FILE: AbstractSearchTestCase.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import junit.framework.TestCase; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public abstract class AbstractSearchTestCase extends TestCase { protected static final String A = "A"; protected static final String B = "B"; protected static final String C = "C"; protected static final String D = "D"; protected static final String E = "E"; protected static final String F = "F"; // fixtures protected final Map fEdgesPerNodeMap = new HashMap(); protected final Set fAllEdgesSet = new HashSet(); protected final Set fExpectedOutput = new LinkedHashSet(); protected final Set fInput = new HashSet(); protected final DepthFirstSearch fSearch = new DepthFirstSearch(); protected void doIt() throws Exception { Set actualOutput = fSearch.search(this.fInput, getCallback()); assertEquals("sizes does not match", this.fExpectedOutput.size(), actualOutput.size()); Iterator iterExpected = this.fExpectedOutput.iterator(); Iterator iterActual = actualOutput.iterator(); int i = 0; while (iterExpected.hasNext()) { Object expectedNode = iterExpected.next(); Object actualNode = iterActual.next(); assertEquals("mismatched element at position " + i, expectedNode, actualNode); i++; } } protected void setInput(String[] nodes) { for (int i = 0; i < nodes.length; i++) { this.fInput.add(nodes[i]); } } protected void setOutput(String[] nodes) { for (int i = 0; i < nodes.length; i++) { this.fExpectedOutput.add(nodes[i]); } } protected void addEdges(String from, String[] tos) { Set tmpEdges = new TreeSet(); for (int i = 0; i < tos.length; i++) { Edge edge = new Edge(from, tos[i]); this.fAllEdgesSet.add( edge ); tmpEdges.add(edge); } this.fEdgesPerNodeMap.put(from, tmpEdges); } protected ISearchCallback getCallback() { return new ISearchCallback() { public SortedSet getEdges(Object fromNode) { return getEdgesFromNode(fromNode); }; public void nodeAdded(Object fromNode) { } public boolean searchNode(Object node) { return true; } }; } protected SortedSet getEdgesFromNode(Object fromNode) { ; return (SortedSet) fEdgesPerNodeMap.get(fromNode); } protected SortedSet getEdgesToNode(Object toNode) { TreeSet set = new TreeSet(); Iterator iterator = this.fAllEdgesSet.iterator(); while ( iterator.hasNext() ) { Edge edge = (Edge) iterator.next(); if ( edge.getTo().equals(toNode)) { set.add( edge ); } } return set; }; } --- NEW FILE: AllTests.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import junit.framework.Test; import junit.framework.TestSuite; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class AllTests { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new TestSuite(BiDirectionalEdgesDepthFirstSearchTest.class)); suite.addTest(new TestSuite(DepthFirstSearchTest.class)); suite.addTest(new TestSuite(ExcludeNodesSearchCallbackTest.class)); suite.addTest(new TestSuite(IncludeNodesSearchCallbackTest.class)); return suite; } } --- NEW FILE: BiDirectionalEdgesDepthFirstSearchTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.SortedSet; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class BiDirectionalEdgesDepthFirstSearchTest extends DepthFirstSearchTest { protected ISearchCallback getCallback() { return new ISearchCallback() { public SortedSet getEdges(Object fromNode) { SortedSet fromSet = getEdgesFromNode(fromNode); SortedSet toSet = getEdgesToNode(fromNode); if ( fromSet == null ) { return toSet; } if ( toSet != null ) { fromSet.addAll( toSet ); } return fromSet; }; public void nodeAdded(Object fromNode) { } public boolean searchNode(Object node) { return true; } }; }; // more tests, now adding nodes or graphs that would not directly reachable // using unidirectional edges. // For, instance, on the graph C->A->B, C would never be reached from A or B public void testSingleReverseEdge() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(C, new String[] { A }); setOutput(new String[] { B, A, C }); doIt(); } public void testSingleReverseEdgeInputB() throws Exception { setInput(new String[] { B }); addEdges(A, new String[] { B }); addEdges(C, new String[] { A }); setOutput(new String[] { B, A, C }); doIt(); } public void testSingleReverseEdgeMultipleInput() throws Exception { setInput(new String[] { B, A }); addEdges(A, new String[] { B }); addEdges(C, new String[] { A }); setOutput(new String[] { B, A, C }); doIt(); } public void testSingleReverseEdgeMultipleInputIncludingC() throws Exception { setInput(new String[] { C, B, A }); addEdges(A, new String[] { B }); addEdges(C, new String[] { A }); setOutput(new String[] { B, A, C }); doIt(); } public void testOneInputTwoEdges() throws Exception { setInput(new String[] { B }); addEdges(A, new String[] { C }); addEdges(B, new String[] { C }); setOutput(new String[] { C, B, A }); doIt(); } // TODO: continue adding more tests uncommenting and adapting tests below... /* public void testSingleEdgeRepeatedInput() throws Exception { setInput(new String[] { A, B, B, A, B }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A }); doIt(); } public void testDisconnected() throws Exception { setInput(new String[] { A, C }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A, C }); doIt(); } public void testDisconnectedInverseOrder() throws Exception { setInput(new String[] { C, A }); addEdges(A, new String[] { B }); setOutput(new String[] { B, A, C }); doIt(); } public void testMultipleEdgesOneSource() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B, C }); setOutput(new String[] { B, C, A }); doIt(); } public void testMultipleEdgesMultipleSources() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B, C }); addEdges(B, new String[] { D, C }); setOutput(new String[] { C, D, B, A }); doIt(); } */ public void testMultipleEdgesCycleFromA() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { A, C, B }); doIt(); } public void testMultipleEdgesCycleFromB() throws Exception { setInput(new String[] { B }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { B, A, C }); doIt(); } public void testMultipleEdgesCycleFromBA() throws Exception { setInput(new String[] { B, A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { A, C, B }); doIt(); } /* public void testSelfCyclic() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { A }); setOutput(new String[] { A }); doIt(); } */ public void testCyclicAndSelfCyclic() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { A, B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); setOutput(new String[] { A, C, B }); doIt(); } public void testDisconnectedCycles() throws Exception { setInput(new String[] { A, D }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A }); addEdges(D, new String[] { E }); addEdges(E, new String[] { F }); addEdges(F, new String[] { D }); setOutput(new String[] { D, F, E, A, C, B }); doIt(); } public void testConnectedCycle() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A, D }); addEdges(D, new String[] { E }); addEdges(E, new String[] { C }); setOutput(new String[] { A, E, D, C, B }); doIt(); } public void testBigConnectedCycle() throws Exception { setInput(new String[] { A }); addEdges(A, new String[] { B }); addEdges(B, new String[] { C }); addEdges(C, new String[] { A, D }); addEdges(D, new String[] { E, B }); addEdges(E, new String[] { C }); setOutput(new String[] { A, C, B, E, D }); doIt(); } } |
From: <de...@us...> - 2005-10-18 14:43:49
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/database/search In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/test/org/dbunit/database/search Added Files: TablesDependencyHelperTest.java ImportNodesFilterSearchCallbackTest.java AllTests.java ImportAndExportNodesFilterSearchCallbackTest.java AbstractMetaDataBasedSearchCallbackTestCase.java ImportAndExportKeysSearchCallbackOwnFileTest.java Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. --- NEW FILE: TablesDependencyHelperTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import java.io.File; import java.sql.Connection; import junit.framework.TestCase; import junitx.framework.ArrayAssert; import org.dbunit.HypersonicEnvironment; import org.dbunit.database.DatabaseConnection; import org.dbunit.database.IDatabaseConnection; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 28, 2005 */ public class TablesDependencyHelperTest extends TestCase { private Connection jdbcConnection; private IDatabaseConnection connection; protected void setUp( String sqlFile ) throws Exception { this.jdbcConnection = HypersonicEnvironment.createJdbcConnection("mem:tempdb"); HypersonicEnvironment.executeDdlFile(new File( "src/sql/" + sqlFile), this.jdbcConnection); this.connection = new DatabaseConnection(jdbcConnection); } protected void tearDown() throws Exception { HypersonicEnvironment.shutdown(this.jdbcConnection); this.jdbcConnection.close(); // HypersonicEnvironment.deleteFiles( "tempdb" ); } public void testGetDependentTablesFromOneTable() throws Exception { setUp( ImportNodesFilterSearchCallbackTest.SQL_FILE ); String[][] allInput = ImportNodesFilterSearchCallbackTest.SINGLE_INPUT; String[][] allExpectedOutput = ImportNodesFilterSearchCallbackTest.SINGLE_OUTPUT; for (int i = 0; i < allInput.length; i++) { String[] input = allInput[i]; String[] expectedOutput = allExpectedOutput[i]; String[] actualOutput = TablesDependencyHelper.getDependentTables( this.connection, input[0]); ArrayAssert.assertEquals( "output didn't match for i=" + i, expectedOutput, actualOutput ); } } public void testGetDependentTablesFromManyTables() throws Exception { setUp( ImportNodesFilterSearchCallbackTest.SQL_FILE ); String[][] allInput = ImportNodesFilterSearchCallbackTest.COMPOUND_INPUT; String[][] allExpectedOutput = ImportNodesFilterSearchCallbackTest.COMPOUND_OUTPUT; for (int i = 0; i < allInput.length; i++) { String[] input = allInput[i]; String[] expectedOutput = allExpectedOutput[i]; String[] actualOutput = TablesDependencyHelper.getDependentTables( this.connection, input); ArrayAssert.assertEquals( "output didn't match for i=" + i, expectedOutput, actualOutput ); } } public void testGetAllDependentTablesFromOneTable() throws Exception { setUp( ImportAndExportKeysSearchCallbackOwnFileTest.SQL_FILE ); String[][] allInput = ImportAndExportKeysSearchCallbackOwnFileTest.SINGLE_INPUT; String[][] allExpectedOutput = ImportAndExportKeysSearchCallbackOwnFileTest.SINGLE_OUTPUT; for (int i = 0; i < allInput.length; i++) { String[] input = allInput[i]; String[] expectedOutput = allExpectedOutput[i]; String[] actualOutput = TablesDependencyHelper.getAllDependentTables( this.connection, input[0]); ArrayAssert.assertEquals( "output didn't match for i=" + i, expectedOutput, actualOutput ); } } public void testGetAllDependentTablesFromManyTables() throws Exception { setUp( ImportAndExportKeysSearchCallbackOwnFileTest.SQL_FILE ); String[][] allInput = ImportAndExportKeysSearchCallbackOwnFileTest.COMPOUND_INPUT; String[][] allExpectedOutput = ImportAndExportKeysSearchCallbackOwnFileTest.COMPOUND_OUTPUT; for (int i = 0; i < allInput.length; i++) { String[] input = allInput[i]; String[] expectedOutput = allExpectedOutput[i]; String[] actualOutput = TablesDependencyHelper.getAllDependentTables( this.connection, input); ArrayAssert.assertEquals( "output didn't match for i=" + i, expectedOutput, actualOutput ); } } // ImportAndExportKeysSearchCallbackOwnFileTest } --- NEW FILE: ImportNodesFilterSearchCallbackTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import org.dbunit.database.IDatabaseConnection; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 28, 2005 */ public class ImportNodesFilterSearchCallbackTest extends AbstractMetaDataBasedSearchCallbackTestCase { public static final String SQL_FILE = "hypersonic_import.sql"; public static final String[][] SINGLE_INPUT = new String[][] { new String[] { "A" }, new String[] { "B" }, new String[] { "C" }, new String[] { "D" }, new String[] { "E" }, new String[] { "F" }, new String[] { "G" }, new String[] { "H" } }; public static final String[][] COMPOUND_INPUT = new String[][] { new String[] { "A", "H" }, new String[] { "H", "A" }, new String[] { "A", "B" }, new String[] { "B", "A" }, new String[] { "B", "A", "A", "B", "D", "G" } }; public static final String[][] SINGLE_OUTPUT = new String[][] { new String[] { "G", "D", "A" }, new String[] { "G", "D", "A", "F", "C", "E", "H", "B" }, new String[] { "G", "D", "A", "F", "C" }, new String[] { "A", "G", "D" }, new String[] { "G", "D", "A", "E" }, new String[] { "A", "G", "D", "F" }, new String[] { "D", "A", "G" }, new String[] { "H" }, }; public static final String[][] COMPOUND_OUTPUT = new String[][] { new String[] { "G", "D", "A", "H" }, new String[] { "H", "G", "D", "A" }, new String[] { "G", "D", "A", "F", "C", "E", "H", "B" }, new String[] { "G", "D", "A", "F", "C", "E", "H", "B" }, new String[] { "G", "D", "A", "F", "C", "E", "H", "B" } }; public ImportNodesFilterSearchCallbackTest(String testName) { super(testName, SQL_FILE); } protected String[][] getInput() { String[][] input = new String[SINGLE_INPUT.length+COMPOUND_INPUT.length][]; System.arraycopy( SINGLE_INPUT, 0, input, 0, SINGLE_INPUT.length); System.arraycopy(COMPOUND_INPUT,0,input,SINGLE_INPUT.length,COMPOUND_INPUT.length); return input; } protected String[][] getExpectedOutput() { String[][] output = new String[SINGLE_OUTPUT.length+COMPOUND_OUTPUT.length][]; System.arraycopy( SINGLE_OUTPUT, 0, output, 0, SINGLE_OUTPUT.length); System.arraycopy(COMPOUND_OUTPUT,0,output,SINGLE_OUTPUT.length,COMPOUND_OUTPUT.length); return output; } protected AbstractMetaDataBasedSearchCallback getCallback(IDatabaseConnection connection) { return new ImportedKeysSearchCallback(connection); } } --- NEW FILE: AllTests.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002-2004, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import junit.framework.Test; import junit.framework.TestSuite; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 28, 2005 */ public class AllTests { public static Test suite() throws Exception { TestSuite suite = new TestSuite(); suite.addTest(new TestSuite(ImportAndExportNodesFilterSearchCallbackTest.class)); suite.addTest(new TestSuite(ImportNodesFilterSearchCallbackTest.class)); suite.addTest(new TestSuite(ImportAndExportKeysSearchCallbackOwnFileTest.class)); suite.addTest(new TestSuite(TablesDependencyHelperTest.class)); return suite; } } --- NEW FILE: ImportAndExportNodesFilterSearchCallbackTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import org.dbunit.database.IDatabaseConnection; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 28, 2005 */ public class ImportAndExportNodesFilterSearchCallbackTest extends ImportNodesFilterSearchCallbackTest { public ImportAndExportNodesFilterSearchCallbackTest(String testName) { super(testName); } protected String[][] getExpectedOutput() { int size = getInput().length; String[][] result = new String[size][]; String[] allResults = super.getExpectedOutput()[1]; for (int i = 0; i < result.length; i++) { result[i] = allResults; } return result; } protected AbstractMetaDataBasedSearchCallback getCallback(IDatabaseConnection connection) { return new ImportedAndExportedKeysSearchCallback(connection); } } --- NEW FILE: AbstractMetaDataBasedSearchCallbackTestCase.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002-2004, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import java.io.File; import java.sql.Connection; import java.util.Set; import junit.framework.TestCase; import junitx.framework.ArrayAssert; import org.dbunit.database.DatabaseConnection; import org.dbunit.database.IDatabaseConnection; import org.dbunit.HypersonicEnvironment; import org.dbunit.util.search.DepthFirstSearch; import org.dbunit.util.search.ISearchCallback; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 28, 2005 */ public abstract class AbstractMetaDataBasedSearchCallbackTestCase extends TestCase { private final String sqlFile; private Connection jdbcConnection; private IDatabaseConnection connection; public AbstractMetaDataBasedSearchCallbackTestCase(String testName, String sqlFile) { super(testName ); this.sqlFile = sqlFile; } protected void setUp() throws Exception { this.jdbcConnection = HypersonicEnvironment.createJdbcConnection("mem:tempdb"); HypersonicEnvironment.executeDdlFile(new File( "src/sql/" + this.sqlFile), this.jdbcConnection); this.connection = new DatabaseConnection(jdbcConnection); } protected void tearDown() throws Exception { HypersonicEnvironment.shutdown(this.jdbcConnection); this.jdbcConnection.close(); // HypersonicEnvironment.deleteFiles( "tempdb" ); } protected IDatabaseConnection getConnection() { return this.connection; } protected abstract String[][] getInput(); protected abstract String[][] getExpectedOutput(); protected abstract AbstractMetaDataBasedSearchCallback getCallback(IDatabaseConnection connection2); public void testAllInput() throws Exception { IDatabaseConnection connection = getConnection(); String[][] allInput = getInput(); String[][] allExpectedOutput = getExpectedOutput(); ISearchCallback callback = getCallback(connection); for (int i = 0; i < allInput.length; i++) { String[] input = allInput[i]; String[] expectedOutput = allExpectedOutput[i]; DepthFirstSearch search = new DepthFirstSearch(); Set result = search.search( input, callback ); String[] actualOutput = DepthFirstSearch.setToStrings( result ); ArrayAssert.assertEquals( "output didn't match for i=" + i, expectedOutput, actualOutput ); } } } --- NEW FILE: ImportAndExportKeysSearchCallbackOwnFileTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import org.dbunit.database.IDatabaseConnection; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 28, 2005 */ public class ImportAndExportKeysSearchCallbackOwnFileTest extends AbstractMetaDataBasedSearchCallbackTestCase { public static final String SQL_FILE = "hypersonic_import_export.sql"; public ImportAndExportKeysSearchCallbackOwnFileTest(String testName) { super(testName, SQL_FILE); } public static final String[][] SINGLE_INPUT = new String[][] { new String[] { "A" }, new String[] { "B" }, new String[] { "C" }, new String[] { "D" }, new String[] { "E" }, new String[] { "F" } }; public static final String[][] COMPOUND_INPUT = new String[][] { new String[] { "A", "D" }, new String[] { "D", "A" }, new String[] { "B", "F" }, new String[] { "F", "B" }, new String[] { "A", "E" }, new String[] { "E", "A" } }; public static final String[][] SINGLE_OUTPUT = new String[][] { new String[] { "B", "A", "C" }, new String[] { "B", "A", "C" }, new String[] { "B", "A", "C" }, new String[] { "F", "E", "D" }, new String[] { "F", "E", "D" }, new String[] { "F", "E", "D" } }; public static final String[][] COMPOUND_OUTPUT = new String[][] { new String[] { "B", "A", "C", "F", "E", "D" }, new String[] { "F", "E", "D", "B", "A", "C" }, new String[] { "B", "A", "C", "F", "E", "D" }, new String[] { "F", "E", "D", "B", "A", "C" }, new String[] { "B", "A", "C", "F", "E", "D" }, new String[] { "F", "E", "D", "B", "A", "C" } }; protected String[][] getInput() { String[][] input = new String[SINGLE_INPUT.length+COMPOUND_INPUT.length][]; System.arraycopy(SINGLE_INPUT, 0, input, 0, SINGLE_INPUT.length); System.arraycopy(COMPOUND_INPUT,0,input,SINGLE_INPUT.length,COMPOUND_INPUT.length); return input; } protected String[][] getExpectedOutput() { String[][] output = new String[SINGLE_OUTPUT.length+COMPOUND_OUTPUT.length][]; System.arraycopy(SINGLE_OUTPUT, 0, output, 0, SINGLE_OUTPUT.length); System.arraycopy(COMPOUND_OUTPUT,0,output,SINGLE_OUTPUT.length,COMPOUND_OUTPUT.length); return output; } protected AbstractMetaDataBasedSearchCallback getCallback(IDatabaseConnection connection) { return new ImportedAndExportedKeysSearchCallback(connection); } } |
From: <de...@us...> - 2005-10-18 14:43:47
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/database/search In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/java/org/dbunit/database/search Added Files: ImportedKeysSearchCallback.java TablesDependencyHelper.java AbstractMetaDataBasedSearchCallback.java FKRelationshipEdge.java ImportedAndExportedKeysSearchCallback.java Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. --- NEW FILE: ImportedKeysSearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */package org.dbunit.database.search; import java.util.SortedSet; import org.dbunit.database.IDatabaseConnection; import org.dbunit.util.search.SearchException; /** * ISearchCallback implementation that get the nodes using direct foreign key * dependency, i.e, if table A has a FK for a table B, then getNodes(A) will * return B. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class ImportedKeysSearchCallback extends AbstractMetaDataBasedSearchCallback { public ImportedKeysSearchCallback(IDatabaseConnection connection) { super(connection); } public SortedSet getEdges(Object node) throws SearchException { return getNodesFromImportedKeys( node ); } } --- NEW FILE: TablesDependencyHelper.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; //import java.sql.SQLException; //import java.util.HashMap; //import java.util.Map; import java.util.Set; import org.dbunit.database.IDatabaseConnection; //import org.dbunit.dataset.FilteredDataSet; //import org.dbunit.dataset.IDataSet; //import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.util.search.DepthFirstSearch; import org.dbunit.util.search.SearchException; /** * Helper for the graph-search based classes used to calculate dependency * among tables. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 26, 2005 */ public class TablesDependencyHelper { // this is a "static" class private TablesDependencyHelper() { } /** * Get the name of all tables that depend on a root table (i.e, all tables whose PK * is a FK for the root table). * @param connection database conncetion * @param rootTable root table described above * @return name of all tables that depend on the root table (including the root table), * in the right order for insertions * @throws SearchException if an exception occurred while calculating the order */ public static String[] getDependentTables( IDatabaseConnection connection, String rootTable ) throws SearchException { return getDependentTables( connection, new String[] { rootTable } ); } /** * Get the name of all tables that depend on the root tables (i.e, all tables whose PK * is a FK for one of root tables). * @param connection database conncetion * @param rootTables array of root tables described above * @return name of all tables that depend on the root tables (including the root tables), * in the right order for insertions * @throws SearchException if an exception occurred while calculating the order */ public static String[] getDependentTables( IDatabaseConnection connection, String[] rootTables ) throws SearchException { ImportedKeysSearchCallback callback = new ImportedKeysSearchCallback(connection); DepthFirstSearch search = new DepthFirstSearch(); Set tables = search.search( rootTables, callback ); return (String[]) DepthFirstSearch.setToStrings( tables ); } /** * Get the name of all tables that depend on a root table ( i.e, all tables whose PK * is a FK for the root table) and also the tables the root table depends on * (i.e., all tables which have a FK for the root table's PK). * @param connection database conncetion * @param rootTable root table described above * @return name of all tables that depend on the root table (including the root table), * in the right order for insertions * @throws SearchException if an exception occurred while calculating the order */ public static String[] getAllDependentTables( IDatabaseConnection connection, String rootTable ) throws SearchException { return getAllDependentTables( connection, new String[] { rootTable } ); } /** * Get the name of all tables that depend on the root tables ( i.e, all tables whose PK * is a FK for any of the root tables) and also the tables the root tables depends on * (i.e., all tables which have a FK for any of the root table's PK). * @param connection database conncetion * @param rootTables root tables described above * @return name of all tables that depend on the root tables (including the root tables), * in the right order for insertions * @throws SearchException if an exception occurred while calculating the order */ public static String[] getAllDependentTables( IDatabaseConnection connection, String[] rootTables ) throws SearchException { ImportedAndExportedKeysSearchCallback callback = new ImportedAndExportedKeysSearchCallback(connection); DepthFirstSearch search = new DepthFirstSearch(); Set tables = search.search( rootTables, callback ); return (String[]) DepthFirstSearch.setToStrings( tables ); } /* TODO: not used yet (but will on second patch) public static IDataSet getDataset( IDatabaseConnection connection, String rootTable, Set allowedIds ) throws SearchException, SQLException { HashMap map = new HashMap(1); map.put( rootTable, allowedIds ); return getDataset( connection, map ); } public static IDataSet getDataset( IDatabaseConnection connection, Map rootTables ) throws SearchException, SQLException { ImportedKeysSearchCallbackFilteredByPKs callback = new ImportedKeysSearchCallbackFilteredByPKs(connection, rootTables); ITableFilter filter = callback.getFilter(); DepthFirstSearch search = new DepthFirstSearch(); String[] tableNames = DepthFirstSearch.setToStrings( rootTables.keySet() ); Set tmpTables = search.search( tableNames, callback ); String[] dependentTables = DepthFirstSearch.setToStrings( tmpTables ); IDataSet tmpDataset = connection.createDataSet( dependentTables ); FilteredDataSet dataset = new FilteredDataSet(filter, tmpDataset); return dataset; } public static IDataSet getAllDataset( IDatabaseConnection connection, String rootTable, Set allowedIds ) throws SearchException, SQLException { HashMap map = new HashMap(1); map.put( rootTable, allowedIds ); return getAllDataset( connection, map ); } public static IDataSet getAllDataset( IDatabaseConnection connection, Map rootTables ) throws SearchException, SQLException { ImportedAndExportedKeysSearchCallbackFilteredByPKs callback = new ImportedAndExportedKeysSearchCallbackFilteredByPKs(connection, rootTables); ITableFilter filter = callback.getFilter(); DepthFirstSearch search = new DepthFirstSearch(); String[] tableNames = DepthFirstSearch.setToStrings( rootTables.keySet() ); Set tmpTables = search.search( tableNames, callback ); String[] dependentTables = DepthFirstSearch.setToStrings( tmpTables ); IDataSet tmpDataset = connection.createDataSet( dependentTables ); FilteredDataSet dataset = new FilteredDataSet(filter, tmpDataset); return dataset; } */ } --- NEW FILE: AbstractMetaDataBasedSearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.SortedSet; import java.util.TreeSet; import org.dbunit.database.IDatabaseConnection; import org.dbunit.util.search.AbstractNodesFilterSearchCallback; import org.dbunit.util.search.IEdge; import org.dbunit.util.search.SearchException; /** * Super-class for the ISearchCallback that implements the * <code>getEdges()</code> method using the database meta-data. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public abstract class AbstractMetaDataBasedSearchCallback extends AbstractNodesFilterSearchCallback { private final IDatabaseConnection connection; /** * Defautl constructor. * @param connection connection where the edges will be calculated from */ public AbstractMetaDataBasedSearchCallback(IDatabaseConnection connection) { this.connection = connection; } /** * Get the connection where the edges will be calculated from. * @return the connection where the edges will be calculated from */ public IDatabaseConnection getConnection() { return connection; } protected static final int IMPORT = 0; protected static final int EXPORT = 1; /** * indexes of the column names on the MetaData result sets. */ protected static final int[] TABLENAME_INDEXES = { 3, 7 }; protected static final int[] PK_INDEXES = { 4, 4 }; protected static final int[] FK_INDEXES = { 8, 8 }; /** * Get the nodes using the direct foreign key dependency, i.e, if table A has * a FK for a table B, then getNodesFromImportedKeys(A) will return B. * @param node table name * @return tables with direct FK dependency from node * @throws SearchException */ protected SortedSet getNodesFromImportedKeys(Object node) throws SearchException { return getNodes(IMPORT, node); } /** * Get the nodes using the reverse foreign key dependency, i.e, if table C has * a FK for a table A, then getNodesFromExportedKeys(A) will return C.<br> * * <strong>NOTE:</strong> this method should be used only as an auxiliary * method for sub-classes that also use <code>getNodesFromImportedKeys()</code> * or something similiar, otherwise the generated sequence of tables might not * work when inserted in the database (as some tables might be missing). * <br> * @param node table name * @return tables with reverse FK dependency from node * @throws SearchException */ protected SortedSet getNodesFromExportedKeys(Object node) throws SearchException { return getNodes(EXPORT, node); } /** * Get the nodes using the both direct and reverse foreign key dependency, i.e, * if table C has a FK for a table A and table A has a FK for a table B, then * getNodesFromImportAndExportedKeys(A) will return B and C. * @param node table name * @return tables with reverse and direct FK dependency from node * @throws SearchException */ protected SortedSet getNodesFromImportAndExportKeys(Object node) throws SearchException { SortedSet importedNodes = getNodesFromImportedKeys( node ); SortedSet exportedNodes = getNodesFromExportedKeys( node ); importedNodes.addAll( exportedNodes ); return importedNodes; } private SortedSet getNodes(int type, Object node) throws SearchException { try { Connection conn = this.connection.getConnection(); String schema = this.connection.getSchema(); DatabaseMetaData metaData = conn.getMetaData(); SortedSet edges = new TreeSet(); getNodes(type, node, conn, schema, metaData, edges); return edges; } catch (SQLException e) { throw new SearchException(e); } } private void getNodes(int type, Object node, Connection conn, String schema, DatabaseMetaData metaData, SortedSet edges) throws SearchException { if ( super.logger.isTraceEnabled() ) { super.logger.trace("Getting edges for node " + node); } try { if (!(node instanceof String)) { throw new IllegalArgumentException("node should be a String, not a " + node.getClass().getName()); } String tableName = (String) node; ResultSet rs = null; switch (type) { case IMPORT: rs = metaData.getImportedKeys(null, schema, tableName); break; case EXPORT: rs = metaData.getExportedKeys(null, schema, tableName); break; } while (rs.next()) { int index = TABLENAME_INDEXES[type]; String dependentTableName = rs.getString(index); String pkColumn = rs.getString( PK_INDEXES[type] ); String fkColumn = rs.getString( FK_INDEXES[type] ); IEdge edge = newEdge(rs, type, tableName, dependentTableName, fkColumn, pkColumn ); if ( super.logger.isTraceEnabled() ) { super.logger.trace("Adding edge " + edge); } edges.add(edge); } } catch (SQLException e) { throw new SearchException(e); } } protected FKRelationshipEdge createFKEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException { return type == IMPORT ? new FKRelationshipEdge( from, to, fkColumn, pkColumn ) : new FKRelationshipEdge( to, from, fkColumn, pkColumn ); } /** * This method can be overwritten by the sub-classes if they need to decorate * the edge (for instance, providing an Edge that contains the primary and * foreign keys used). * * @throws SearchException exception wrapper */ protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException { return createFKEdge( rs, type, from, to, fkColumn, pkColumn ); } } --- NEW FILE: FKRelationshipEdge.java --- package org.dbunit.database.search; import org.dbunit.util.search.Edge; public class FKRelationshipEdge extends Edge { // TODO: support multiple columns private String fkColumn; private String pkColumn; public FKRelationshipEdge(String tableFrom, String tableTo, String fkColumn, String pkColumn) { super(tableFrom, tableTo); this.fkColumn = fkColumn; this.pkColumn = pkColumn; } public String getFKColumn() { return fkColumn; } public String getPKColumn() { return pkColumn; } public String toString() { return getFrom() + "(" + getFKColumn() + ")->" + getTo() + "(" + getPKColumn() + ")"; } // TODO: hashcode and equals } --- NEW FILE: ImportedAndExportedKeysSearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.database.search; import java.util.SortedSet; import org.dbunit.database.IDatabaseConnection; import org.dbunit.util.search.SearchException; /** * ISearchCallback implementation that get the nodes using both direct and reverse * foreign key dependency, i.e, if table C has a FK for a table A and table A has * a FK for a table B, then getNodes(A) will return B and C. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class ImportedAndExportedKeysSearchCallback extends AbstractMetaDataBasedSearchCallback { public ImportedAndExportedKeysSearchCallback(IDatabaseConnection connection) { super(connection); } public SortedSet getEdges(Object node) throws SearchException { return getNodesFromImportAndExportKeys(node); } } |
From: <de...@us...> - 2005-10-18 14:43:44
|
Update of /cvsroot/dbunit/dbunit/src/sql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/sql Added Files: hypersonic_import_export.sql hypersonic_import.sql Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. --- NEW FILE: hypersonic_import_export.sql --- /** Create tables used to test ImportedAndExportedKeysSearchCallback's ordering algorithm with the following dependencies: A - B | C D - E \ / F */ CREATE TABLE A (PKA NUMERIC, FKB NUMERIC, PRIMARY KEY (PKA)); CREATE TABLE B (PKB NUMERIC, PRIMARY KEY (PKB)); CREATE TABLE C (PKC NUMERIC, FKA NUMERIC, PRIMARY KEY (PKC)); CREATE TABLE D (PKD NUMERIC, FKE NUMERIC, FKF NUMERIC, PRIMARY KEY (PKD)); CREATE TABLE E (PKE NUMERIC, FKF NUMERIC, PRIMARY KEY (PKE)); CREATE TABLE F (PKF NUMERIC, PRIMARY KEY (PKF)); ALTER TABLE A ADD CONSTRAINT AB FOREIGN KEY (FKB) REFERENCES B (PKB); ALTER TABLE C ADD CONSTRAINT CA FOREIGN KEY (FKA) REFERENCES A (PKA); ALTER TABLE D ADD CONSTRAINT DE FOREIGN KEY (FKE) REFERENCES E(PKE); ALTER TABLE D ADD CONSTRAINT DF FOREIGN KEY (FKF) REFERENCES F (PKF); ALTER TABLE E ADD CONSTRAINT EF FOREIGN KEY (FKF) REFERENCES F (PKF); --- NEW FILE: hypersonic_import.sql --- /** Create tables used to test ImportedKeysSearchCallback's ordering algorithm with the following dependencies: D - D / \ \ F A - G \ / \ / C E H \ / / B The correct result should be: D, A, F, C, G, E, H, B Cycles: D <-> D A -> G -> D */ CREATE TABLE A (PKA NUMERIC, FKD NUMERIC, PRIMARY KEY (PKA)); CREATE TABLE B (PKB NUMERIC, FKC NUMERIC, FKE NUMERIC, FKH NUMERIC, PRIMARY KEY (PKB)); CREATE TABLE C (PKC NUMERIC, FKA NUMERIC, FKF NUMERIC, PRIMARY KEY (PKC)); CREATE TABLE D (PKD NUMERIC, FKD NUMERIC, FKG NUMERIC, PRIMARY KEY (PKD)); CREATE TABLE E (PKE NUMERIC, FKA NUMERIC, FKG NUMERIC, PRIMARY KEY (PKE)); CREATE TABLE F (PKF NUMERIC, FKD NUMERIC, PRIMARY KEY (PKF)); CREATE TABLE G (PKG NUMERIC, FKA NUMERIC, PRIMARY KEY (PKG)); CREATE TABLE H (PKH NUMERIC, PRIMARY KEY (PKH)); ALTER TABLE A ADD CONSTRAINT AD FOREIGN KEY (FKD) REFERENCES D (PKD); ALTER TABLE B ADD CONSTRAINT BC FOREIGN KEY (FKC) REFERENCES C (PKC); ALTER TABLE B ADD CONSTRAINT BE FOREIGN KEY (FKE) REFERENCES E (PKE); ALTER TABLE B ADD CONSTRAINT BH FOREIGN KEY (FKH) REFERENCES H (PKH); ALTER TABLE C ADD CONSTRAINT CA FOREIGN KEY (FKA) REFERENCES A (PKA); ALTER TABLE C ADD CONSTRAINT CF FOREIGN KEY (FKF) REFERENCES F (PKF); ALTER TABLE D ADD CONSTRAINT DD FOREIGN KEY (FKD) REFERENCES D (PKD); ALTER TABLE D ADD CONSTRAINT DG FOREIGN KEY (FKG) REFERENCES G (PKG); ALTER TABLE E ADD CONSTRAINT EA FOREIGN KEY (FKA) REFERENCES A (PKA); ALTER TABLE E ADD CONSTRAINT EG FOREIGN KEY (FKG) REFERENCES G (PKG); ALTER TABLE F ADD CONSTRAINT FD FOREIGN KEY (FKD) REFERENCES D (PKD); ALTER TABLE G ADD CONSTRAINT GA FOREIGN KEY (FKA) REFERENCES A (PKA); |
From: <de...@us...> - 2005-10-18 14:43:43
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/operation/mssqlserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/java/org/dbunit/operation/mssqlserver Removed Files: InsertIdentityOperation.java Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. --- InsertIdentityOperation.java DELETED --- |
From: <de...@us...> - 2005-10-18 14:43:43
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/search In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/java/org/dbunit/util/search Added Files: IEdge.java SearchException.java AbstractExcludeNodesSearchCallback.java Edge.java AbstractNodesFilterSearchCallback.java DepthFirstSearch.java ISearchAlgorithm.java AbstractIncludeNodesSearchCallback.java ISearchCallback.java Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. --- NEW FILE: IEdge.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; /** * A bidirectional edge on the graph to be searched.<br> * It must implement <code>Comparable</code> so the * <code>ISearchCallback</code> can properly order the dependencies of a node * (so, typically, the implementations will compare the <code>getTo()</code> * node). * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public interface IEdge extends Comparable { /** * Get the node this edge originates from. * * @return node this edge originates from. */ Object getFrom(); /** * Get the node this edge points to. * * @return node this edge points to. */ Object getTo(); } --- NEW FILE: SearchException.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002-2004, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import org.dbunit.DatabaseUnitException; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class SearchException extends DatabaseUnitException { /** * */ private static final long serialVersionUID = -8369726048539373231L; public SearchException() { } public SearchException(String msg) { super(msg); } public SearchException(String msg, Throwable e) { super(msg, e); } public SearchException(Throwable e) { super(e); } } --- NEW FILE: AbstractExcludeNodesSearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.Set; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 * */ public abstract class AbstractExcludeNodesSearchCallback extends AbstractNodesFilterSearchCallback { public AbstractExcludeNodesSearchCallback(Set deniedNodes) { super(); setDeniedNodes(deniedNodes); } public AbstractExcludeNodesSearchCallback(Object[] deniedNodes) { super(); setDeniedNodes(deniedNodes); } } --- NEW FILE: Edge.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; /** * Basic implementation of the IEdge interface. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public class Edge implements IEdge { private final Comparable nodeFrom; private final Comparable nodeTo; public Edge(Comparable nodeFrom, Comparable nodeTo) { if (nodeFrom == null) { throw new IllegalArgumentException("node from cannot be null"); } if (nodeTo == null) { throw new IllegalArgumentException("node to cannot be null"); } this.nodeFrom = nodeFrom; this.nodeTo = nodeTo; } public Object getFrom() { return this.nodeFrom; } public Object getTo() { return this.nodeTo; } public String toString() { return this.nodeFrom + "->" + this.nodeTo; } public int compareTo(Object o) { Edge otherEdge = (Edge) o; int result = this.nodeFrom.compareTo(otherEdge.getFrom()); if ( result == 0 ) { result = this.nodeTo.compareTo(otherEdge.getTo()); } return result; } public boolean equals(Object obj) { return EqualsBuilder.reflectionEquals( this, obj ); } public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } } --- NEW FILE: AbstractNodesFilterSearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Super-class for ISearchCallback implementations that needs to filter which * nodes should be included or excluded from the search.<br> * This class implements the <code>searchNode()</code> based on its internal * mode, which could be <code>ALLOW_MODE</code>, <code>DENY_MODE</code> or * <code>NO_MODE</code>: * <ul> * <li><code>NO_MODE</code> is the default mode and means <code>searchNode()</code> * always return true</li> * <li><code>ALLOW_MODE</code> is set when <code>setAllowedNodes()</code> is called * and it means <code>searchNode()</code> will return true only if the node is * contained on the Set (or array) passed to <code>setAllowedNodes()</code> * <li><code>DENY_MODE</code> is set when <code>setDeniedNodes()</code> is called * and it means <code>searchNode()</code> will return true only if the node is * not contained on the Set (or array) passed to <code>setDeniedNodes()</code> * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 * */ public abstract class AbstractNodesFilterSearchCallback implements ISearchCallback { protected final Log logger = LogFactory.getLog(getClass()); // internal modes protected static final int NO_MODE = 0; protected static final int ALLOW_MODE = 1; protected static final int DENY_MODE = 2; private int filteringMode = NO_MODE; private Set filteredNodes = new HashSet(); /** * Default constructor. * */ public AbstractNodesFilterSearchCallback() { } /** * Get which modes are allowed/denied, depending on the operation mode. * @return which modes are allowed/denied, depending on the operation mode. */ protected Set getFilteredNodes() { return this.filteredNodes; } /** * Get the operation mode * @return operation mode */ protected int getFilteringMode() { return this.filteringMode; } /** * Set which modes are allowed on the search. * @param filteredNodes which modes are allowed on the search. */ protected void setAllowedNodes(Set filteredNodes) { setFilteredNodes(filteredNodes); this.filteringMode = ALLOW_MODE; } /** * Set which modes are allowed on the search. * @param filteredNodes which modes are allowed on the search. */ protected void setAllowedNodes(Object[] filteredNodes) { setFilteredNodes(filteredNodes); this.filteringMode = ALLOW_MODE; } /** * Set which modes are not allowed on the search. * @param filteredNodes which modes are not allowed on the search. */ protected void setDeniedNodes(Set filteredNodes) { setFilteredNodes(filteredNodes); this.filteringMode = DENY_MODE; } /** * Set which modes are not allowed on the search. * @param filteredNodes which modes are not allowed on the search. */ protected void setDeniedNodes(Object[] filteredNodes) { setFilteredNodes(filteredNodes); this.filteringMode = DENY_MODE; } /** * Do nothing... */ public void nodeAdded(Object fromNode) throws SearchException { // do nothing } public boolean searchNode(Object node) throws SearchException { switch( this.filteringMode ) { case ALLOW_MODE: return getFilteredNodes().contains(node); case DENY_MODE: return !getFilteredNodes().contains(node); default: return true; } } private void setFilteredNodes(Set filteredNodes) { this.filteredNodes = new HashSet(filteredNodes); } private void setFilteredNodes(Object[] filteredNodes) { this.filteredNodes = new HashSet(filteredNodes.length); for (int i = 0; i < filteredNodes.length; i++) { this.filteredNodes.add(filteredNodes[i]); } } } --- NEW FILE: DepthFirstSearch.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.SortedSet; import org.apache.commons.collections.set.ListOrderedSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Search using depth-first algorithm.<br> * <br> * An instance of this class must be used only once, as it maintains the * internal state of the search.<br> * <br> * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 * */ public class DepthFirstSearch implements ISearchAlgorithm { // nodes that were already scanned during the search private Set scannedNodes; private Set reverseScannedNodes; protected final Log logger = LogFactory.getLog(getClass()); // result of the search private Set result; // input of the search private Set nodesFrom; // callback used to help the search private ISearchCallback callback; // flag, as one instance cannot be used more than once private boolean searching = false; /** * Helper method, returns a Set from an array of objects. * Note the Iterator returned by this Set mantains the order of the array. * @param objects array of objects * @return Set with the elements of the array */ public static Set objectsToSet( Object[] objects ) { Set set = new ListOrderedSet(); for (int i = 0; i < objects.length; i++) { set.add(objects[i]); } return set; } /** * Helper method, returns an array of Objects from a Set. * @param a Set * @return array of Objects with the elements of the Set */ public static Object[] setToObjects( Set set ) { Object[] objects = new Object[ set.size() ]; int i=0; for (Iterator iter = set.iterator(); iter.hasNext(); i++) { objects[i] = iter.next(); } return objects; } /** * Helper method, returns an array of Strings from a Set. * @param a Set of Strings * @return array of Strings with the elements of the Set */ public static String[] setToStrings( Set set ) { String[] strings = new String[ set.size() ]; int i=0; for (Iterator iter = set.iterator(); iter.hasNext(); i++) { strings[i] = (String) iter.next(); } return strings; } /** * Alternative option to search() that takes an array of nodes as input (instead of a Set) */ public Set search(Object[] nodesFrom, ISearchCallback callback) throws SearchException { return search(objectsToSet(nodesFrom), callback); } /** * @see ISearchAlgorithm */ public Set search(Set nodesFrom, ISearchCallback callback) throws SearchException { synchronized (this) { if (searching) { throw new IllegalStateException("already searching/searched"); } this.searching = true; } // set of tables that will be returned (i.e, the declared tables and its // depedencies) this.result = new ListOrderedSet(); // callback used to help the search this.callback = callback; this.nodesFrom = new ListOrderedSet(); int sizeNodesFromBefore = 0; int sizeResultBefore = 0; boolean keepSearching = true; this.scannedNodes = new HashSet(); this.reverseScannedNodes = new HashSet(); this.scannedNodes = new HashSet(); do { // In a traditional depth-first search, the getEdges() method should return only // edges where this node is the 'from' vertex, as the graph is known in advance. // But in our case, the graph is built 'on the fly', so it's possible that the // getEdges() also returns edges where the node is the 'to' vertex. // So, before we do the "real" search, we need to do a reverse search to find out // all the nodes that should be part of the input. Iterator iterator = nodesFrom.iterator(); while (iterator.hasNext()) { Object node = iterator.next(); reverseSearch(node); } // now that the input is adjusted, do the search iterator = this.nodesFrom.iterator(); while (iterator.hasNext()) { Object node = iterator.next(); search(node); } nodesFrom = new HashSet(this.result); // decides if we continue searching boolean sizesDontMatch = this.result.size() != this.nodesFrom.size(); boolean resultChanged = this.result.size() != sizeResultBefore; boolean nodesFromChanged = this.nodesFrom.size() != sizeNodesFromBefore; sizeNodesFromBefore = this.nodesFrom.size(); sizeResultBefore = this.result.size(); keepSearching = sizesDontMatch && ( resultChanged || nodesFromChanged ); } while ( keepSearching ); return this.result; } /** * This is the real depth first search algorithm, which is called recursively. * * @param node node where the search starts * @return true if the node has been already searched before * @throws Exception if an exception occurs while getting the edges */ private boolean search(Object node) throws SearchException { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "search:" + node ); } if (this.scannedNodes.contains(node)) { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "already searched; returning true" ); } return true; } if (!this.callback.searchNode(node)) { if ( this.logger.isTraceEnabled() ) { this.logger.trace( "Callback handler blocked filtered out node " + node ); } return true; } if ( this.logger.isDebugEnabled() ) { this.logger.debug("Pushing " + node); } this.scannedNodes.add(node); // first, search the nodes the node depends on SortedSet edges = this.callback.getEdges(node); if (edges != null) { Iterator iterator = edges.iterator(); while (iterator.hasNext()) { // and recursively search these nodes IEdge edge = (IEdge) iterator.next(); Object toNode = edge.getTo(); search(toNode); } } // finally, add the node to the result this.logger.trace( "Adding node " + node + " to the final result" ); this.callback.nodeAdded(node); result.add(node); return false; } /** * Do a reverse search (i.e, searching the other way of the edges) in order * to adjust the input before the real search. * @param node node where the search starts * @return true if the node has been already reverse-searched before * @throws Exception if an exception occurs while getting the edges */ private boolean reverseSearch(Object node) throws SearchException { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "reverseSearch:" + node ); } if (this.reverseScannedNodes.contains(node)) { if ( this.logger.isDebugEnabled() ) { this.logger.debug( "already searched; returning true" ); } return true; } if (!this.callback.searchNode(node)) { if ( this.logger.isTraceEnabled() ) { this.logger.trace( "callback handler blocked filtered out node (reverse) " + node ); } return true; } if ( this.logger.isDebugEnabled() ) { this.logger.debug("Pushing (reverse) " + node); } this.reverseScannedNodes.add(node); // first, search the nodes the node depends on SortedSet edges = this.callback.getEdges(node); if (edges != null) { Iterator iterator = edges.iterator(); while (iterator.hasNext()) { // and recursively search these nodes if we find a match IEdge edge = (IEdge) iterator.next(); Object toNode = edge.getTo(); if ( toNode.equals(node) ) { Object fromNode = edge.getFrom(); reverseSearch(fromNode); } } } // finally, add the node to the input this.nodesFrom.add(node); return false; } } --- NEW FILE: ISearchAlgorithm.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.Set; /** * Interface representing an algorithm that searchs a graph. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 * */ public interface ISearchAlgorithm { /** * Search all nodes that originates from a set of nodes. * * @param nodesFrom input nodes * @param callback helper callback * @return all nodes, in the right dependent order (like a LinkedHashSet) * @throws Exception exception wrapper */ Set search(Set nodesFrom, ISearchCallback callback) throws SearchException; } --- NEW FILE: AbstractIncludeNodesSearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.Set; /** * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 * */ public abstract class AbstractIncludeNodesSearchCallback extends AbstractNodesFilterSearchCallback { public AbstractIncludeNodesSearchCallback(Set allowedNodes) { super(); setAllowedNodes(allowedNodes); } public AbstractIncludeNodesSearchCallback(Object[] allowedNodes) { super(); setAllowedNodes(allowedNodes); } } --- NEW FILE: ISearchCallback.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.search; import java.util.SortedSet; /** * Callback used by the search algorithms.<br> * This interface is responsible for providing the edges of the graph and it can * be notified of some events generated by the search. * * @author Felipe Leme <db...@fe...> * @version $Revision: 1.1 $ * @since Aug 25, 2005 */ public interface ISearchCallback { /** * Get the edges originating from a node. * * @param node * node from * @return all edges originating from this node. * @throws Exception * exception wrapper */ SortedSet getEdges(Object fromNode) throws SearchException; /** * Notifies the callback that a node has been added to the search result. * * @param fromNode * node that has been added. * @throws Exception * exception wrapper */ void nodeAdded(Object fromNode) throws SearchException; /** * Decides if a node should be searched or not * * @param node * node to be filtered * @return true if the node should be searched * @throws Exception * exception wrapper */ boolean searchNode(Object node) throws SearchException; } |
From: <de...@us...> - 2005-10-18 14:43:42
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/src/test/org/dbunit Modified Files: HypersonicEnvironment.java AllTests.java Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. Index: HypersonicEnvironment.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/HypersonicEnvironment.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** HypersonicEnvironment.java 10 May 2004 23:33:29 -0000 1.11 --- HypersonicEnvironment.java 18 Oct 2005 14:43:30 -0000 1.12 *************** *** 27,32 **** --- 27,34 ---- import java.io.File; import java.io.FileReader; + import java.io.FilenameFilter; import java.sql.Connection; import java.sql.DriverManager; + import java.sql.SQLException; import java.sql.Statement; *************** *** 38,94 **** public class HypersonicEnvironment extends DatabaseEnvironment { ! public HypersonicEnvironment(DatabaseProfile profile) throws Exception ! { ! super(profile); ! // Creates required tables into the hypersonic in-memory database ! File ddlFile = new File("src/sql/hypersonic.sql"); ! Connection connection = getConnection().getConnection(); ! executeDdlFile(ddlFile, connection); ! } ! public static void executeDdlFile(File ddlFile, Connection connection) throws Exception ! { ! BufferedReader sqlReader = new BufferedReader(new FileReader(ddlFile)); ! StringBuffer sqlBuffer = new StringBuffer(); ! while (sqlReader.ready()) ! { ! String line = sqlReader.readLine(); ! if (!line.startsWith("-")) ! { ! sqlBuffer.append(line); ! } ! } ! String sql = sqlBuffer.toString(); ! Statement statement = connection.createStatement(); ! try ! { ! statement.execute(sql); ! } ! finally ! { ! statement.close(); ! } ! } ! public static Connection createJdbcConnection(String databaseName) throws Exception ! { ! Class.forName("org.hsqldb.jdbcDriver"); ! Connection connection = DriverManager.getConnection( ! "jdbc:hsqldb:" + databaseName, "sa", ""); ! return connection; ! } ! public void closeConnection() throws Exception ! { ! DatabaseOperation.DELETE_ALL.execute(getConnection(), getInitDataSet()); ! } ! } --- 40,122 ---- public class HypersonicEnvironment extends DatabaseEnvironment { ! public HypersonicEnvironment(DatabaseProfile profile) throws Exception ! { ! super(profile); ! // Creates required tables into the hypersonic in-memory database ! File ddlFile = new File("src/sql/hypersonic.sql"); ! Connection connection = getConnection().getConnection(); ! executeDdlFile(ddlFile, connection); ! } ! public static void executeDdlFile(File ddlFile, Connection connection) throws Exception ! { ! BufferedReader sqlReader = new BufferedReader(new FileReader(ddlFile)); ! StringBuffer sqlBuffer = new StringBuffer(); ! while (sqlReader.ready()) ! { ! String line = sqlReader.readLine(); ! if (!line.startsWith("-")) ! { ! sqlBuffer.append(line); ! } ! } ! String sql = sqlBuffer.toString(); ! executeSql( connection, sql ); ! } ! ! public static void executeSql( Connection connection, String sql ) throws SQLException { ! Statement statement = connection.createStatement(); ! try ! { ! statement.execute(sql); ! } ! finally ! { ! statement.close(); ! } ! } ! public static Connection createJdbcConnection(String databaseName) throws Exception ! { ! Class.forName("org.hsqldb.jdbcDriver"); ! Connection connection = DriverManager.getConnection( ! "jdbc:hsqldb:" + databaseName, "sa", ""); ! return connection; ! } ! public void closeConnection() throws Exception ! { ! DatabaseOperation.DELETE_ALL.execute(getConnection(), getInitDataSet()); ! } + public static void shutdown(Connection connection) throws SQLException { + executeSql( connection, "SHUTDOWN IMMEDIATELY" ); + } + public static void deleteFiles(final String filename) { + File[] files = new File(".").listFiles(new FilenameFilter() + { + public boolean accept(File dir, String name) + { + if (name.indexOf(filename) != -1) + { + return true; + } + return false; + } + }); + for (int i = 0; i < files.length; i++) + { + File file = files[i]; + file.delete(); + } + } + + } Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/AllTests.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AllTests.java 22 Jan 2004 02:54:20 -0000 1.13 --- AllTests.java 18 Oct 2005 14:43:30 -0000 1.14 *************** *** 36,44 **** suite.addTest(org.dbunit.ant.AllTests.suite()); suite.addTest(org.dbunit.database.AllTests.suite()); suite.addTest(org.dbunit.dataset.AllTests.suite()); suite.addTest(org.dbunit.ext.AllTests.suite()); suite.addTest(org.dbunit.operation.AllTests.suite()); suite.addTest(new TestSuite(AssertionTest.class)); - return suite; } --- 36,45 ---- suite.addTest(org.dbunit.ant.AllTests.suite()); suite.addTest(org.dbunit.database.AllTests.suite()); + suite.addTest(org.dbunit.database.search.AllTests.suite()); suite.addTest(org.dbunit.dataset.AllTests.suite()); suite.addTest(org.dbunit.ext.AllTests.suite()); suite.addTest(org.dbunit.operation.AllTests.suite()); + suite.addTest(org.dbunit.util.search.AllTests.suite()); suite.addTest(new TestSuite(AssertionTest.class)); return suite; } |
From: <de...@us...> - 2005-10-18 14:43:41
|
Update of /cvsroot/dbunit/dbunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808 Modified Files: project.xml Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. Index: project.xml =================================================================== RCS file: /cvsroot/dbunit/dbunit/project.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** project.xml 19 Aug 2005 21:50:43 -0000 1.22 --- project.xml 18 Oct 2005 14:43:30 -0000 1.23 *************** *** 165,168 **** --- 165,171 ---- --> </contributor> + <contributor> + <name>Felipe Leme</name> + </contributor> </contributors> *************** *** 188,192 **** <dependency> <id>hsqldb</id> ! <version>1.7.1</version> </dependency> <!-- --- 191,195 ---- <dependency> <id>hsqldb</id> ! <version>1.7.3.0</version> </dependency> <!-- *************** *** 215,218 **** --- 218,241 ---- <version>1.12.0</version> </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.0.4</version> + </dependency> + <dependency> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + <version>1.4</version> + </dependency> </dependencies> |
From: <de...@us...> - 2005-10-18 14:43:41
|
Update of /cvsroot/dbunit/dbunit/xdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30808/xdocs Modified Files: changes.xml Log Message: Addition of a search api and implementation from Felipe. Updates to dependencies, cleanup of Hypersonic startup/shutdown process. Index: changes.xml =================================================================== RCS file: /cvsroot/dbunit/dbunit/xdocs/changes.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** changes.xml 18 Oct 2005 12:55:30 -0000 1.21 --- changes.xml 18 Oct 2005 14:43:30 -0000 1.22 *************** *** 8,13 **** <body> ! <release version="2.2" date="IN CVS" description=""> ! <action dev="dep4b" due-to="Reuben Firmin" type="fix" issue="1328956">NPE In InsertIdentityOperation.</action> <action dev="dep4b" due-to="John Lewis" type="add" issue="1264212">Add "transaction" attribute to ant tasks to wrap operations in a single transaction. Can make operations faster.</action> <action dev="dep4b" due-to="Jeremy Frens" type="fix">Typo in howto example</action> --- 8,16 ---- <body> ! <release version="2.2" date="IN CVS" description=""> ! <action dev="dep4b" type="remove" issue="1273949">Remove deprecated org.dbunit.operation.mssqlserver.InsertIdentityOperation. Please use o.d.ext.mssql.InsertIdentityOperation</action> ! <action dev="dep4b" due-to="Felipe Leme" type="fix" issue="1273949">Refactor <code>DatabaseSequenceFilter</code> to use the new depth-first algorithm - fixed the cyclic dependencies issue.</action> ! <action dev="dep4b" due-to="Felipe Leme" type="add" issue="1273949">Add packages <code>org.dbunit.util.search</code> and <code>org.dbunit.database.search</code>, which provides a depth-first algorithm which is used to find the dependency on tables relationshipts</action> ! <action dev="dep4b" due-to="Reuben Firmin" type="fix" issue="1328956">NPE In InsertIdentityOperation.</action> <action dev="dep4b" due-to="John Lewis" type="add" issue="1264212">Add "transaction" attribute to ant tasks to wrap operations in a single transaction. Can make operations faster.</action> <action dev="dep4b" due-to="Jeremy Frens" type="fix">Typo in howto example</action> *************** *** 151,155 **** </action> <action dev="" type="update"> ! Moved InsertIdentityOperation to "org.dbunit.ext.mssql" package to be consistent with other vendor extensions. Temporary keep a deprecated copy in "org.dbunit.operation.mssqlserver" to ease transition to DbUnit 2. </action> </release> --- 154,158 ---- </action> <action dev="" type="update"> ! Moved `Operation to "org.dbunit.ext.mssql" package to be consistent with other vendor extensions. Temporary keep a deprecated copy in "org.dbunit.operation.mssqlserver" to ease transition to DbUnit 2. </action> </release> |