Source Code Cross Referenced for Export.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.io.File;
028:        import java.io.FileOutputStream;
029:        import java.io.IOException;
030:        import java.io.OutputStream;
031:        import java.util.ArrayList;
032:        import java.util.Arrays;
033:        import java.util.List;
034:
035:        import org.apache.tools.ant.Project;
036:        import org.dbunit.DatabaseUnitException;
037:        import org.dbunit.database.IDatabaseConnection;
038:        import org.dbunit.dataset.IDataSet;
039:        import org.dbunit.dataset.csv.CsvDataSetWriter;
040:        import org.dbunit.dataset.xml.FlatDtdDataSet;
041:        import org.dbunit.dataset.xml.FlatXmlWriter;
042:        import org.dbunit.dataset.xml.XmlDataSet;
043:
044:        /**
045:         * The <code>Export</code> class is the step that facilitates exporting
046:         * the contents of the database and/or it's corresponding dtd to a file.
047:         * The export can be performed on a full dataset or a partial one if
048:         * specific table names are identified.
049:         *
050:         * @author Timothy Ruppert
051:         * @author Ben Cox
052:         * @version $Revision: 554 $
053:         * @since Jun 10, 2002
054:         * @see DbUnitTaskStep
055:         */
056:        public class Export extends AbstractStep {
057:
058:            /**
059:             * Logger for this class
060:             */
061:            private static final Logger logger = LoggerFactory
062:                    .getLogger(Export.class);
063:
064:            private File _dest;
065:            private String _format = FORMAT_FLAT;
066:            private String _doctype = null;
067:            private List _tables = new ArrayList();
068:
069:            public Export() {
070:            }
071:
072:            private String getAbsolutePath(File filename) {
073:                logger.debug("getAbsolutePath(filename=" + filename
074:                        + ") - start");
075:
076:                return filename != null ? filename.getAbsolutePath() : "null";
077:            }
078:
079:            public File getDest() {
080:                logger.debug("getDest() - start");
081:
082:                return _dest;
083:            }
084:
085:            public String getFormat() {
086:                logger.debug("getFormat() - start");
087:
088:                return _format;
089:            }
090:
091:            public List getTables() {
092:                logger.debug("getTables() - start");
093:
094:                return _tables;
095:            }
096:
097:            public void setDest(File dest) {
098:                logger.debug("setDest(dest=" + dest + ") - start");
099:
100:                _dest = dest;
101:            }
102:
103:            public void setFormat(String format) {
104:                logger.debug("setFormat(format=" + format + ") - start");
105:
106:                if (format.equalsIgnoreCase(FORMAT_FLAT)
107:                        || format.equalsIgnoreCase(FORMAT_XML)
108:                        || format.equalsIgnoreCase(FORMAT_DTD)
109:                        || format.equalsIgnoreCase(FORMAT_CSV)) {
110:                    _format = format;
111:                } else {
112:                    throw new IllegalArgumentException(
113:                            "Type must be one of: 'flat'(default), 'xml', or 'dtd' but was: "
114:                                    + format);
115:                }
116:            }
117:
118:            public void addTable(Table table) {
119:                logger.debug("addTable(table=" + table + ") - start");
120:
121:                _tables.add(table);
122:            }
123:
124:            public void addQuery(Query query) {
125:                logger.debug("addQuery(query=" + query + ") - start");
126:
127:                _tables.add(query);
128:            }
129:
130:            public void addQuerySet(QuerySet querySet) {
131:                logger.debug("addQuerySet(querySet=" + querySet + ") - start");
132:
133:                _tables.add(querySet);
134:            }
135:
136:            public String getDoctype() {
137:                logger.debug("getDoctype() - start");
138:
139:                return _doctype;
140:            }
141:
142:            public void setDoctype(String doctype) {
143:                logger.debug("setDoctype(doctype=" + doctype + ") - start");
144:
145:                _doctype = doctype;
146:            }
147:
148:            public void execute(IDatabaseConnection connection)
149:                    throws DatabaseUnitException {
150:                logger.debug("execute(connection=" + connection + ") - start");
151:
152:                try {
153:                    if (_dest == null) {
154:                        throw new DatabaseUnitException(
155:                                "'_dest' is a required attribute of the <export> step.");
156:                    }
157:
158:                    IDataSet dataset = getDatabaseDataSet(connection, _tables,
159:                            false);
160:
161:                    log("dataset tables: "
162:                            + Arrays.asList(dataset.getTableNames()),
163:                            Project.MSG_VERBOSE);
164:
165:                    // Write the dataset
166:                    if (_format.equals(FORMAT_CSV)) {
167:                        CsvDataSetWriter.write(dataset, _dest);
168:                    } else {
169:                        OutputStream out = new FileOutputStream(_dest);
170:                        try {
171:                            if (_format.equalsIgnoreCase(FORMAT_FLAT)) {
172:                                FlatXmlWriter writer = new FlatXmlWriter(out);
173:                                writer.setDocType(_doctype);
174:                                writer.write(dataset);
175:                            } else if (_format.equalsIgnoreCase(FORMAT_XML)) {
176:                                XmlDataSet.write(dataset, out);
177:                            } else if (_format.equalsIgnoreCase(FORMAT_DTD)) {
178:                                FlatDtdDataSet.write(dataset, out);
179:                            }
180:
181:                        } finally {
182:                            out.close();
183:                        }
184:                    }
185:
186:                } catch (IOException e) {
187:                    logger.error("execute()", e);
188:
189:                    throw new DatabaseUnitException(e);
190:                }
191:            }
192:
193:            public String getLogMessage() {
194:                logger.debug("getLogMessage() - start");
195:
196:                return "Executing export: " + "\n      in format: " + _format
197:                        + " to datafile: " + getAbsolutePath(_dest);
198:            }
199:
200:            public String toString() {
201:                logger.debug("toString() - start");
202:
203:                StringBuffer result = new StringBuffer();
204:                result.append("Export: ");
205:                result.append(" dest=" + getAbsolutePath(_dest));
206:                result.append(", format= " + _format);
207:                result.append(", doctype= " + _doctype);
208:                result.append(", tables= " + _tables);
209:
210:                return result.toString();
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.