Source Code Cross Referenced for TablesDependencyHelper.java in  » Testing » DbUnit » org » dbunit » database » search » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » DbUnit » org.dbunit.database.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * The DbUnit Database Testing Framework
004:         * Copyright (C)2005, DbUnit.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         */
021:        package org.dbunit.database.search;
022:
023:        import org.slf4j.Logger;
024:        import org.slf4j.LoggerFactory;
025:
026:        import java.sql.SQLException;
027:        import java.util.HashMap;
028:        import java.util.Map;
029:        import java.util.Set;
030:
031:        import org.dbunit.database.IDatabaseConnection;
032:        import org.dbunit.dataset.FilteredDataSet;
033:        import org.dbunit.dataset.IDataSet;
034:        import org.dbunit.dataset.filter.ITableFilter;
035:
036:        import org.dbunit.util.CollectionsHelper;
037:        import org.dbunit.util.search.DepthFirstSearch;
038:        import org.dbunit.util.search.SearchException;
039:
040:        /**
041:         * Helper for the graph-search based classes used to calculate dependency
042:         * among tables.  
043:         * 
044:         * @author Felipe Leme <dbunit@felipeal.net>
045:         * @version $Revision: 554 $
046:         * @since Aug 26, 2005
047:         */
048:        public class TablesDependencyHelper {
049:
050:            /**
051:             * Logger for this class
052:             */
053:            private static final Logger logger = LoggerFactory
054:                    .getLogger(TablesDependencyHelper.class);
055:
056:            // this is a "static" class
057:            private TablesDependencyHelper() {
058:            }
059:
060:            /**
061:             * Get the name of all tables that depend on a root table (i.e, all tables whose PK
062:             * is a FK for the root table).
063:             * @param connection database conncetion
064:             * @param rootTable root table described above
065:             * @return name of all tables that depend on the root table (including the root table), 
066:             * in the right order for insertions
067:             * @throws SearchException if an exception occurred while calculating the order
068:             */
069:            public static String[] getDependentTables(
070:                    IDatabaseConnection connection, String rootTable)
071:                    throws SearchException {
072:                logger.debug("getDependentTables(connection=" + connection
073:                        + ", rootTable=" + rootTable + ") - start");
074:
075:                return getDependentTables(connection,
076:                        new String[] { rootTable });
077:            }
078:
079:            /**
080:             * Get the name of all tables that depend on the root tables (i.e, all tables whose PK
081:             * is a FK for one of root tables).
082:             * @param connection database conncetion
083:             * @param rootTables array of root tables described above
084:             * @return name of all tables that depend on the root tables (including the root tables), 
085:             * in the right order for insertions
086:             * @throws SearchException if an exception occurred while calculating the order
087:             */
088:            public static String[] getDependentTables(
089:                    IDatabaseConnection connection, String[] rootTables)
090:                    throws SearchException {
091:                logger.debug("getDependentTables(connection=" + connection
092:                        + ", rootTables=" + rootTables + ") - start");
093:
094:                ImportedKeysSearchCallback callback = new ImportedKeysSearchCallback(
095:                        connection);
096:                DepthFirstSearch search = new DepthFirstSearch();
097:                Set tables = search.search(rootTables, callback);
098:                return (String[]) CollectionsHelper.setToStrings(tables);
099:            }
100:
101:            /**
102:             * Get the name of all tables that depend on a root table ( i.e, all tables whose PK
103:             * is a FK for the root table) and also the tables the root table depends on 
104:             * (i.e., all tables which have a FK for the root table's PK). 
105:             * @param connection database conncetion
106:             * @param rootTable root table described above
107:             * @return name of all tables that depend on the root table (including the root table), 
108:             * in the right order for insertions
109:             * @throws SearchException if an exception occurred while calculating the order
110:             */
111:            public static String[] getAllDependentTables(
112:                    IDatabaseConnection connection, String rootTable)
113:                    throws SearchException {
114:                logger.debug("getAllDependentTables(connection=" + connection
115:                        + ", rootTable=" + rootTable + ") - start");
116:
117:                return getAllDependentTables(connection,
118:                        new String[] { rootTable });
119:            }
120:
121:            /**
122:             * Get the name of all tables that depend on the root tables ( i.e, all tables whose PK
123:             * is a FK for any of the root tables) and also the tables the root tables depends on 
124:             * (i.e., all tables which have a FK for any of the root table's PK). 
125:             * @param connection database conncetion
126:             * @param rootTables root tables described above
127:             * @return name of all tables that depend on the root tables (including the root tables), 
128:             * in the right order for insertions
129:             * @throws SearchException if an exception occurred while calculating the order
130:             */
131:            public static String[] getAllDependentTables(
132:                    IDatabaseConnection connection, String[] rootTables)
133:                    throws SearchException {
134:                logger.debug("getAllDependentTables(connection=" + connection
135:                        + ", rootTables=" + rootTables + ") - start");
136:
137:                ImportedAndExportedKeysSearchCallback callback = new ImportedAndExportedKeysSearchCallback(
138:                        connection);
139:                DepthFirstSearch search = new DepthFirstSearch();
140:                Set tables = search.search(rootTables, callback);
141:                return (String[]) CollectionsHelper.setToStrings(tables);
142:            }
143:
144:            // TODO: javadoc (and unit tests) from down here...
145:
146:            public static IDataSet getDataset(IDatabaseConnection connection,
147:                    String rootTable, Set allowedIds) throws SearchException,
148:                    SQLException {
149:                logger.debug("getDataset(connection=" + connection
150:                        + ", rootTable=" + rootTable + ", allowedIds="
151:                        + allowedIds + ") - start");
152:
153:                HashMap map = new HashMap(1);
154:                map.put(rootTable, allowedIds);
155:                return getDataset(connection, map);
156:            }
157:
158:            public static IDataSet getDataset(IDatabaseConnection connection,
159:                    Map rootTables) throws SearchException, SQLException {
160:                logger.debug("getDataset(connection=" + connection
161:                        + ", rootTables=" + rootTables + ") - start");
162:
163:                ImportedKeysSearchCallbackFilteredByPKs callback = new ImportedKeysSearchCallbackFilteredByPKs(
164:                        connection, rootTables);
165:                ITableFilter filter = callback.getFilter();
166:                DepthFirstSearch search = new DepthFirstSearch();
167:                String[] tableNames = CollectionsHelper.setToStrings(rootTables
168:                        .keySet());
169:                Set tmpTables = search.search(tableNames, callback);
170:                String[] dependentTables = CollectionsHelper
171:                        .setToStrings(tmpTables);
172:                IDataSet tmpDataset = connection.createDataSet(dependentTables);
173:                FilteredDataSet dataset = new FilteredDataSet(filter,
174:                        tmpDataset);
175:                return dataset;
176:            }
177:
178:            public static IDataSet getAllDataset(
179:                    IDatabaseConnection connection, String rootTable,
180:                    Set allowedPKs) throws SearchException, SQLException {
181:                logger.debug("getAllDataset(connection=" + connection
182:                        + ", rootTable=" + rootTable + ", allowedPKs="
183:                        + allowedPKs + ") - start");
184:
185:                HashMap map = new HashMap(1);
186:                map.put(rootTable, allowedPKs);
187:                return getAllDataset(connection, map);
188:            }
189:
190:            public static IDataSet getAllDataset(
191:                    IDatabaseConnection connection, Map rootTables)
192:                    throws SearchException, SQLException {
193:                logger.debug("getAllDataset(connection=" + connection
194:                        + ", rootTables=" + rootTables + ") - start");
195:
196:                ImportedAndExportedKeysSearchCallbackFilteredByPKs callback = new ImportedAndExportedKeysSearchCallbackFilteredByPKs(
197:                        connection, rootTables);
198:                ITableFilter filter = callback.getFilter();
199:                DepthFirstSearch search = new DepthFirstSearch();
200:                String[] tableNames = CollectionsHelper.setToStrings(rootTables
201:                        .keySet());
202:                Set tmpTables = search.search(tableNames, callback);
203:                String[] dependentTables = CollectionsHelper
204:                        .setToStrings(tmpTables);
205:                IDataSet tmpDataset = connection.createDataSet(dependentTables);
206:                FilteredDataSet dataset = new FilteredDataSet(filter,
207:                        tmpDataset);
208:                return dataset;
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.