Source Code Cross Referenced for TableSourceTab.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » db2 » tab » 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 » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.db2.tab 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.db2.tab;
002:
003:        /*
004:         * Copyright (C) 2007 Rob Manning
005:         * manningr@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        import static java.util.Arrays.asList;
022:
023:        import java.sql.PreparedStatement;
024:        import java.sql.SQLException;
025:        import java.util.List;
026:
027:        import net.sourceforge.squirrel_sql.client.session.ISession;
028:        import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.FormattedSourceTab;
029:        import net.sourceforge.squirrel_sql.fw.dialects.CreateScriptPreferences;
030:        import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
031:        import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
032:        import net.sourceforge.squirrel_sql.fw.dialects.UnknownDialectException;
033:        import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
034:        import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
035:        import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
036:        import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
037:        import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
038:        import net.sourceforge.squirrel_sql.fw.sql.TableInfo;
039:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
040:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
041:
042:        /**
043:         * This class will display the source for a DB2 table (including MQTs).
044:         *
045:         * @author manningr
046:         */
047:        public class TableSourceTab extends FormattedSourceTab {
048:            /** SQL that retrieves the source of a MQT. */
049:            private static final String MQT_SQL = "SELECT text "
050:                    + "FROM SYSCAT.VIEWS " + "WHERE viewschema = ? "
051:                    + "and viewname = ? ";
052:
053:            /** SQL that retrieves the source of a MQT on OS/400 */
054:            private static final String OS400_MQT_SQL = "select mqt_definition "
055:                    + "from qsys2.systables "
056:                    + "where table_schema = ? "
057:                    + "and table_name = ? ";
058:
059:            /** Logger for this class. */
060:            private final static ILogger s_log = LoggerController
061:                    .createLogger(ViewSourceTab.class);
062:
063:            /** boolean to indicate whether or not this session is OS/400 */
064:            private boolean isOS400 = false;
065:
066:            /**
067:             * Constructor
068:             * 
069:             * @param isOS400 whether or not we are connected to an OS/400 system
070:             */
071:            public TableSourceTab(String hint, String stmtSep, boolean isOS400) {
072:                super (hint);
073:                super .setCompressWhitespace(true);
074:                super .setupFormatter(stmtSep, null);
075:                this .isOS400 = isOS400;
076:            }
077:
078:            /**
079:             * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BaseSourceTab#createStatement()
080:             */
081:            @Override
082:            protected PreparedStatement createStatement() throws SQLException {
083:                final ISession session = getSession();
084:                final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
085:
086:                ISQLConnection conn = session.getSQLConnection();
087:                String sql = MQT_SQL;
088:                if (isOS400) {
089:                    sql = OS400_MQT_SQL;
090:                }
091:                if (!isMQT()) {
092:                    sql = getTableSelectSql((ITableInfo) doi);
093:
094:                    // we may have more than one statement in sql at this point
095:                    super .appendSeparator = false;
096:                } else {
097:                    // MQTs only ever have one sql statement
098:                    super .appendSeparator = true;
099:                }
100:                if (s_log.isDebugEnabled()) {
101:                    s_log.debug("Running SQL for View source tab: " + sql);
102:                    s_log.debug("schema=" + doi.getSchemaName());
103:                    s_log.debug("view name=" + doi.getSimpleName());
104:                }
105:                PreparedStatement pstmt = conn.prepareStatement(sql);
106:                if (isMQT()) {
107:                    pstmt.setString(1, doi.getSchemaName());
108:                    pstmt.setString(2, doi.getSimpleName());
109:                }
110:                return pstmt;
111:            }
112:
113:            private boolean isMQT() {
114:                final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
115:
116:                boolean isMQT = false;
117:
118:                if (doi.getDatabaseObjectType() == DatabaseObjectType.TABLE) {
119:                    TableInfo info = (TableInfo) doi;
120:                    if (info.getType().startsWith("MATERIALIZED")) {
121:                        isMQT = true;
122:                        if (s_log.isDebugEnabled()) {
123:                            s_log.debug("Table " + doi.getSimpleName()
124:                                    + " appears to be an MQT");
125:                        }
126:                    } else {
127:                        if (s_log.isDebugEnabled()) {
128:                            s_log.debug("Table " + doi.getSimpleName()
129:                                    + " appears to be a regular table");
130:                        }
131:                    }
132:                }
133:
134:                return isMQT;
135:            }
136:
137:            private String getTableSelectSql(ITableInfo ti) {
138:                String sql = getRegularTableSelectSql(ti);
139:                if (sql == null) {
140:                    sql = MQT_SQL;
141:                }
142:                return sql;
143:            }
144:
145:            /**
146:             * This builds a create statement 
147:             * @param ti
148:             * @return
149:             */
150:            private String getRegularTableSelectSql(ITableInfo ti) {
151:                StringBuilder tmp = new StringBuilder();
152:                tmp.append("select '");
153:
154:                ISQLDatabaseMetaData md = getSession().getMetaData();
155:                try {
156:                    HibernateDialect dialect = DialectFactory.getDialect(md);
157:                    List<ITableInfo> tableList = asList(new ITableInfo[] { ti });
158:                    CreateScriptPreferences prefs = new CreateScriptPreferences();
159:                    List<String> sqls = dialect.getCreateTableSQL(tableList,
160:                            md, prefs, false);
161:                    for (String sql : sqls) {
162:                        tmp.append(sql);
163:                        tmp.append(statementSeparator);
164:                        tmp.append("\n");
165:                        tmp.append("\n");
166:                    }
167:                } catch (UnknownDialectException e) {
168:                    s_log
169:                            .error("createStatement: Unable to determine the dialect "
170:                                    + "to use");
171:                    return null;
172:                } catch (SQLException e) {
173:                    s_log.error("createStatement: Unexpected exception while "
174:                            + "constructing SQL for table("
175:                            + ti.getSimpleName() + "): " + e.getMessage(), e);
176:                    return null;
177:                }
178:                tmp.append("' from sysibm.sysdummy1");
179:                return tmp.toString();
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.