001: /*
002: * $Id: TestNestedLoopJoinedRowIterator_IndexedRightOuterJoinCase.java,v 1.3 2005/04/22 21:34:17 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2004-2005 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.engine.rowiterators;
042:
043: import java.util.ArrayList;
044: import java.util.HashMap;
045: import java.util.List;
046: import java.util.Map;
047:
048: import junit.framework.Test;
049: import junit.framework.TestSuite;
050:
051: import org.axiondb.Column;
052: import org.axiondb.ColumnIdentifier;
053: import org.axiondb.Index;
054: import org.axiondb.RowDecorator;
055: import org.axiondb.RowIterator;
056: import org.axiondb.Table;
057: import org.axiondb.TableIdentifier;
058: import org.axiondb.engine.indexes.ObjectArrayIndex;
059: import org.axiondb.engine.rows.SimpleRow;
060: import org.axiondb.engine.tables.MemoryTable;
061: import org.axiondb.functions.ConcreteFunction;
062: import org.axiondb.functions.EqualFunction;
063: import org.axiondb.types.StringType;
064:
065: /**
066: * @version $Revision: 1.3 $ $Date: 2005/04/22 21:34:17 $
067: * @author Rodney Waldhoff
068: */
069: public class TestNestedLoopJoinedRowIterator_IndexedRightOuterJoinCase
070: extends AbstractRowIteratorTest {
071:
072: //------------------------------------------------------------ Conventional
073:
074: public TestNestedLoopJoinedRowIterator_IndexedRightOuterJoinCase(
075: String testName) {
076: super (testName);
077: }
078:
079: public static Test suite() {
080: TestSuite suite = new TestSuite(
081: TestNestedLoopJoinedRowIterator_IndexedRightOuterJoinCase.class);
082: return suite;
083: }
084:
085: private List _left;
086: private Table _table;
087: private ConcreteFunction _where;
088: private Index _index;
089: private Column _column;
090:
091: private RowDecorator _decorator;
092:
093: protected void setUp() throws Exception {
094: _left = new ArrayList();
095: {
096: SimpleRow row = new SimpleRow(2);
097: row.set(0, "A");
098: row.set(1, "A");
099: _left.add(row);
100: }
101: {
102: SimpleRow row = new SimpleRow(2);
103: row.set(0, "A");
104: row.set(1, "B");
105: _left.add(row);
106: }
107: {
108: SimpleRow row = new SimpleRow(2);
109: row.set(0, "B");
110: row.set(1, "A");
111: _left.add(row);
112: }
113: _column = new Column("c", StringType.instance());
114: _table = new MemoryTable("x");
115: _table.addColumn(_column);
116: _table.addColumn(new Column("d", StringType.instance()));
117: _index = new ObjectArrayIndex("y", _column, false);
118: _table.addIndex(_index);
119: {
120: SimpleRow row = new SimpleRow(2);
121: row.set(0, "A");
122: row.set(1, "A");
123: _table.addRow(row);
124: }
125: {
126: SimpleRow row = new SimpleRow(2);
127: row.set(0, "A");
128: row.set(1, "B");
129: _table.addRow(row);
130: }
131: {
132: SimpleRow row = new SimpleRow(2);
133: row.set(0, "A");
134: row.set(1, "C");
135: _table.addRow(row);
136: }
137: _where = new EqualFunction();
138: _where.addArgument(new ColumnIdentifier("b"));
139: _where.addArgument(new ColumnIdentifier(
140: new TableIdentifier("x"), "c"));
141:
142: Map map = new HashMap();
143: map.put(new ColumnIdentifier(new TableIdentifier("x"), "c"),
144: new Integer(0));
145: map.put(new ColumnIdentifier(new TableIdentifier("x"), "d"),
146: new Integer(1));
147: map.put(new ColumnIdentifier("a"), new Integer(2));
148: map.put(new ColumnIdentifier("b"), new Integer(3));
149:
150: _decorator = new RowDecorator(map);
151: }
152:
153: protected RowIterator makeRowIterator() {
154: try {
155: RowIterator left = new ListRowIterator(_left);
156: RowIterator right = _table
157: .getIndexedRows(new ColumnIdentifier(
158: new TableIdentifier("x"), "c"), true);
159: NestedLoopJoinedRowIterator rowIter = new NestedLoopJoinedRowIterator(
160: left, right, 2, true, true);
161: rowIter.setJoinCondition(_where, _decorator);
162: return rowIter;
163: } catch (Exception e) {
164: e.printStackTrace();
165: throw new RuntimeException(e.toString());
166: }
167: }
168:
169: protected int getSize() {
170: return 7;
171: }
172:
173: protected List makeRowList() {
174: List list = new ArrayList();
175: {
176: SimpleRow row = new SimpleRow(4);
177: row.set(0, "A");
178: row.set(1, "B");
179: row.set(2, "A");
180: row.set(3, "A");
181: list.add(row);
182: }
183: {
184: SimpleRow row = new SimpleRow(4);
185: row.set(0, "A");
186: row.set(1, "C");
187: row.set(2, "A");
188: row.set(3, "A");
189: list.add(row);
190: }
191: {
192: SimpleRow row = new SimpleRow(4);
193: row.set(0, "A");
194: row.set(1, "A");
195: row.set(2, "A");
196: row.set(3, "A");
197: list.add(row);
198: }
199: {
200: SimpleRow row = new SimpleRow(4);
201: row.set(0, null);
202: row.set(1, null);
203: row.set(2, "A");
204: row.set(3, "B");
205: list.add(row);
206: }
207: {
208: SimpleRow row = new SimpleRow(4);
209: row.set(0, "A");
210: row.set(1, "B");
211: row.set(2, "B");
212: row.set(3, "A");
213: list.add(row);
214: }
215: {
216: SimpleRow row = new SimpleRow(4);
217: row.set(0, "A");
218: row.set(1, "C");
219: row.set(2, "B");
220: row.set(3, "A");
221: list.add(row);
222: }
223: {
224: SimpleRow row = new SimpleRow(4);
225: row.set(0, "A");
226: row.set(1, "A");
227: row.set(2, "B");
228: row.set(3, "A");
229: list.add(row);
230: }
231: return list;
232: }
233:
234: //------------------------------------------------------------------- Tests
235:
236: }
|