001: package com.quadcap.sql.meta;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042:
043: import java.util.HashMap;
044: import java.util.Iterator;
045: import java.util.Vector;
046:
047: import java.sql.DatabaseMetaData;
048: import java.sql.SQLException;
049:
050: import com.quadcap.sql.Column;
051: import com.quadcap.sql.Database;
052: import com.quadcap.sql.Row;
053: import com.quadcap.sql.Session;
054:
055: import com.quadcap.sql.index.Btree;
056: import com.quadcap.sql.index.BCursor;
057:
058: import com.quadcap.sql.types.*;
059:
060: import com.quadcap.util.Debug;
061:
062: /**
063: * A Cursor supporting the <code>getSchemas</code> function.
064: *
065: * @author Stan Bailes
066: */
067: public class MetaSchemas extends MetaCursor {
068: static Column[] cols = { new Column("TABLE_SCHEM", typeString) // 1
069: };
070:
071: static int[] sortColumns = { 1 };
072:
073: /**
074: * Cursor constructor.
075: */
076: public MetaSchemas(Session session) throws SQLException {
077: super (session, null);
078: try {
079: addColumns(cols);
080: HashMap schemaNames = new HashMap();
081: Database db = session.getDatabase();
082: session.getTableWriteLock("#Schema");
083: synchronized (db.getFile().getLock()) {
084: Iterator iter = db.getRelationNameIterator();
085: while (iter.hasNext()) {
086: String name = iter.next().toString();
087: int idx = name.indexOf('.');
088: if (idx > 0) {
089: name = name.substring(0, idx);
090: } else {
091: name = session.getConnection().getAuth();
092: }
093: if (!schemaNames.containsKey(name)) {
094: Row row = new Row(1);
095: row.set(1, new ValueString(name));
096: addRow(row);
097: schemaNames.put(name, "");
098: }
099: }
100: }
101: sort();
102: } catch (ValueException e) {
103: Debug.print(e);
104: SQLException te = new SQLException(e.toString(), "Q000P");
105: te.setNextException(e);
106: throw te;
107: } catch (IOException e) {
108: Debug.print(e);
109: throw new SQLException(e.toString(), "Q000Q");
110: }
111: }
112:
113: /**
114: * Sort by type
115: */
116: public int[] getSortColumns() {
117: return sortColumns;
118: }
119: }
|