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