001: /*
002: * $Id: TestAxionResultSet_DelimitedFlatfile.java,v 1.2 2005/04/09 02:04:38 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: package org.axiondb.jdbc;
041:
042: import java.io.File;
043: import java.sql.ResultSet;
044: import java.sql.SQLException;
045:
046: import org.axiondb.io.FileUtil;
047:
048: import junit.framework.Test;
049: import junit.framework.TestSuite;
050: import junit.textui.TestRunner;
051:
052: /**
053: *
054: * @author Jonathan Giron
055: * @version $Revision: 1.2 $
056: */
057: public class TestAxionResultSet_DelimitedFlatfile extends
058: TestAxionResultSet {
059:
060: private static final String DATABASE_NAME = "JDBC_DelimitedFFDB";
061:
062: /**
063: * Constructor for TestAxionResultSet_DelimitedFlatfile.
064: * @param arg0
065: */
066: public TestAxionResultSet_DelimitedFlatfile(String testName) {
067: super (testName);
068: }
069:
070: public static void main(String[] args) {
071: TestRunner.run(suite());
072: }
073:
074: public static Test suite() {
075: return new TestSuite(TestAxionResultSet_DelimitedFlatfile.class);
076: }
077:
078: protected void doCleanup() throws Exception {
079: if (_rset != null) {
080: _rset.close();
081: }
082:
083: if (_stmt != null) {
084: _stmt.execute("drop table foo");
085: _stmt.close();
086: }
087:
088: if (_conn != null) {
089: _conn.close();
090: }
091:
092: FileUtil.delete(getDatabaseDirectory());
093: }
094:
095: protected String getDatabaseName() {
096: return DATABASE_NAME;
097: }
098:
099: protected File getDatabaseDirectory() {
100: return new File(".", DATABASE_NAME);
101: }
102:
103: /**
104: * Creates basic (scrollable, read-only) table for use in general ResultSet testing.
105: *
106: * @throws Exception if error occurs during table or ResultSet construction
107: */
108: protected void createBasicTable() throws Exception {
109: if (_stmt != null) {
110: _stmt.close();
111: }
112:
113: _stmt = (AxionStatement) _conn.createStatement(
114: ResultSet.TYPE_SCROLL_SENSITIVE,
115: ResultSet.CONCUR_UPDATABLE);
116: try {
117: _stmt.executeUpdate("drop table foo");
118: } catch (SQLException ignore) {
119: // ignore - table doesn't exist.
120: }
121:
122: _stmt
123: .executeUpdate("create external table foo (test varchar(10), num int) organization ("
124: + "loadtype='delimited' filename='basicfoo.txt')");
125: _stmt.execute("truncate table foo");
126:
127: _conn.setAutoCommit(false);
128: for (int i = 0; i < IMAX; i++) {
129: for (int j = 0; j < JMAX; j++) {
130: _stmt.executeUpdate("insert into foo values ('"
131: + String.valueOf((char) (65 + i)) + "', " + j
132: + ")");
133: }
134: }
135: _conn.commit();
136: _conn.setAutoCommit(true);
137:
138: _stmt = (AxionStatement) _conn.createStatement(
139: ResultSet.TYPE_SCROLL_SENSITIVE,
140: ResultSet.CONCUR_READ_ONLY);
141: _stmt.executeQuery("select * from foo");
142: _rset = _stmt.getCurrentResultSet();
143: }
144:
145: /**
146: * Creates empty table for use in testing position logic against a degenerate AxionResultSet.
147: *
148: * @throws Exception if error occurs during table or ResultSet construction
149: */
150: protected void createEmptyTable() throws Exception {
151: if (_stmt != null) {
152: _stmt.close();
153: }
154:
155: _stmt = (AxionStatement) _conn.createStatement(
156: ResultSet.TYPE_SCROLL_SENSITIVE,
157: ResultSet.CONCUR_UPDATABLE);
158:
159: try {
160: _stmt.execute("drop table foo");
161: } catch (SQLException ignore) {
162: // ignore and continue
163: }
164: _stmt
165: .execute("create external table foo (id int) organization (loadtype='delimited' filename='emptyfoo.txt')");
166: _stmt.execute("truncate table foo");
167:
168: _rset = _stmt.executeQuery("select * from foo");
169: }
170:
171: /**
172: * Creates empty table for use in testing position logic against a degenerate AxionResultSet.
173: *
174: * @throws Exception if error occurs during table or ResultSet construction
175: */
176: protected void createOneRowTable() throws Exception {
177: if (_stmt != null) {
178: _stmt.close();
179: }
180:
181: _stmt = (AxionStatement) _conn.createStatement(
182: ResultSet.TYPE_SCROLL_SENSITIVE,
183: ResultSet.CONCUR_UPDATABLE);
184: try {
185: _stmt.execute("drop table foo");
186: } catch (SQLException ignore) {
187: // ignore and continue
188: }
189: _stmt
190: .execute("create external table foo (id int) organization (loadtype='delimited' filename='onerowfoo.txt')");
191: _stmt.execute("truncate table foo");
192:
193: _stmt.execute("insert into foo values (1)");
194:
195: _rset = _stmt.executeQuery("select * from foo");
196: }
197:
198: /**
199: * Constructs a table for use in testing updating methods in AxionResultSet.
200: *
201: * @throws Exception if error occurs during table or ResultSet construction
202: */
203: protected void createUpdateTable() throws Exception {
204: if (_stmt != null) {
205: _stmt.close();
206: }
207:
208: _stmt = (AxionStatement) _conn.createStatement(
209: ResultSet.TYPE_SCROLL_SENSITIVE,
210: ResultSet.CONCUR_UPDATABLE);
211:
212: try {
213: _stmt.execute("drop table foo");
214: } catch (SQLException ignore) {
215: // ignore and continue
216: }
217: String createString = "create external table foo (id int, str_10 varchar(10), dt date, "
218: + "tm time, ts timestamp, bool boolean) organization (loadtype='delimited' filename='updatefoo.txt')";
219: _stmt.execute(createString);
220: _stmt.execute("truncate table foo");
221:
222: _stmt
223: .execute("insert into foo values (1, 'This is 1', '2005-01-01', '12:34:56', '2005-03-31 23:56:00.0', false)");
224: _stmt
225: .execute("insert into foo values (2, 'This is 2', '2005-02-02', '23:45:00', '2005-04-01 00:00:00.0', false)");
226: _stmt
227: .execute("insert into foo values (3, 'This is 3', '2005-03-03', '06:30:30', '2005-04-02 01:23:45.6', false)");
228: _stmt
229: .execute("insert into foo values (4, 'This is 4', '2005-04-04', '07:45:45', '2005-04-03 02:34:32.1', false)");
230:
231: _rset = _stmt.executeQuery("select * from foo");
232: }
233:
234: }
|