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:
052: import com.quadcap.util.Debug;
053:
054: /**
055: * A row containing a natural join, all columns from each of two cursors,
056: * with only one instance of the join columns.
057: *
058: * @author Stan Bailes
059: */
060: public class JoinNaturalRow extends Row {
061: Row a;
062: Row b;
063: int aSize;
064: int[] aMap;
065: int[] bMap;
066:
067: /**
068: * @param a the left row
069: * @param b the right row
070: * @param aMap map columns from their join row position to their position
071: * in the left row. Zero based.
072: * @param bMap map columns from their join row offset to their position
073: * in the right row. Zero based.
074: */
075: public JoinNaturalRow(Row a, Row b, int[] aMap, int[] bMap) {
076: this .a = a;
077: this .aSize = a.size();
078: this .b = b;
079: this .aMap = aMap;
080: this .bMap = bMap;
081: }
082:
083: public void setA(Row a) {
084: this .a = a;
085: }
086:
087: public void setB(Row b) {
088: this .b = b;
089: }
090:
091: public int size() {
092: return aSize + bMap.length;
093: }
094:
095: public Value item(int i) throws SQLException {
096: if (i < 1 || i > size()) {
097: throw new SQLException("bad column: " + i, "42000");
098: }
099: if (i <= aSize) {
100: return a.item(aMap[i - 1]);
101: } else {
102: return b.item(bMap[i - aSize - 1]);
103: }
104: }
105:
106: public void set(int i, Value val) throws SQLException {
107: if (i < 1 || i > size()) {
108: throw new SQLException("bad column: " + i, "42000");
109: }
110: if (i <= aSize)
111: a.set(aMap[i - 1], val);
112: else
113: b.set(bMap[i - aSize - 1], val);
114: }
115: }
|