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