Source Code Cross Referenced for QuerySet.java in  » Testing » DbUnit » org » dbunit » ant » 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.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * The DbUnit Database Testing Framework
004:         * Copyright (C)2002-2004, 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:
022:        package org.dbunit.ant;
023:
024:        import org.slf4j.Logger;
025:        import org.slf4j.LoggerFactory;
026:
027:        import java.util.*;
028:        import java.util.ArrayList;
029:        import java.util.List;
030:
031:        import org.apache.tools.ant.BuildException;
032:        import org.apache.tools.ant.types.FilterSet;
033:
034:        /**
035:         * This element is a container for Queries. It facilitates reuse
036:         * through references. Using Ant 1.6 and greater, references can be
037:         * defined in a single build file and <i>import</i>ed into many others.
038:         * An example of where this is useful follows:
039:         * <p>
040:         * In our database
041:         * we have INDIVIDUALS which must have an associated NAME_INFO and
042:         * at least one IND_ADDRESS. The developer creating a dataset for
043:         * his/her tests probably won't know all the details of what relationships are
044:         * expected, and if he did, its an error prone and repetitive task
045:         * to create the correct SQL for entities in each dataset.
046:         * Missing a related table, not only creates invalid data for your tests,
047:         * but also is likely to cause DBUnit setUp() failures due to foreign key
048:         * constraint errors.
049:         * (ex. If a previous test had inserted INDIVIDUALS
050:         * and NAME_INFO and my test tries to delete only the INDIVIDUALS, the
051:         * NAME_INFO.IND_ID constraint would prevent it)
052:         * <p>
053:         * Usage:
054:         *
055:         * <pre>
056:         * &lt;!-- ======== Define the reusable reference ========== --&gt;
057:         *
058:         * &lt;queryset id="individuals"&gt;
059:         *    &lt;query name="INDIVIDUALS" sql="
060:         *      SELECT * FROM APS_DATA.INDIVIDUALS WHERE IND_ID IN (@subQuery@)"/&gt;
061:         *
062:         *    &lt;query name="NAME_INFO" sql="
063:         *      SELECT B.* FROM APS_DATA.INDIVIDUALS A, APS_DATA.NAME_INFO B
064:         *      WHERE A.IND_ID IN (@subQuery@)
065:         *      AND B.IND_ID = A.IND_ID"/&gt;
066:         *
067:         *    &lt;query name="IND_ADDRESSES" sql="
068:         *      SELECT B.* FROM APS_DATA.INDIVIDUALS A, APS_DATA.IND_ADDRESSES B
069:         *      WHERE A.IND_ID IN (@subQuery@)
070:         *      AND B.IND_ID = A.IND_ID"/&gt;
071:         * &lt;/queryset&gt;
072:         *
073:         * &lt;!-- ========= Use the reference ====================== --&gt;
074:         *
075:         * &lt;dbunit dest="@{destDir}" driver="${jdbcDriver}"
076:         *     url="${jdbcURL}" userid="${jdbcUser}" password="${jdbcPassword}"&gt;
077:         *   &lt;export dest="someDir"&gt;
078:         *   &lt;queryset refid="individuals"&gt;
079:         *      &lt;filterset&gt;
080:         *        &lt;filter token="subQuery" value="
081:         *          SELECT IND_ID FROM APS_DATA.INDIVIDUALS WHERE USER_NAME = 'UNKNOWN'"/&gt;
082:         *      &lt;/filterset&gt;
083:         *   &lt;/queryset&gt;
084:         *
085:         *   &lt;queryset&gt;
086:         *      &lt;query name="MAN_EVENT_TYPE"
087:         *        sql="SELECT * FROM MANUSCRIPTS.MAN_EVENT_TYPE"/&gt;
088:         *      &lt;query name="JOURNAL" sql="SELECT * FROM MANUSCRIPTS.JOURNAL"/&gt;
089:         *   &lt;/queryset&gt;
090:         *   &lt;/export&gt;
091:         * &lt;/dbunit&gt;
092:         *
093:         * </pre>
094:         *
095:         * @author Lenny Marks lenny@aps.org
096:         * @version $Revision: 554 $
097:         * @since Sep. 13 2004
098:         */
099:        public class QuerySet {
100:
101:            /**
102:             * Logger for this class
103:             */
104:            private static final Logger logger = LoggerFactory
105:                    .getLogger(QuerySet.class);
106:
107:            private String id;
108:            private String refid;
109:            private List queries = new ArrayList();
110:            private List filterSets = new ArrayList();
111:
112:            private static String ERR_MSG = "Cannot specify 'id' and 'refid' attributes together in queryset.";
113:
114:            public QuerySet() {
115:                super ();
116:            }
117:
118:            public void addQuery(Query query) {
119:                logger.debug("addQuery(query=" + query + ") - start");
120:
121:                queries.add(query);
122:            }
123:
124:            public void addFilterSet(FilterSet filterSet) {
125:                logger.debug("addFilterSet(filterSet=" + filterSet
126:                        + ") - start");
127:
128:                filterSets.add(filterSet);
129:            }
130:
131:            public String getId() {
132:                logger.debug("getId() - start");
133:
134:                return id;
135:            }
136:
137:            public String getRefid() {
138:                logger.debug("getRefid() - start");
139:
140:                return refid;
141:            }
142:
143:            public void setId(String string) {
144:                logger.debug("setId(string=" + string + ") - start");
145:
146:                if (refid != null)
147:                    throw new BuildException(ERR_MSG);
148:                id = string;
149:            }
150:
151:            public void setRefid(String string) {
152:                logger.debug("setRefid(string=" + string + ") - start");
153:
154:                if (id != null)
155:                    throw new BuildException(ERR_MSG);
156:                refid = string;
157:            }
158:
159:            protected List getQueries() {
160:                logger.debug("getQueries() - start");
161:
162:                Iterator i = queries.iterator();
163:                while (i.hasNext()) {
164:                    Query query = (Query) i.next();
165:                    replaceTokens(query);
166:                }
167:
168:                return queries;
169:
170:            }
171:
172:            private void replaceTokens(Query query) {
173:                logger.debug("replaceTokens(query=" + query + ") - start");
174:
175:                Iterator i = filterSets.iterator();
176:                while (i.hasNext()) {
177:                    FilterSet filterSet = (FilterSet) i.next();
178:                    query.setSql(filterSet.replaceTokens(query.getSql()));
179:                }
180:            }
181:
182:            public void copyQueriesFrom(QuerySet referenced) {
183:                logger.debug("copyQueriesFrom(referenced=" + referenced
184:                        + ") - start");
185:
186:                Iterator i = referenced.queries.iterator();
187:                while (i.hasNext()) {
188:                    addQuery((Query) i.next());
189:                }
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.