001: /*
002: * $Id: TestNestedLoopJoinedRowIterator_RightOuterJoinCase.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.RowDecorator;
054: import org.axiondb.RowIterator;
055: import org.axiondb.Table;
056: import org.axiondb.TableIdentifier;
057: import org.axiondb.engine.rows.SimpleRow;
058: import org.axiondb.engine.tables.MemoryTable;
059: import org.axiondb.functions.ConcreteFunction;
060: import org.axiondb.functions.EqualFunction;
061: import org.axiondb.types.StringType;
062:
063: /**
064: * @version $Revision: 1.3 $ $Date: 2005/04/22 21:34:17 $
065: * @author Rodney Waldhoff
066: * @author Ahimanikya Satapathy
067: */
068: public class TestNestedLoopJoinedRowIterator_RightOuterJoinCase extends
069: AbstractRowIteratorTest {
070:
071: //------------------------------------------------------------ Conventional
072:
073: public TestNestedLoopJoinedRowIterator_RightOuterJoinCase(
074: String testName) {
075: super (testName);
076: }
077:
078: public static Test suite() {
079: TestSuite suite = new TestSuite(
080: TestNestedLoopJoinedRowIterator_RightOuterJoinCase.class);
081: return suite;
082: }
083:
084: private List _left;
085: private Table _table;
086: private ConcreteFunction _where;
087: private Column _column;
088:
089: private RowDecorator _decorator;
090:
091: protected void setUp() throws Exception {
092: _left = new ArrayList();
093: {
094: SimpleRow row = new SimpleRow(2);
095: row.set(0, "A");
096: row.set(1, "A");
097: _left.add(row);
098: }
099: {
100: SimpleRow row = new SimpleRow(2);
101: row.set(0, "A");
102: row.set(1, "B");
103: _left.add(row);
104: }
105: {
106: SimpleRow row = new SimpleRow(2);
107: row.set(0, "B");
108: row.set(1, "A");
109: _left.add(row);
110: }
111: _column = new Column("c", StringType.instance());
112: _table = new MemoryTable("x");
113: _table.addColumn(_column);
114: _table.addColumn(new Column("d", StringType.instance()));
115: {
116: SimpleRow row = new SimpleRow(2);
117: row.set(0, "A");
118: row.set(1, "A");
119: _table.addRow(row);
120: }
121: {
122: SimpleRow row = new SimpleRow(2);
123: row.set(0, "A");
124: row.set(1, "B");
125: _table.addRow(row);
126: }
127: {
128: SimpleRow row = new SimpleRow(2);
129: row.set(0, "A");
130: row.set(1, "C");
131: _table.addRow(row);
132: }
133: _where = new EqualFunction();
134: _where.addArgument(new ColumnIdentifier("b"));
135: _where.addArgument(new ColumnIdentifier(
136: new TableIdentifier("x"), "c"));
137:
138: Map map = new HashMap();
139: map.put(new ColumnIdentifier(new TableIdentifier("x"), "c"),
140: new Integer(0));
141: map.put(new ColumnIdentifier(new TableIdentifier("x"), "d"),
142: new Integer(1));
143: map.put(new ColumnIdentifier("a"), new Integer(2));
144: map.put(new ColumnIdentifier("b"), new Integer(3));
145:
146: _decorator = new RowDecorator(map);
147: }
148:
149: protected RowIterator makeRowIterator() {
150: try {
151: RowIterator left = new ListRowIterator(_left);
152: RowIterator right = _table.getRowIterator(true);
153: NestedLoopJoinedRowIterator rowIter = new NestedLoopJoinedRowIterator(
154: left, right, 2, true, true);
155: rowIter.setJoinCondition(_where, _decorator);
156: return rowIter;
157: } catch (Exception e) {
158: e.printStackTrace();
159: throw new RuntimeException(e.toString());
160: }
161: }
162:
163: protected int getSize() {
164: return 7;
165: }
166:
167: protected List makeRowList() {
168: List list = new ArrayList();
169: {
170: SimpleRow row = new SimpleRow(4);
171: row.set(0, "A");
172: row.set(1, "A");
173: row.set(2, "A");
174: row.set(3, "A");
175: list.add(row);
176: }
177: {
178: SimpleRow row = new SimpleRow(4);
179: row.set(0, "A");
180: row.set(1, "B");
181: row.set(2, "A");
182: row.set(3, "A");
183: list.add(row);
184: }
185: {
186: SimpleRow row = new SimpleRow(4);
187: row.set(0, "A");
188: row.set(1, "C");
189: row.set(2, "A");
190: row.set(3, "A");
191: list.add(row);
192: }
193: {
194: SimpleRow row = new SimpleRow(4);
195: row.set(0, null);
196: row.set(1, null);
197: row.set(2, "A");
198: row.set(3, "B");
199: list.add(row);
200: }
201: {
202: SimpleRow row = new SimpleRow(4);
203: row.set(0, "A");
204: row.set(1, "A");
205: row.set(2, "B");
206: row.set(3, "A");
207: list.add(row);
208: }
209: {
210: SimpleRow row = new SimpleRow(4);
211: row.set(0, "A");
212: row.set(1, "B");
213: row.set(2, "B");
214: row.set(3, "A");
215: list.add(row);
216: }
217: {
218: SimpleRow row = new SimpleRow(4);
219: row.set(0, "A");
220: row.set(1, "C");
221: row.set(2, "B");
222: row.set(3, "A");
223: list.add(row);
224: }
225:
226: return list;
227: }
228:
229: //------------------------------------------------------------------- Tests
230:
231: }
|