Source Code Cross Referenced for GenericObjectDropper.java in  » Database-Client » SQL-Workbench » workbench » db » 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 » Database Client » SQL Workbench » workbench.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GenericObjectDropper.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.db;
013:
014:        import java.sql.SQLException;
015:        import java.sql.Statement;
016:        import java.util.List;
017:
018:        import workbench.interfaces.ObjectDropper;
019:        import workbench.log.LogMgr;
020:        import workbench.util.SqlUtil;
021:        import workbench.util.StringUtil;
022:
023:        /**
024:         * A helper class to drop different types of objects
025:         * 
026:         * @author  support@sql-workbench.net
027:         */
028:        public class GenericObjectDropper implements  ObjectDropper {
029:            private List<? extends DbObject> objects;
030:            private WbConnection connection;
031:            private Statement currentStatement;
032:            private boolean cascadeConstraints;
033:            private TableIdentifier objectTable;
034:
035:            public GenericObjectDropper() {
036:            }
037:
038:            public List<? extends DbObject> getObjects() {
039:                return objects;
040:            }
041:
042:            public boolean supportsCascade() {
043:                boolean canCascade = false;
044:
045:                if (objects != null && this .connection != null) {
046:                    int numTypes = this .objects.size();
047:                    for (int i = 0; i < numTypes; i++) {
048:                        String type = this .objects.get(i).getObjectType();
049:                        String verb = this .connection.getDbSettings()
050:                                .getCascadeConstraintsVerb(type);
051:
052:                        // if at least one type can be dropped with CASCADE, enable the checkbox
053:                        if (!StringUtil.isEmptyString(verb)) {
054:                            canCascade = true;
055:                            break;
056:                        }
057:                    }
058:                }
059:                return canCascade;
060:            }
061:
062:            public void setObjects(List<? extends DbObject> toDrop) {
063:                this .objects = toDrop;
064:            }
065:
066:            public void setObjectTable(TableIdentifier tbl) {
067:                this .objectTable = tbl;
068:            }
069:
070:            public void setConnection(WbConnection aConn) {
071:                this .connection = aConn;
072:            }
073:
074:            public void dropObjects() throws SQLException {
075:                boolean needCommit = this .connection.shouldCommitDDL();
076:
077:                try {
078:                    if (this .connection == null)
079:                        throw new NullPointerException("No connection!");
080:                    if (this .connection.isBusy())
081:                        return;
082:                    if (this .objects == null || this .objects.size() == 0)
083:                        return;
084:                    int count = this .objects.size();
085:                    this .connection.setBusy(true);
086:
087:                    currentStatement = this .connection.createStatement();
088:
089:                    String cascade = null;
090:
091:                    boolean needTableForIndexDrop = this .connection
092:                            .getDbSettings().needsTableForDropIndex();
093:
094:                    for (int i = 0; i < count; i++) {
095:                        String name = this .objects.get(i).getObjectName();
096:                        String type = this .objects.get(i).getObjectType();
097:
098:                        StringBuilder sql = new StringBuilder(120);
099:                        sql.append("DROP ");
100:                        sql.append(type);
101:                        sql.append(' ');
102:                        sql.append(name);
103:
104:                        if (needTableForIndexDrop && "INDEX".equals(type)
105:                                && objectTable != null) {
106:                            sql.append(" ON ");
107:                            sql.append(objectTable
108:                                    .getTableExpression(this .connection));
109:                        }
110:
111:                        if (this .cascadeConstraints) {
112:                            cascade = this .connection.getDbSettings()
113:                                    .getCascadeConstraintsVerb(type);
114:                            if (cascade != null) {
115:                                sql.append(' ');
116:                                sql.append(cascade);
117:                            }
118:                        }
119:                        LogMgr.logDebug("ObjectDropper.execute()",
120:                                "Using SQL: " + sql);
121:                        currentStatement.execute(sql.toString());
122:                    }
123:
124:                    if (needCommit) {
125:                        this .connection.commit();
126:                    }
127:                } catch (SQLException e) {
128:                    if (needCommit) {
129:                        try {
130:                            this .connection.rollback();
131:                        } catch (Throwable th) {
132:                        }
133:                    }
134:                    throw e;
135:                } finally {
136:                    SqlUtil.closeStatement(currentStatement);
137:                    this .currentStatement = null;
138:                    this .connection.setBusy(false);
139:                }
140:            }
141:
142:            public void cancel() throws SQLException {
143:                if (this .currentStatement == null)
144:                    return;
145:                this .currentStatement.cancel();
146:                if (this .connection.shouldCommitDDL()) {
147:                    try {
148:                        this .connection.rollback();
149:                    } catch (Throwable th) {
150:                    }
151:                }
152:            }
153:
154:            public void setCascade(boolean flag) {
155:                this.cascadeConstraints = flag;
156:            }
157:
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.