001: /*
002: * $Id: TestExternalAxionDBTableRowIterator.java,v 1.1 2005/06/29 21:11:10 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.engine.tables;
041:
042: import java.util.ArrayList;
043: import java.util.List;
044: import java.util.Properties;
045:
046: import junit.framework.Test;
047: import junit.framework.TestSuite;
048:
049: import org.axiondb.AxionException;
050: import org.axiondb.Column;
051: import org.axiondb.Database;
052: import org.axiondb.DatabaseLink;
053: import org.axiondb.ExternalConnectionProvider;
054: import org.axiondb.ExternalTable;
055: import org.axiondb.RowIterator;
056: import org.axiondb.Table;
057: import org.axiondb.engine.Databases;
058: import org.axiondb.engine.rowiterators.AbstractRowIteratorTest;
059: import org.axiondb.engine.rows.SimpleRow;
060: import org.axiondb.types.CharacterVaryingType;
061: import org.axiondb.types.IntegerType;
062:
063: /**
064: *
065: * @author Jonathan Giron
066: * @version $Revision: 1.1 $
067: */
068: public class TestExternalAxionDBTableRowIterator extends
069: AbstractRowIteratorTest {
070:
071: private static final String DATABASE_NAME = "REMOTEDB";
072: private static final String DBLINK_NAME = "AXIONDB";
073:
074: /**
075: * @param testName
076: */
077: public TestExternalAxionDBTableRowIterator(String testName) {
078: super (testName);
079: }
080:
081: public static Test suite() {
082: TestSuite suite = new TestSuite(
083: TestExternalAxionDBTableRowIterator.class);
084: return suite;
085: }
086:
087: protected void setUp() throws Exception {
088: setUpRemote();
089: createExternalTable(getRemoteTableName());
090: }
091:
092: protected void setUpRemote() throws Exception {
093: _db = Databases.getOrCreateDatabase(DATABASE_NAME, null);
094: _table = new MemoryTable(getRemoteTableName());
095: addColumns(_table);
096: _db.addTable(_table);
097: addRow();
098: }
099:
100: protected void tearDown() throws Exception {
101: if (_externalTable != null) {
102: _externalTable.shutdown();
103: _externalTable = null;
104: }
105:
106: if (_db.hasDatabaseLink(DBLINK_NAME)) {
107: _db.dropDatabaseLink(DBLINK_NAME);
108: }
109:
110: _db.dropTable(getRemoteTableName());
111: _table.shutdown();
112: _table = null;
113:
114: _db.shutdown();
115: try {
116: Databases.forgetDatabase(DATABASE_NAME);
117: } catch (Exception e) {
118: // ignored
119: }
120:
121: }
122:
123: protected RowIterator makeRowIterator() {
124: try {
125: return _externalTable.getRowIterator(false);
126: } catch (AxionException e) {
127: throw new UnsupportedOperationException(
128: "Could not get RowIterator from external table.");
129: }
130: }
131:
132: protected String getJdbcDriverName() {
133: return "org.axiondb.jdbc.AxionDriver";
134: }
135:
136: protected String getJdbcURL() {
137: return "jdbc:axiondb:" + DATABASE_NAME;
138: }
139:
140: protected String getUserName() {
141: return "ignored";
142: }
143:
144: protected String getPassword() {
145: return "ignored";
146: }
147:
148: protected String getSchemaName() {
149: return "";
150: }
151:
152: protected String getRemoteTableName() {
153: return "REMOTETABLE";
154: }
155:
156: protected int getSize() {
157: return 3;
158: }
159:
160: protected List makeRowList() {
161: List list = new ArrayList();
162: {
163: SimpleRow row = new SimpleRow(2);
164: row.set(0, new Integer(1));
165: row.set(1, "a");
166: list.add(row);
167: }
168: {
169: SimpleRow row = new SimpleRow(2);
170: row.set(0, new Integer(2));
171: row.set(1, "bb");
172: list.add(row);
173: }
174: {
175: SimpleRow row = new SimpleRow(2);
176: row.set(0, new Integer(3));
177: row.set(1, "ccc");
178: list.add(row);
179: }
180: return list;
181: }
182:
183: private List buildColumns() {
184: List list = new ArrayList(2);
185:
186: Column id = new Column("id", new IntegerType());
187: id.setSqlType("integer");
188: list.add(id);
189:
190: Column name = new Column("name", new CharacterVaryingType(10));
191: name.setSqlType("varchar");
192: list.add(name);
193: return list;
194: }
195:
196: private void addColumns(Table t) throws Exception {
197: Column id = new Column("id", new IntegerType());
198: id.setSqlType("integer");
199: t.addColumn(id);
200:
201: Column name = new Column("name", new CharacterVaryingType(10));
202: name.setSqlType("varchar");
203: t.addColumn(name);
204: }
205:
206: private Properties getDBLinkProperties() {
207: Properties props = new Properties();
208: props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
209: getJdbcDriverName());
210: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
211: getJdbcURL());
212: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
213: getUserName());
214: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
215: getPassword());
216:
217: return props;
218: }
219:
220: private Properties getExternalTableProperties(String name) {
221: Properties props = new Properties();
222: props.setProperty(ExternalTable.PROP_DB, DBLINK_NAME);
223: props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
224: props.setProperty(ExternalTable.PROP_VENDOR, "AXION");
225: props.setProperty(ExternalTable.PROP_REMOTETABLE, name);
226: return props;
227: }
228:
229: private void createExternalTable(String name) throws Exception {
230: _db.createDatabaseLink(new DatabaseLink(DBLINK_NAME,
231: getDBLinkProperties()));
232:
233: ExternalTableFactory factory = new ExternalTableFactory();
234: _externalTable = (ExternalAxionDBTable) factory.createTable(
235: _db, name + "_EXT", getExternalTableProperties(name),
236: buildColumns());
237: }
238:
239: private void addRow() throws Exception {
240: {
241: SimpleRow row = new SimpleRow(2);
242: row.set(0, new Integer(1));
243: row.set(1, "a");
244: _table.addRow(row);
245: }
246: {
247: SimpleRow row = new SimpleRow(2);
248: row.set(0, new Integer(2));
249: row.set(1, "bb");
250: _table.addRow(row);
251: }
252: {
253: SimpleRow row = new SimpleRow(2);
254: row.set(0, new Integer(3));
255: row.set(1, "ccc");
256: _table.addRow(row);
257: }
258: }
259:
260: private Database _db;
261: private ExternalAxionDBTable _externalTable = null;
262: private Table _table = null;
263: }
|