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: * A row containing a cross-join, all columns from each of two cursors.
057: *
058: * @author Stan Bailes
059: */
060: public class JoinMapRow extends Row {
061: Row a;
062: Row b;
063:
064: // n = map[i]; row[i] = if (n<0) a[0-n], if (n>0) rb[i], if (n==0) null
065: int[] map;
066:
067: public JoinMapRow(int[] map) {
068: this .map = map;
069: }
070:
071: public final void setA(Row a) {
072: this .a = a;
073: }
074:
075: public final void setB(Row b) {
076: this .b = b;
077: }
078:
079: public final Row getA() {
080: return a;
081: }
082:
083: public final Row getB() {
084: return b;
085: }
086:
087: public final int size() {
088: return map.length;
089: }
090:
091: public final Value item(int i) throws SQLException {
092: int n = map[i - 1];
093: if (n < 0)
094: return a == null ? ValueNull.valueNull : a.item(0 - n);
095: if (n > 0)
096: return b == null ? ValueNull.valueNull : b.item(n);
097: return ValueNull.valueNull;
098: }
099:
100: public final void set(int i, Value val) throws SQLException {
101: int n = map[i - 1];
102: if (n < 0 && a != null)
103: a.set(0 - n, val);
104: if (n > 0 && b != null)
105: b.set(n, val);
106: }
107:
108: //#ifdef DEBUG
109: public String toString1() {
110: StringBuffer sb = new StringBuffer("{");
111: for (int i = 1; i <= size(); i++) {
112: if (i > 1)
113: sb.append(",");
114: int n = map[i - 1];
115: if (n < 0) {
116: sb.append("A");
117: n = 0 - n;
118: sb.append(n);
119: } else if (n > 0) {
120: sb.append("B");
121: sb.append(n);
122: } else if (n == 0) {
123: sb.append("0:null");
124: continue;
125: }
126: sb.append(":");
127: try {
128: sb.append(item(i).toString());
129: } catch (Throwable t) {
130: sb.append(t.toString());
131: }
132: }
133: sb.append("}");
134: return sb.toString();
135: }
136: //#endif
137: }
|