001: /*
002: * $Id: TestIndexNestedLoopJoinedRowIterator_OuterJoinWithAdditionalCriteriaCase.java,v 1.3 2005/04/22 21:34:17 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 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.Literal;
055: import org.axiondb.RowDecorator;
056: import org.axiondb.RowIterator;
057: import org.axiondb.Table;
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 TestIndexNestedLoopJoinedRowIterator_OuterJoinWithAdditionalCriteriaCase
070: extends AbstractRowIteratorTest {
071:
072: //------------------------------------------------------------ Conventional
073:
074: public TestIndexNestedLoopJoinedRowIterator_OuterJoinWithAdditionalCriteriaCase(
075: String testName) {
076: super (testName);
077: }
078:
079: public static Test suite() {
080: TestSuite suite = new TestSuite(
081: TestIndexNestedLoopJoinedRowIterator_OuterJoinWithAdditionalCriteriaCase.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: private RowDecorator _decorator;
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(null, "a", null,
138: StringType.instance()));
139: _where.addArgument(new Literal("A", StringType.instance()));
140: Map map = new HashMap();
141: map.put(new ColumnIdentifier(null, "a", null, StringType
142: .instance()), new Integer(0));
143: _decorator = new RowDecorator(map);
144: }
145:
146: protected RowIterator makeRowIterator() {
147: try {
148: RowIterator left = new ListRowIterator(_left);
149: ChangingIndexedRowIterator right = new ChangingIndexedRowIterator(
150: _index, _table, new EqualFunction());
151: IndexNestedLoopJoinedRowIterator iter = new IndexNestedLoopJoinedRowIterator(
152: left, 1, right, 2, true, false);
153: iter.setJoinCondition(_where, _decorator);
154: return iter;
155: } catch (Exception e) {
156: e.printStackTrace();
157: throw new RuntimeException(e.toString());
158: }
159: }
160:
161: protected int getSize() {
162: return 5;
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, "B");
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, "C");
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, "A");
189: list.add(row);
190: }
191: {
192: SimpleRow row = new SimpleRow(4);
193: row.set(0, "A");
194: row.set(1, "B");
195: row.set(2, null);
196: row.set(3, null);
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, null);
204: row.set(3, null);
205: list.add(row);
206: }
207: return list;
208: }
209:
210: //------------------------------------------------------------------- Tests
211:
212: }
|