001: package com.quadcap.sql;
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.Externalizable;
042: import java.io.IOException;
043: import java.io.ObjectInput;
044: import java.io.ObjectOutput;
045:
046: import java.util.Enumeration;
047: import java.util.Hashtable;
048: import java.util.Vector;
049:
050: import java.sql.SQLException;
051:
052: import com.quadcap.util.Debug;
053:
054: /**
055: * This cursor performs the name mapping associated with the (optional)
056: * column list of the <code>CREATE VIEW</code> statement.
057: *
058: * @author Stan Bailes
059: */
060: public class ViewCursor extends CursorImpl {
061: Cursor cursor;
062: View view;
063:
064: public ViewCursor(Session session, View view, Cursor cursor,
065: Vector names) throws SQLException {
066: super (session, view.getName());
067: this .view = view;
068: this .cursor = cursor;
069: if (names.size() > cursor.getColumnCount()) {
070: throw new SQLException(
071: "Too many names in view column list", "42000");
072: }
073: if (names.size() < cursor.getColumnCount()) {
074: //#ifdef TRACE
075: if (Trace.bit(2)) {
076: Debug.println("cursor = " + cursor);
077: for (int i = 0; i < names.size(); i++) {
078: Debug.println("name[" + i + "] = "
079: + names.elementAt(i).toString());
080: }
081: }
082: //#endif
083: throw new SQLException(
084: "Not enough names in view column list", "42000");
085: }
086: for (int i = 0; i < names.size(); i++) {
087: String name = (String) names.elementAt(i);
088: addColumn(new Column(name, cursor.getColumn(i + 1)
089: .getType()));
090: }
091: resolveColumns();
092: }
093:
094: public long size() throws SQLException {
095: return -1;
096: }
097:
098: public Row getRow() throws SQLException {
099: return cursor.getRow();
100: }
101:
102: public void updateRow(Row row) throws SQLException {
103: view.checkRow(session, cursor, row);
104: cursor.updateRow(row);
105: }
106:
107: public void insertRow(Row row) throws SQLException {
108: view.checkRow(session, cursor, row);
109: cursor.insertRow(row);
110: }
111:
112: public void deleteRow() throws SQLException {
113: cursor.deleteRow();
114: }
115:
116: public void beforeFirst() throws SQLException {
117: cursor.beforeFirst();
118: }
119:
120: public void afterLast() throws SQLException {
121: cursor.afterLast();
122: }
123:
124: public boolean absolute(int row) throws SQLException {
125: return cursor.absolute(row);
126: }
127:
128: public boolean next() throws SQLException {
129: return cursor.next();
130: }
131:
132: public boolean isWritable(int column) throws SQLException {
133: return cursor.isWritable(column);
134: }
135:
136: public int getColumnCount() throws SQLException {
137: return cursor.getColumnCount();
138: }
139:
140: public void close() throws SQLException {
141: cursor.close();
142: }
143: }
|