001: /*
002: * $Id: TestIndexedJoin.java,v 1.2 2003/03/27 19:14:02 rwald Exp $
003: * =======================================================================
004: * Copyright (c) 2002 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.functional;
042:
043: import java.sql.Connection;
044: import java.sql.DriverManager;
045: import java.sql.PreparedStatement;
046: import java.sql.ResultSet;
047: import java.sql.SQLException;
048: import java.sql.Statement;
049:
050: import junit.framework.Test;
051: import junit.framework.TestCase;
052: import junit.framework.TestSuite;
053:
054: /**
055: * @version $Revision: 1.2 $ $Date: 2003/03/27 19:14:02 $
056: * @author Rodney Waldhoff
057: */
058: public class TestIndexedJoin extends TestCase {
059: protected Connection _conn = null;
060: protected ResultSet _rset = null;
061: protected Statement _stmt = null;
062:
063: //------------------------------------------------------------ Conventional
064:
065: public TestIndexedJoin(String testName) {
066: super (testName);
067: }
068:
069: public static Test suite() {
070: return new TestSuite(TestIndexedJoin.class);
071: }
072:
073: //--------------------------------------------------------------- Lifecycle
074:
075: public void setUp() throws SQLException, ClassNotFoundException {
076: Class.forName("org.axiondb.jdbc.AxionDriver");
077: _conn = DriverManager.getConnection("jdbc:axiondb:memdb");
078: _stmt = _conn.createStatement();
079: }
080:
081: public void tearDown() throws Exception {
082: try {
083: _rset.close();
084: } catch (Exception t) {
085: }
086: try {
087: _stmt.close();
088: } catch (Exception t) {
089: }
090: try {
091: _conn.close();
092: } catch (Exception t) {
093: }
094: _rset = null;
095: _stmt = null;
096: _conn = null;
097: {
098: Connection conn = DriverManager
099: .getConnection("jdbc:axiondb:memdb");
100: Statement stmt = conn.createStatement();
101: stmt.execute("shutdown");
102: stmt.close();
103: conn.close();
104: }
105: }
106:
107: //------------------------------------------------------------------- Tests
108:
109: public void testSelectOneRow() throws Exception {
110: createTableFoo();
111: populateTableFoo();
112: createTableBar();
113: populateTableBar();
114:
115: PreparedStatement stmt = _conn
116: .prepareStatement("select FOO.B from FOO, BAR where FOO.A = BAR.A and BAR.B = ?");
117: for (int i = 0; i < 10; i++) {
118: stmt.setInt(1, i * 2);
119: _rset = stmt.executeQuery();
120: assertNotNull("Should have been able to create ResultSet",
121: _rset);
122: assertTrue(_rset.next());
123: assertEquals((i * 2), _rset.getInt(1));
124: assertTrue(!_rset.next());
125: _rset.close();
126: }
127: }
128:
129: //-------------------------------------------------------------------- Util
130:
131: private void createTableFoo() throws Exception {
132: _stmt.execute("create table FOO ( A integer, B integer )");
133: _stmt.execute("create index FOO_NDX on FOO ( A )");
134: }
135:
136: private void populateTableFoo() throws Exception {
137: for (int i = 0; i < 10; i++) {
138: _stmt.execute("insert into FOO ( A, B ) values ( " + i
139: + "," + (2 * i) + ")");
140: }
141: }
142:
143: private void createTableBar() throws Exception {
144: _stmt.execute("create table BAR ( A integer, B integer )");
145: _stmt.execute("create index BAR_NDX on BAR ( B )");
146: }
147:
148: private void populateTableBar() throws Exception {
149: for (int i = 0; i < 10; i++) {
150: _stmt.execute("insert into BAR ( A, B ) values ( " + i
151: + "," + (2 * i) + ")");
152: }
153: }
154:
155: }
|