001: /*
002: * $Id: TestDQLDiskWithBTreeIndex.java,v 1.7 2005/05/02 22:32:02 ahimanikya 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.ResultSet;
044: import java.sql.Statement;
045:
046: import junit.framework.Test;
047: import junit.framework.TestSuite;
048:
049: /**
050: * @version $Revision: 1.7 $ $Date: 2005/05/02 22:32:02 $
051: * @author Dave Pekarek Krohn
052: * @author Rodney Waldhoff
053: */
054: public class TestDQLDiskWithBTreeIndex extends TestDQLDisk {
055:
056: public TestDQLDiskWithBTreeIndex(String testName) {
057: super (testName);
058: }
059:
060: public static Test suite() {
061: return new TestSuite(TestDQLDiskWithBTreeIndex.class);
062: }
063:
064: protected void createIndexOnFoo() throws Exception {
065: _stmt
066: .execute("create unique btree index FOO_NUM_NDX on FOO ( NUM )");
067: _stmt.execute("create btree index FOO_STR_NDX on FOO ( STR )");
068: }
069:
070: public void testDeleteFromBTreeIndexWithDuplicateKeys()
071: throws Exception {
072: Statement stmt = _conn.createStatement();
073: stmt
074: .execute("create table mytable ( intcol integer, strcol varchar(10), extra integer )");
075: stmt.execute("create btree index intindex on mytable (intcol)");
076: stmt.execute("create btree index strindex on mytable (strcol)");
077: for (int i = 0; i < 10; i++) {
078: stmt.execute("insert into mytable values ( 1, 'key', " + i
079: + " )");
080: }
081:
082: assertNRows(10, "select intcol, strcol, extra from mytable");
083: assertNRows(10,
084: "select intcol, strcol, extra from mytable where strcol = 'key'");
085: assertNRows(10,
086: "select intcol, strcol, extra from mytable where intcol = 1");
087:
088: assertEquals(1, stmt
089: .executeUpdate("delete from mytable where extra = 0"));
090:
091: assertNRows(9, "select intcol, strcol, extra from mytable");
092: {
093: ResultSet rset = stmt
094: .executeQuery("select extra from mytable");
095: while (rset.next()) {
096: assertTrue(rset.getInt(1) != 0);
097: }
098: rset.close();
099: }
100:
101: assertNRows(9,
102: "select intcol, strcol, extra from mytable where strcol = 'key'");
103: {
104: ResultSet rset = stmt
105: .executeQuery("select extra from mytable where strcol = 'key'");
106: while (rset.next()) {
107: assertTrue(rset.getInt(1) != 0);
108: }
109: rset.close();
110: }
111: assertNRows(9,
112: "select intcol, strcol, extra from mytable where intcol = 1");
113: {
114: ResultSet rset = stmt
115: .executeQuery("select extra from mytable where intcol = 1");
116: while (rset.next()) {
117: assertTrue(rset.getInt(1) != 0);
118: }
119: rset.close();
120: }
121: stmt.close();
122: }
123:
124: }
|