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.Vector;
047:
048: import java.sql.SQLException;
049:
050: import com.quadcap.sql.types.Value;
051: import com.quadcap.sql.types.ValueNull;
052:
053: import com.quadcap.util.Debug;
054:
055: /**
056: * Part of the 'ItemCursor' implementation, this implements a row that
057: * is a mapped Essentially, a vector with one-based indices.
058: *
059: * @author Stan Bailes
060: */
061: public class ItemsRow extends Row {
062: Session session;
063: Vector items;
064: Cursor cursor;
065: Row myRow;
066: Row baseRow;
067: int[] map;
068:
069: public ItemsRow(Session session, Vector items, Cursor cursor,
070: Row r, int[] map) throws SQLException {
071: this .session = session;
072: this .items = items;
073: this .cursor = cursor;
074: this .map = map;
075: this .myRow = new Row(items.size());
076: if (r == null && cursor != null) {
077: r = new Row(cursor.getColumnCount());
078: for (int i = 1; i <= r.size(); i++)
079: r.set(i, ValueNull.valueNull);
080: }
081: this .nextRow(r);
082: }
083:
084: Row getBaseRow() {
085: return baseRow;
086: }
087:
088: public void nextRow(Row r) throws SQLException {
089: this .baseRow = r;
090: for (int i = 1; i <= size(); i++) {
091: myRow.set(i, getItem(r, i));
092: }
093: }
094:
095: public int size() {
096: return map.length;
097: }
098:
099: public Value item(int i) throws SQLException {
100: return myRow.item(i);
101: }
102:
103: public Value getItem(Row r, int i) throws SQLException {
104: int pos = map[i - 1];
105: if (pos < 0) {
106: SelectItem item = (SelectItem) items.elementAt(i - 1);
107: Expression e = item.getExpression();
108: return e.getValue(session, cursor);
109: } else if (r != null) {
110: return r.item(pos);
111: } else {
112: return new ValueNull();
113: }
114: }
115:
116: public void set(int i, Value val) throws SQLException {
117: int pos = map[i - 1];
118: if (pos < 0) {
119: throw new SQLException("Not updatable: "
120: + items.elementAt(i - 1), "42000");
121: }
122: myRow.set(i, val);
123: baseRow.set(map[i - 1], val);
124: }
125:
126: public boolean isUpdateable(int i) {
127: return map[i - 1] >= 0;
128: }
129: }
|