1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 /*
23  * Class.java
24  *
25  * Created on June 23, 2003, 3:19 PM
26  */
27 
28 /**
29  *
30  * @author  oj93728
31  */
32 package complex.connectivity.hsqldb;
33 import complex.connectivity.HsqlDriverTest;
34 import java.sql.*;
35 import java.lang.reflect.Method;
36 
37 
38 public class DatabaseMetaData {
39 
40     private java.sql.DatabaseMetaData m_xMD;
41     private HsqlDriverTest m_TestCase;
42 
43     /** Creates a new instance of DatabaseMetaData */
DatabaseMetaData(HsqlDriverTest _testCase,java.sql.DatabaseMetaData _xmd)44     public DatabaseMetaData(HsqlDriverTest _testCase,java.sql.DatabaseMetaData _xmd) {
45         m_TestCase = _testCase;
46         m_xMD = _xmd;
47     }
48 
assure(String _sText,boolean btest)49     protected void assure(String _sText,boolean btest){
50         m_TestCase.assurePublic(_sText,btest);
51     }
52 
testMethod(String sName,Class[] params,Object[] objParams,int nCount)53     protected void testMethod(String sName,Class[] params,Object[] objParams,int nCount){
54         try {
55             System.out.println("test method " + sName);
56 
57             Method aGet = ((Object)m_xMD).getClass().getDeclaredMethod(sName, params);
58             if ( aGet != null ){
59                 ResultSet rs = (ResultSet)aGet.invoke(m_xMD, objParams);
60                 ResultSetMetaData rsMD = rs.getMetaData();
61 
62                 assure( sName + " returns wrong column count" , rsMD.getColumnCount() == nCount);
63             }
64             else
65                 assure( sName + " returns wrong column count" , false);
66         } catch( java.lang.NoSuchMethodException ex ) {
67             assure("Method " + sName + " could not be found!",false);
68         } catch( java.lang.IllegalAccessException ex ) {
69             assure("IllegalAccessException!",false);
70         } catch( SQLException ex ) {
71             assure("SQLException occured: " + ex.getMessage() ,false);
72         } catch( java.lang.reflect.InvocationTargetException ex ) {
73             assure("IllegalAccessException!",false);
74         } finally {
75 
76         }
77     }
78 
test()79     public void test(){
80 
81    //     try {
82 
83             try{
84 		ResultSet rs = m_xMD.getTables(null,null,"TESTCASE",null);
85 		while ( rs.next() )
86 		{
87 			String catalog = rs.getString( 1 );
88 			if ( rs.wasNull() )
89 				catalog = null;
90 
91 			String schema = rs.getString( 2 );
92 			if ( rs.wasNull() )
93 				schema = null;
94 
95 			String table = rs.getString( 3 );
96 			String type = rs.getString( 4 );
97 			System.out.println("Catalog: " + catalog + " Schema: " + schema + " Table: " + table + " Type: " + type);
98 			System.out.println("------------------ Columns ------------------");
99 			ResultSet rsColumns = m_xMD.getColumns(catalog,schema,table,"%");
100 			while ( rsColumns.next() )
101 			{
102 				System.out.println("Column: " + rsColumns.getString( 4 ) + " Type: " + rsColumns.getInt( 5 ) + " TypeName: " + rsColumns.getString( 6 ) );
103 			}
104 
105 		}
106             } catch(Exception e){
107 
108             }
109             //testMethod("getTypeInfo", zclass,empty,17);
110 /*
111             Class[] zclass = new Class[]{};
112             Object[] empty = new Object[]{};
113             testMethod("getCatalogs", zclass,empty,1);
114 
115             testMethod("getSchemas", zclass,empty,2);
116             testMethod("getTableTypes", zclass,empty,1);
117             Class[] a4 = new Class[4];
118             Object[] o4 = new Object[4];
119             a4[0] = Class.forName("java.lang.Object");
120             a4[1] = Class.forName("java.lang.String");
121             a4[2] = Class.forName("java.lang.String");
122             a4[3] = Class.forName("java.lang.String");
123 
124             o4[0] = null;
125             o4[1] = null;
126             o4[2] = null;
127             o4[3] = "%";
128             testMethod("getColumnPrivileges", a4,o4,7);
129             testMethod("getColumns", a4,o4,18);
130             testMethod("getProcedureColumns", a4,o4,13);
131             testMethod("getColumns", a4,o4,18);
132 
133             Class[] a3 = new Class[3];
134             Object[] o3 = new Object[3];
135             a3[0] = Class.forName("java.lang.Object");
136             a3[1] = Class.forName("java.lang.String");
137             a3[2] = Class.forName("java.lang.String");
138 
139             o3[0] = null;
140             o3[1] = null;
141             o3[2] = "%";
142 
143             testMethod("getExportedKeys", a3,o3,14);
144             testMethod("getImportedKeys", a3,o3,14);
145             testMethod("getPrimaryKeys", a3,o3,14);
146             testMethod("getProcedures", a3,o3,5);
147             testMethod("getTablePrivileges", a3,o3,6);
148             testMethod("getVersionColumns", a3,o3,7);
149             // testMethod("getCrossReference", a3,o3,14);
150 
151         } catch( java.lang.ClassNotFoundException ex) {
152             assure("ClassNotFoundException: " + ex.getMessage() ,false);
153         }
154  */
155     }
156 /*
157     public com.sun.star.sdbc.XResultSet getCrossReference(Object obj, String str, String str2, Object obj3, String str4, String str5) {
158     }
159     public com.sun.star.sdbc.XResultSet getIndexInfo(Object obj, String str, String str2, boolean param, boolean param4) {
160     }
161 
162     public com.sun.star.sdbc.XResultSet getTables(Object obj, String str, String str2, String[] str3) {
163     }
164 
165     public com.sun.star.sdbc.XResultSet getUDTs(Object obj, String str, String str2, int[] values) {
166     }
167 
168     public com.sun.star.sdbc.XResultSet getBestRowIdentifier(Object obj, String str, String str2, int param, boolean param4) throws com.sun.star.sdbc.SQLException {
169     }
170  */
171 }
172