Source Code Cross Referenced for metadata.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbcapi » 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 DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.jdbcapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.metadata
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.functionTests.tests.jdbcapi;
023:
024:        import java.sql.Connection;
025:        import java.sql.DriverManager;
026:        import java.sql.DatabaseMetaData;
027:        import java.sql.ResultSetMetaData;
028:        import java.sql.Statement;
029:        import java.sql.CallableStatement;
030:        import java.sql.ResultSet;
031:        import java.sql.SQLException;
032:        import java.sql.Types;
033:        import java.sql.Timestamp;
034:        import java.sql.Time;
035:        import java.sql.Date;
036:        import java.math.BigDecimal;
037:
038:        import java.util.Properties;
039:
040:        import org.apache.derby.tools.ij;
041:
042:        /**
043:         * Test of database meta-data.  This program simply calls each of the meta-data
044:         * methods, one by one, and prints the results.  The test passes if the printed
045:         * results match a previously stored "master".  Thus this test cannot actually
046:         * discern whether it passes or not.
047:         *
048:         * @author alan
049:         */
050:
051:        public class metadata extends metadata_test {
052:
053:            public metadata() {
054:            }
055:
056:            /**
057:             * Constructor:
058:             * Just intializes the Connection and Statement fields
059:             * to be used through the test.
060:             */
061:            public metadata(String[] args) {
062:
063:                try {
064:
065:                    ij.getPropertyArg(args);
066:                    con = ij.startJBMS();
067:                    s = con.createStatement();
068:
069:                } catch (SQLException e) {
070:                    dumpSQLExceptions(e);
071:                } catch (Throwable e) {
072:                    System.out.println("FAIL -- unexpected exception:");
073:                    e.printStackTrace(System.out);
074:                }
075:
076:            }
077:
078:            /**
079:             * Makes a call to the "runTest" method in metadata_test.java,
080:             * which will in turn call back here for implementations of
081:             * the abstract methods.
082:             */
083:            public static void main(String[] args) throws Exception {
084:
085:                new metadata(args).runTest();
086:
087:            }
088:
089:            /**
090:             * This method is responsible for executing a metadata query and returning
091:             * a result set that complies with the JDBC specification.
092:             */
093:            protected ResultSet getMetaDataRS(DatabaseMetaData dmd, int procId,
094:                    String[] sArgs, String[] argArray, int[] iArgs,
095:                    boolean[] bArgs) throws SQLException {
096:
097:                switch (procId) {
098:
099:                case GET_PROCEDURES:
100:                    return dmd.getProcedures(sArgs[0], sArgs[1], sArgs[2]);
101:
102:                case GET_PROCEDURE_COLUMNS:
103:                    return dmd.getProcedureColumns(sArgs[0], sArgs[1],
104:                            sArgs[2], sArgs[3]);
105:
106:                case GET_TABLES:
107:                    return dmd
108:                            .getTables(sArgs[0], sArgs[1], sArgs[2], argArray);
109:
110:                case GET_COLUMNS:
111:                    return dmd.getColumns(sArgs[0], sArgs[1], sArgs[2],
112:                            sArgs[3]);
113:
114:                case GET_COLUMN_PRIVILEGES:
115:                    return dmd.getColumnPrivileges(sArgs[0], sArgs[1],
116:                            sArgs[2], sArgs[3]);
117:
118:                case GET_TABLE_PRIVILEGES:
119:                    return dmd.getTablePrivileges(sArgs[0], sArgs[1], sArgs[2]);
120:
121:                case GET_BEST_ROW_IDENTIFIER:
122:                    return dmd.getBestRowIdentifier(sArgs[0], sArgs[1],
123:                            sArgs[2], iArgs[0], bArgs[0]);
124:
125:                case GET_VERSION_COLUMNS:
126:                    return dmd.getVersionColumns(sArgs[0], sArgs[1], sArgs[2]);
127:
128:                case GET_PRIMARY_KEYS:
129:                    return dmd.getPrimaryKeys(sArgs[0], sArgs[1], sArgs[2]);
130:
131:                case GET_IMPORTED_KEYS:
132:                    return dmd.getImportedKeys(sArgs[0], sArgs[1], sArgs[2]);
133:
134:                case GET_EXPORTED_KEYS:
135:                    return dmd.getExportedKeys(sArgs[0], sArgs[1], sArgs[2]);
136:
137:                case GET_CROSS_REFERENCE:
138:                    return dmd.getCrossReference(sArgs[0], sArgs[1], sArgs[2],
139:                            sArgs[3], sArgs[4], sArgs[5]);
140:
141:                case GET_TYPE_INFO:
142:                    return dmd.getTypeInfo();
143:
144:                case GET_INDEX_INFO:
145:                    return dmd.getIndexInfo(sArgs[0], sArgs[1], sArgs[2],
146:                            bArgs[0], bArgs[1]);
147:
148:                default:
149:                    // shouldn't get here.
150:
151:                    System.out
152:                            .println("*** UNEXPECTED PROCEDURE ID ENCOUNTERED: "
153:                                    + procId + ".");
154:                    return null;
155:                }
156:
157:            }
158:
159:            protected void dumpRS(int procId, ResultSet s) throws SQLException {
160:
161:                ResultSetMetaData rsmd = s.getMetaData();
162:
163:                // Get the number of columns in the result set
164:                int numCols = rsmd.getColumnCount();
165:                String[] headers = new String[numCols];
166:                if (numCols <= 0) {
167:                    System.out.println("(no columns!)");
168:                    return;
169:                }
170:
171:                // Display column headings, and include column types
172:                // as part of those headings.
173:                for (int i = 1; i <= numCols; i++) {
174:                    if (i > 1)
175:                        System.out.print(",");
176:                    headers[i - 1] = rsmd.getColumnLabel(i);
177:                    System.out.print(headers[i - 1]);
178:                    System.out.print("[" + rsmd.getColumnTypeName(i) + "]");
179:
180:                }
181:                System.out.println();
182:
183:                // Display data, fetching until end of the result set
184:                StringBuffer errorColumns;
185:                while (s.next()) {
186:                    // Loop through each column, getting the
187:                    // column data and displaying
188:                    errorColumns = new StringBuffer();
189:                    String value;
190:                    for (int i = 1; i <= numCols; i++) {
191:                        if (i > 1)
192:                            System.out.print(",");
193:                        value = s.getString(i);
194:                        if (headers[i - 1].equals("DATA_TYPE")) {
195:                            if (((org.apache.derbyTesting.functionTests.util.TestUtil
196:                                    .getJDBCMajorVersion(s.getStatement()
197:                                            .getConnection()) >= 3) && (Integer
198:                                    .valueOf(value).intValue() == 16))
199:                                    || (Integer.valueOf(value).intValue() == -7))
200:                                System.out.print("**BOOLEAN_TYPE for VM**");
201:                            else
202:                                System.out.print(value);
203:                        } else
204:                            System.out.print(value);
205:
206:                    }
207:                    System.out.println();
208:                }
209:                s.close();
210:            }
211:
212:            /** dummy method to test getProcedureColumns
213:             */
214:            public static byte[] getpc(String a, BigDecimal b, short c, byte d,
215:                    short e, int f, long g, float h, double i, byte[] j,
216:                    Date k, Time l, Timestamp T) {
217:                return j;
218:            }
219:
220:            /** overload getpc to further test getProcedureColumns
221:             */
222:            public static void getpc(int a, long[] b) {
223:            }
224:
225:            /** overload getpc to further test getProcedureColumns
226:             *  private method shouldn't be returned with alias, ok with procedure
227:             */
228:            private static void getpc(int a, long b) {
229:            }
230:
231:            // instance method 
232:            // with method alias, this should not be returned by getProcedureColumns
233:            // but DB2 returns this with a java procedure
234:            public void getpc(String a, String b) {
235:            }
236:
237:            // this method should notbe seen by getProcedureColumns as
238:            // it has no parameters and no return value.
239:            public static void getpc4a() {
240:            }
241:
242:            // check a method with no paramters and a return value works
243:            // for getProcedureColumns.
244:            public static int getpc4b() {
245:                return 4;
246:            }
247:
248:            // check for nested connection working ok
249:            public static void isro() throws SQLException {
250:                DriverManager.getConnection("jdbc:default:connection")
251:                        .getMetaData().isReadOnly();
252:            }
253:
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.