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


001:        /*
002:         * The DbUnit Database Testing Framework
003:         * Copyright (C)2002-2004, DbUnit.org
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         */
020:
021:        package org.dbunit.operation;
022:
023:        import org.slf4j.Logger;
024:        import org.slf4j.LoggerFactory;
025:
026:        import org.dbunit.DatabaseUnitException;
027:        import org.dbunit.database.DatabaseConfig;
028:        import org.dbunit.database.IDatabaseConnection;
029:        import org.dbunit.database.statement.IBatchStatement;
030:        import org.dbunit.database.statement.IStatementFactory;
031:        import org.dbunit.dataset.IDataSet;
032:        import org.dbunit.dataset.ITableIterator;
033:        import org.dbunit.dataset.ITableMetaData;
034:
035:        import java.sql.SQLException;
036:        import java.util.HashSet;
037:        import java.util.Set;
038:        import java.util.Stack;
039:
040:        /**
041:         * Deletes all rows of tables present in the specified dataset. If the dataset
042:         * does not contains a particular table, but that table exists in the database,
043:         * the database table is not affected. Table are truncated in
044:         * reverse sequence.
045:         * <p/>
046:         * This operation has the same effect of as {@link TruncateTableOperation}.
047:         * TruncateTableOperation is faster, and it is non-logged, meaning it cannot be
048:         * rollback. DeleteAllOperation is more portable because not all database vendor
049:         * support TRUNCATE_TABLE TABLE statement.
050:         *
051:         * @author Manuel Laflamme
052:         * @version $Revision: 554 $
053:         * @see TruncateTableOperation
054:         * @since Feb 18, 2002
055:         */
056:        public class DeleteAllOperation extends AbstractOperation {
057:
058:            /**
059:             * Logger for this class
060:             */
061:            private static final Logger logger = LoggerFactory
062:                    .getLogger(DeleteAllOperation.class);
063:
064:            DeleteAllOperation() {
065:            }
066:
067:            protected String getDeleteAllCommand() {
068:                logger.debug("getDeleteAllCommand() - start");
069:
070:                return "delete from ";
071:            }
072:
073:            ////////////////////////////////////////////////////////////////////////////
074:            // DatabaseOperation class
075:
076:            public void execute(IDatabaseConnection connection, IDataSet dataSet)
077:                    throws DatabaseUnitException, SQLException {
078:                logger.debug("execute(connection=" + connection + ", dataSet="
079:                        + dataSet + ") - start");
080:
081:                IDataSet databaseDataSet = connection.createDataSet();
082:
083:                DatabaseConfig databaseConfig = connection.getConfig();
084:                IStatementFactory statementFactory = (IStatementFactory) databaseConfig
085:                        .getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
086:                IBatchStatement statement = statementFactory
087:                        .createBatchStatement(connection);
088:                try {
089:                    int count = 0;
090:
091:                    Stack tableNames = new Stack();
092:                    Set tablesSeen = new HashSet();
093:                    ITableIterator iterator = dataSet.iterator();
094:                    while (iterator.next()) {
095:                        String tableName = iterator.getTableMetaData()
096:                                .getTableName();
097:                        if (!tablesSeen.contains(tableName)) {
098:                            tableNames.push(tableName);
099:                            tablesSeen.add(tableName);
100:                        }
101:                    }
102:
103:                    // delete tables once each in reverse order of seeing them.
104:                    while (!tableNames.isEmpty()) {
105:                        String tableName = (String) tableNames.pop();
106:
107:                        // Use database table name. Required to support case sensitive database.
108:                        ITableMetaData databaseMetaData = databaseDataSet
109:                                .getTableMetaData(tableName);
110:                        tableName = databaseMetaData.getTableName();
111:
112:                        StringBuffer sqlBuffer = new StringBuffer(128);
113:                        sqlBuffer.append(getDeleteAllCommand());
114:                        sqlBuffer.append(getQualifiedName(connection
115:                                .getSchema(), tableName, connection));
116:                        statement.addBatch(sqlBuffer.toString());
117:
118:                        count++;
119:                    }
120:
121:                    if (count > 0) {
122:                        statement.executeBatch();
123:                        statement.clearBatch();
124:                    }
125:                } finally {
126:                    statement.close();
127:                }
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.