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


001:        package net.sourceforge.squirrel_sql.fw.sql;
002:
003:        /*
004:         * Copyright (C) 2001-2003 Colin Bell
005:         * colbell@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 java.lang.reflect.Method;
022:        import java.sql.DatabaseMetaData;
023:        import java.sql.SQLException;
024:        import java.util.ArrayList;
025:        import java.util.HashMap;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:
030:        import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
031:        import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetDefinition;
032:        import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSet;
033:        import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
034:        import net.sourceforge.squirrel_sql.fw.util.NullMessageHandler;
035:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
036:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
037:
038:        public class MetaDataDataSet implements  IDataSet {
039:            /** Internationalized strings for this class. */
040:            private static final StringManager s_stringMgr = StringManagerFactory
041:                    .getStringManager(MetaDataDataSet.class);
042:
043:            private final static Map<String, Object> s_ignoreMethods = new HashMap<String, Object>();
044:            static {
045:                s_ignoreMethods.put("getCatalogs", null);
046:                s_ignoreMethods.put("getConnection", null);
047:                s_ignoreMethods.put("getSchemas", null);
048:                s_ignoreMethods.put("getTableTypes", null);
049:                s_ignoreMethods.put("getTypeInfo", null);
050:                s_ignoreMethods.put("fail", null);
051:                s_ignoreMethods.put("hashCode", null);
052:                s_ignoreMethods.put("toString", null);
053:                s_ignoreMethods.put("getNumericFunctions", null);
054:                s_ignoreMethods.put("getStringFunctions", null);
055:                s_ignoreMethods.put("getSystemFunctions", null);
056:                s_ignoreMethods.put("getTimeDateFunctions", null);
057:                s_ignoreMethods.put("getSQLKeywords", null);
058:            }
059:
060:            private static interface IStrings {
061:                String UNSUPPORTED = s_stringMgr
062:                        .getString("MetaDataDataSet.unsupported");
063:                String NAME_COLUMN = s_stringMgr
064:                        .getString("MetaDataDataSet.propname");
065:                String VALUE_COLUMN = s_stringMgr
066:                        .getString("MetaDataDataSet.value");
067:            }
068:
069:            private final static String[] s_hdgs = new String[] {
070:                    IStrings.NAME_COLUMN, IStrings.VALUE_COLUMN };
071:            private DataSetDefinition _dsDef;
072:
073:            private Iterator<Object[]> _rowsIter;
074:            private Object[] _row;
075:
076:            private IMessageHandler _msgHandler;
077:
078:            /**
079:             * Data. Each element represents a row of the table and is made up of
080:             * an array of strings. Each string is an element in the row.
081:             */
082:            private List<Object[]> _data = new ArrayList<Object[]>();
083:
084:            public MetaDataDataSet(DatabaseMetaData md) {
085:                this (md, null);
086:            }
087:
088:            public MetaDataDataSet(DatabaseMetaData md,
089:                    IMessageHandler msgHandler) {
090:                super ();
091:                _msgHandler = msgHandler != null ? msgHandler
092:                        : NullMessageHandler.getInstance();
093:                _dsDef = new DataSetDefinition(createColumnDefinitions());
094:                load(md);
095:            }
096:
097:            public final int getColumnCount() {
098:                return s_hdgs.length;
099:            }
100:
101:            public DataSetDefinition getDataSetDefinition() {
102:                return _dsDef;
103:            }
104:
105:            public synchronized boolean next(IMessageHandler msgHandler) {
106:                if (_rowsIter.hasNext()) {
107:                    _row = _rowsIter.next();
108:                } else {
109:                    _row = null;
110:                }
111:                return _row != null;
112:            }
113:
114:            public synchronized Object get(int columnIndex) {
115:                return _row[columnIndex];
116:            }
117:
118:            private ColumnDisplayDefinition[] createColumnDefinitions() {
119:                final int columnCount = getColumnCount();
120:                ColumnDisplayDefinition[] columnDefs = new ColumnDisplayDefinition[columnCount];
121:                for (int i = 0; i < columnCount; ++i) {
122:                    columnDefs[i] = new ColumnDisplayDefinition(200, s_hdgs[i]);
123:                }
124:                return columnDefs;
125:            }
126:
127:            private void load(DatabaseMetaData md) {
128:                Method[] methods = DatabaseMetaData.class.getMethods();
129:                for (int i = 0; i < methods.length; ++i) {
130:                    final Method method = methods[i];
131:                    if (method.getParameterTypes().length == 0
132:                            && method.getReturnType() != Void.TYPE
133:                            && !s_ignoreMethods.containsKey(method.getName())) {
134:                        _data.add(generateLine(md, method));
135:                    }
136:                }
137:
138:                // Sort the rows by the property name.
139:                //		Collections.sort(_data, new DataSorter());
140:
141:                _rowsIter = _data.iterator();
142:            }
143:
144:            /**
145:             * Generate a line for the result of calling the passed method.
146:             *
147:             * @param   getter	  The "getter" function to retrieve the
148:             *					  properties value.
149:             *
150:             * @return  An <TT>Object[]</CODE> containing the cells for the line in
151:             *		  the table. Element zero the first cell etc. Return
152:             *		  <CODE>null</CODE> if this property is <B>not</B> to be added
153:             *		  to the table.
154:             */
155:            private Object[] generateLine(DatabaseMetaData md, Method getter) {
156:                final Object[] line = new Object[2];
157:                line[0] = getter.getName();
158:                if (line[0].equals("getDefaultTransactionIsolation")) {
159:                    try {
160:                        line[1] = IStrings.UNSUPPORTED;
161:                        final int isol = md.getDefaultTransactionIsolation();
162:                        switch (isol) {
163:                        case java.sql.Connection.TRANSACTION_NONE: {
164:                            line[1] = "TRANSACTION_NONE";
165:                            break;
166:                        }
167:                        case java.sql.Connection.TRANSACTION_READ_COMMITTED: {
168:                            line[1] = "TRANSACTION_READ_COMMITTED";
169:                            break;
170:                        }
171:                        case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED: {
172:                            line[1] = "TRANSACTION_READ_UNCOMMITTED";
173:                            break;
174:                        }
175:                        case java.sql.Connection.TRANSACTION_REPEATABLE_READ: {
176:                            line[1] = "TRANSACTION_REPEATABLE_READ";
177:                            break;
178:                        }
179:                        case java.sql.Connection.TRANSACTION_SERIALIZABLE: {
180:                            line[1] = "TRANSACTION_SERIALIZABLE";
181:                            break;
182:                        }
183:                        default: {
184:                            line[1] = "" + isol + "?";
185:                            break;
186:                        }
187:                        }
188:                    } catch (SQLException ex) {
189:                        _msgHandler.showMessage(ex, null);
190:                    }
191:
192:                } else {
193:                    Object obj = executeGetter(md, getter);
194:                    line[1] = obj;
195:                }
196:                return line;
197:            }
198:
199:            protected Object executeGetter(Object bean, Method getter) {
200:                try {
201:                    return getter.invoke(bean, (Object[]) null);
202:                } catch (Throwable th) {
203:                    return IStrings.UNSUPPORTED;
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.