1 package com.quadcap.sql.meta; 2 3 40 41 import java.io.IOException ; 42 43 import java.util.HashMap ; 44 import java.util.Iterator ; 45 import java.util.Vector ; 46 47 import java.sql.DatabaseMetaData ; 48 import java.sql.SQLException ; 49 50 import com.quadcap.sql.Column; 51 import com.quadcap.sql.Database; 52 import com.quadcap.sql.Row; 53 import com.quadcap.sql.Session; 54 55 import com.quadcap.sql.index.Btree; 56 import com.quadcap.sql.index.BCursor; 57 58 import com.quadcap.sql.types.*; 59 60 import com.quadcap.util.Debug; 61 62 67 public class MetaSchemas extends MetaCursor { 68 static Column[] cols = { 69 new Column("TABLE_SCHEM", typeString) }; 71 72 static int[] sortColumns = { 1 }; 73 74 77 public MetaSchemas(Session session) 78 throws SQLException 79 { 80 super(session, null); 81 try { 82 addColumns(cols); 83 HashMap schemaNames = new HashMap (); 84 Database db = session.getDatabase(); 85 session.getTableWriteLock("#Schema"); 86 synchronized (db.getFile().getLock()) { 87 Iterator iter = db.getRelationNameIterator(); 88 while (iter.hasNext()) { 89 String name = iter.next().toString(); 90 int idx = name.indexOf('.'); 91 if (idx > 0) { 92 name = name.substring(0, idx); 93 } else { 94 name = session.getConnection().getAuth(); 95 } 96 if (!schemaNames.containsKey(name)) { 97 Row row = new Row(1); 98 row.set(1, new ValueString(name)); 99 addRow(row); 100 schemaNames.put(name, ""); 101 } 102 } 103 } 104 sort(); 105 } catch (ValueException e) { 106 Debug.print(e); 107 SQLException te = new SQLException (e.toString(), "Q000P"); 108 te.setNextException(e); 109 throw te; 110 } catch (IOException e) { 111 Debug.print(e); 112 throw new SQLException (e.toString(), "Q000Q"); 113 } 114 } 115 116 119 public int[] getSortColumns() { 120 return sortColumns; 121 } 122 } 123 | Popular Tags |