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 java.sql.*; 34 import java.lang.reflect.Method; 35 36 import static org.junit.Assert.*; 37 38 public class DatabaseMetaData { 39 40 private java.sql.DatabaseMetaData m_xMD; 41 42 /** Creates a new instance of DatabaseMetaData */ DatabaseMetaData(java.sql.DatabaseMetaData _xmd)43 public DatabaseMetaData(java.sql.DatabaseMetaData _xmd) { 44 m_xMD = _xmd; 45 } 46 testMethod(String sName,Class[] params,Object[] objParams,int nCount)47 protected void testMethod(String sName,Class[] params,Object[] objParams,int nCount){ 48 try { 49 System.out.println("test method " + sName); 50 51 Method aGet = ((Object)m_xMD).getClass().getDeclaredMethod(sName, params); 52 if ( aGet != null ){ 53 ResultSet rs = (ResultSet)aGet.invoke(m_xMD, objParams); 54 ResultSetMetaData rsMD = rs.getMetaData(); 55 56 assertTrue( sName + " returns wrong column count" , rsMD.getColumnCount() == nCount); 57 } 58 else 59 fail( sName + " returns wrong column count"); 60 } catch( java.lang.NoSuchMethodException ex ) { 61 fail("Method " + sName + " could not be found!"); 62 } catch( java.lang.IllegalAccessException ex ) { 63 fail("IllegalAccessException!"); 64 } catch( SQLException ex ) { 65 fail("SQLException occurred: " + ex.getMessage()); 66 } catch( java.lang.reflect.InvocationTargetException ex ) { 67 fail("IllegalAccessException!"); 68 } finally { 69 70 } 71 } 72 test()73 public void test(){ 74 75 // try { 76 77 try{ 78 ResultSet rs = m_xMD.getTables(null,null,"TESTCASE",null); 79 while ( rs.next() ) 80 { 81 String catalog = rs.getString( 1 ); 82 if ( rs.wasNull() ) 83 catalog = null; 84 85 String schema = rs.getString( 2 ); 86 if ( rs.wasNull() ) 87 schema = null; 88 89 String table = rs.getString( 3 ); 90 String type = rs.getString( 4 ); 91 System.out.println("Catalog: " + catalog + " Schema: " + schema + " Table: " + table + " Type: " + type); 92 System.out.println("------------------ Columns ------------------"); 93 ResultSet rsColumns = m_xMD.getColumns(catalog,schema,table,"%"); 94 while ( rsColumns.next() ) 95 { 96 System.out.println("Column: " + rsColumns.getString( 4 ) + " Type: " + rsColumns.getInt( 5 ) + " TypeName: " + rsColumns.getString( 6 ) ); 97 } 98 99 } 100 } catch(Exception e){ 101 102 } 103 //testMethod("getTypeInfo", zclass,empty,17); 104 /* 105 Class[] zclass = new Class[]{}; 106 Object[] empty = new Object[]{}; 107 testMethod("getCatalogs", zclass,empty,1); 108 109 testMethod("getSchemas", zclass,empty,2); 110 testMethod("getTableTypes", zclass,empty,1); 111 Class[] a4 = new Class[4]; 112 Object[] o4 = new Object[4]; 113 a4[0] = Class.forName("java.lang.Object"); 114 a4[1] = Class.forName("java.lang.String"); 115 a4[2] = Class.forName("java.lang.String"); 116 a4[3] = Class.forName("java.lang.String"); 117 118 o4[0] = null; 119 o4[1] = null; 120 o4[2] = null; 121 o4[3] = "%"; 122 testMethod("getColumnPrivileges", a4,o4,7); 123 testMethod("getColumns", a4,o4,18); 124 testMethod("getProcedureColumns", a4,o4,13); 125 testMethod("getColumns", a4,o4,18); 126 127 Class[] a3 = new Class[3]; 128 Object[] o3 = new Object[3]; 129 a3[0] = Class.forName("java.lang.Object"); 130 a3[1] = Class.forName("java.lang.String"); 131 a3[2] = Class.forName("java.lang.String"); 132 133 o3[0] = null; 134 o3[1] = null; 135 o3[2] = "%"; 136 137 testMethod("getExportedKeys", a3,o3,14); 138 testMethod("getImportedKeys", a3,o3,14); 139 testMethod("getPrimaryKeys", a3,o3,14); 140 testMethod("getProcedures", a3,o3,5); 141 testMethod("getTablePrivileges", a3,o3,6); 142 testMethod("getVersionColumns", a3,o3,7); 143 // testMethod("getCrossReference", a3,o3,14); 144 145 } catch( java.lang.ClassNotFoundException ex) { 146 fail("ClassNotFoundException: " + ex.getMessage()); 147 } 148 */ 149 } 150 /* 151 public com.sun.star.sdbc.XResultSet getCrossReference(Object obj, String str, String str2, Object obj3, String str4, String str5) { 152 } 153 public com.sun.star.sdbc.XResultSet getIndexInfo(Object obj, String str, String str2, boolean param, boolean param4) { 154 } 155 156 public com.sun.star.sdbc.XResultSet getTables(Object obj, String str, String str2, String[] str3) { 157 } 158 159 public com.sun.star.sdbc.XResultSet getUDTs(Object obj, String str, String str2, int[] values) { 160 } 161 162 public com.sun.star.sdbc.XResultSet getBestRowIdentifier(Object obj, String str, String str2, int param, boolean param4) throws com.sun.star.sdbc.SQLException { 163 } 164 */ 165 } 166