001: /*
002: * $Id: TestExternalAxionDBTable.java,v 1.3 2005/12/20 18:32:42 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2004 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.tables;
042:
043: import java.io.File;
044: import java.util.ArrayList;
045: import java.util.List;
046: import java.util.Properties;
047: import java.util.Random;
048:
049: import junit.framework.Test;
050: import junit.framework.TestCase;
051: import junit.framework.TestSuite;
052:
053: import org.axiondb.AxionException;
054: import org.axiondb.Column;
055: import org.axiondb.ColumnIdentifier;
056: import org.axiondb.Database;
057: import org.axiondb.DatabaseLink;
058: import org.axiondb.ExternalConnectionProvider;
059: import org.axiondb.ExternalTable;
060: import org.axiondb.ExternalTableLoader;
061: import org.axiondb.Row;
062: import org.axiondb.RowIterator;
063: import org.axiondb.Table;
064: import org.axiondb.TableIdentifier;
065: import org.axiondb.TransactableTable;
066: import org.axiondb.engine.Databases;
067: import org.axiondb.engine.commands.RemountCommand;
068: import org.axiondb.engine.rows.SimpleRow;
069: import org.axiondb.io.FileUtil;
070: import org.axiondb.types.CharacterVaryingType;
071: import org.axiondb.types.IntegerType;
072:
073: /**
074: * @version $Revision: 1.3 $ $Date: 2005/12/20 18:32:42 $
075: * @author Rodney Waldhoff
076: * @author Ahimanikya Satapathy
077: * @author Jonathan Giron
078: */
079: public class TestExternalAxionDBTable extends TestCase {
080:
081: //------------------------------------------------------------ Conventional
082:
083: public TestExternalAxionDBTable(String testName) {
084: super (testName);
085: }
086:
087: public static Test suite() {
088: TestSuite suite = new TestSuite(TestExternalAxionDBTable.class);
089: return suite;
090: }
091:
092: //--------------------------------------------------------------- Lifecycle
093:
094: private Database _db;
095: private Table _table = null;
096: private ExternalAxionDBTable _externalTable = null;
097: private File _dbDir = new File(new File("."), "testdb2");
098:
099: public void setUp() throws Exception {
100: _dbDir.mkdirs();
101: _db = Databases.getOrCreateDatabase("testdb2", _dbDir);
102: _table = new DiskTable("FOO24", _db);
103: addColumns(_table);
104: _db.addTable(_table);
105: }
106:
107: public void tearDown() throws Exception {
108: _table.shutdown();
109: _table = null;
110:
111: if (_externalTable != null) {
112: _externalTable.drop();
113: _externalTable = null;
114: }
115:
116: if (_db.hasDatabaseLink("AXIONDB")) {
117: _db.dropDatabaseLink("AXIONDB");
118: }
119:
120: _db.shutdown();
121: FileUtil.delete(_dbDir);
122: }
123:
124: private void createExternalTable(String name) throws Exception {
125: String rtable = "FOO24";
126: Properties props = new Properties();
127: props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
128: "org.axiondb.jdbc.AxionDriver");
129: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
130: "jdbc:axiondb:testdb2:testdb2");
131: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
132: "ignored");
133: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
134: "ignored");
135: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
136:
137: props = new Properties();
138: props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
139: props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
140: props.setProperty(ExternalTable.PROP_REMOTETABLE, rtable);
141: props.setProperty(ExternalTable.PROP_VENDOR, "AXION");
142: List columns = new ArrayList(2);
143: Column id = new Column("ID", new IntegerType());
144: id.setSqlType("integer");
145: columns.add(id);
146:
147: Column colname = new Column("NAME",
148: new CharacterVaryingType(10));
149: colname.setSqlType("varchar");
150: columns.add(colname);
151:
152: ExternalTableFactory factory = new ExternalTableFactory();
153: _externalTable = (ExternalAxionDBTable) factory.createTable(
154: _db, name, props, columns);
155: addRow();
156: }
157:
158: private void addColumns(Table t) throws Exception {
159: Column id = new Column("ID", new IntegerType());
160: id.setSqlType("integer");
161: t.addColumn(id);
162:
163: Column name = new Column("NAME", new CharacterVaryingType(20));
164: name.setSqlType("varchar");
165: t.addColumn(name);
166: }
167:
168: private void addRow() throws Exception {
169: {
170: Row row = new SimpleRow(2);
171: row.set(0, new Integer(1));
172: row.set(1, "one");
173: _externalTable.addRow(row);
174: }
175: {
176: Row row = new SimpleRow(2);
177: row.set(0, new Integer(2));
178: row.set(1, "two");
179: _externalTable.addRow(row);
180: }
181: }
182:
183: //------------------------------------------------------------------- Tests
184:
185: public void testGetName() throws Exception {
186: createExternalTable("FOO");
187: assertEquals("FOO", _externalTable.getName());
188: }
189:
190: public void testToString() throws Exception {
191: createExternalTable("FOO");
192: assertNotNull(_externalTable.toString());
193: RowIterator iter = _externalTable.getRowIterator(true);
194: assertNotNull(iter);
195: assertNotNull(iter.toString());
196: }
197:
198: public void testTableProperties() throws Exception {
199: createExternalTable("FOO");
200: assertNotNull(_externalTable.getTableProperties());
201: assertEquals("REMOTE", _externalTable.getTableProperties()
202: .getProperty(ExternalTable.PROP_LOADTYPE));
203: assertEquals("AXIONDB", _externalTable.getTableProperties()
204: .getProperty(ExternalTable.PROP_DB));
205: assertEquals("AXION", _externalTable.getTableProperties()
206: .getProperty(ExternalTable.PROP_VENDOR));
207:
208: }
209:
210: public void testAddThenDropConstraint() throws Exception {
211:
212: }
213:
214: public void testAddThenDropColumn() throws Exception {
215:
216: }
217:
218: public void testGetRowIterator() throws Exception {
219: createExternalTable("FOO");
220:
221: RowIterator iter = _externalTable.getRowIterator(true);
222: assertNotNull(iter);
223:
224: assertFalse(iter.hasPrevious());
225:
226: assertTrue(iter.hasNext());
227: assertNotNull(iter.next());
228: assertNotNull(iter.current());
229: assertTrue(iter.hasNext());
230: assertNotNull(iter.next());
231: assertNotNull(iter.current());
232:
233: assertFalse(iter.hasNext());
234:
235: iter.reset();
236: assertFalse(iter.hasPrevious());
237: assertTrue(iter.hasNext());
238: assertNotNull(iter.next());
239: assertTrue(iter.hasNext());
240: assertNotNull(iter.next());
241:
242: assertFalse(iter.hasNext());
243:
244: assertTrue(iter.hasPrevious());
245: assertNotNull(iter.previous());
246: assertTrue(iter.hasPrevious());
247: assertNotNull(iter.previous());
248: assertFalse(iter.hasPrevious());
249:
250: assertTrue(iter.hasNext());
251: _externalTable.freeRowId(0); // does nothing
252: assertEquals(2, _externalTable.getNextRowId());
253: }
254:
255: public void testGetMatchingRowsForNull() throws Exception {
256: createExternalTable("FOO");
257: RowIterator iter = _externalTable.getMatchingRows(null, null,
258: true);
259: assertNotNull(iter);
260: }
261:
262: public void testDrop() throws Exception {
263: createExternalTable("FOO");
264: _externalTable.drop();
265:
266: _externalTable = null;
267:
268: }
269:
270: public void testRollback() throws Exception {
271: createExternalTable("FOO");
272: TransactableTable tranTable = _externalTable
273: .makeTransactableTable();
274: {
275: Row row = new SimpleRow(2);
276: row.set(0, new Integer(3));
277: row.set(1, "three");
278: tranTable.addRow(row);
279: }
280: tranTable.rollback();
281: assertEquals(2, _externalTable.getRowCount());
282:
283: _externalTable.remount();
284: tranTable = _externalTable.makeTransactableTable();
285: assertEquals(2, _externalTable.getRowCount());
286:
287: RowIterator iter = _externalTable.getRowIterator(true);
288: assertNotNull(iter);
289: assertFalse(iter.hasPrevious());
290:
291: assertTrue(iter.hasNext());
292: assertNotNull(iter.next());
293: assertNotNull(iter.current());
294: assertTrue(iter.hasNext());
295: assertNotNull(iter.next());
296: assertNotNull(iter.current());
297: assertFalse(iter.hasNext());
298: {
299: Row row = new SimpleRow(2);
300: row.set(0, new Integer(3));
301: row.set(1, "three");
302: tranTable.addRow(row);
303: }
304: tranTable.commit();
305: tranTable.apply();
306: assertEquals(3, _externalTable.getRowCount());
307:
308: iter = _externalTable.getRowIterator(true);
309: assertNotNull(iter);
310: assertFalse(iter.hasPrevious());
311:
312: assertTrue(iter.hasNext());
313: assertNotNull(iter.next());
314: assertNotNull(iter.current());
315:
316: assertTrue(iter.hasNext());
317: assertNotNull(iter.next());
318: assertNotNull(iter.current());
319:
320: assertTrue(iter.hasNext());
321: assertNotNull(iter.next());
322: assertNotNull(iter.current());
323:
324: assertFalse(iter.hasNext());
325:
326: _externalTable.shutdown(); // try again
327: _table.shutdown();
328: _externalTable = null;
329: }
330:
331: public void testRemount() throws Exception {
332: testAddRow();
333: _db.addTable(_externalTable);
334: ((ExternalTable) _externalTable).remount();
335:
336: RowIterator iter = _externalTable.getRowIterator(true);
337: assertNotNull(iter);
338: assertTrue(iter.hasNext());
339: assertNotNull(iter.next());
340: assertTrue(iter.hasNext());
341: assertNotNull(iter.next());
342: assertTrue(!iter.hasNext());
343:
344: _table.truncate();
345: _table.shutdown();
346:
347: RemountCommand cmd = new RemountCommand();
348: cmd.setTable(new TableIdentifier(_externalTable.getName()));
349: cmd.execute(_db);
350: iter = _externalTable.getRowIterator(true);
351: assertNotNull(iter);
352: assertTrue(!iter.hasNext());
353:
354: }
355:
356: public void testTruncate() throws Exception {
357: createExternalTable("FOO");
358: _externalTable.truncate();
359: addRow();
360:
361: RowIterator iter = _externalTable.getRowIterator(true);
362: assertNotNull(iter);
363: assertFalse(iter.hasPrevious());
364:
365: assertTrue(iter.hasNext());
366: assertNotNull(iter.next());
367: assertNotNull(iter.current());
368: assertTrue(iter.hasNext());
369: assertNotNull(iter.next());
370: assertNotNull(iter.current());
371: assertFalse(iter.hasNext());
372: _externalTable.truncate();
373:
374: iter = _externalTable.getRowIterator(true);
375: assertNotNull(iter);
376: assertFalse(iter.hasPrevious());
377: assertFalse(iter.hasNext());
378:
379: addRow();
380: assertTrue(iter.hasNext());
381: assertNotNull(iter.next());
382: assertNotNull(iter.current());
383: assertTrue(iter.hasNext());
384: assertNotNull(iter.next());
385: assertNotNull(iter.current());
386: assertFalse(iter.hasNext());
387: }
388:
389: public void testHasColumn() throws Exception {
390: createExternalTable("FOO");
391: ColumnIdentifier id = new ColumnIdentifier("ID");
392:
393: assertTrue("Should have column", _externalTable.hasColumn(id));
394: id.setTableIdentifier(new TableIdentifier("FOO"));
395: assertTrue("Should have column", _externalTable.hasColumn(id));
396:
397: id.setTableIdentifier(new TableIdentifier("bogus"));
398: assertTrue("Should not have column", !_externalTable
399: .hasColumn(id));
400: }
401:
402: public void testInvalidPropertyKey() throws Exception {
403: Properties badProps = new Properties();
404: badProps.put(ExternalTable.PROP_LOADTYPE, "remote");
405: badProps.put("UNKNOWN_PROPERTY", Boolean.TRUE);
406: ExternalTableFactory factory = new ExternalTableFactory();
407: try {
408: factory.createTable(_db, "BadTable", badProps,
409: new ArrayList());
410: fail("Expected AxionException due to unrecognized property name 'UNKNOWN_PROPERTY'");
411: } catch (AxionException expected) {
412: // Expected AxionException due to unrecognized property name.
413: }
414: }
415:
416: public void testMissingRequiredProperty() throws Exception {
417: Properties badProps = new Properties();
418: ExternalTableFactory factory = new ExternalTableFactory();
419: try {
420: factory.createTable(_db, "BadTable", badProps,
421: new ArrayList());
422: fail("Expected AxionException");
423: } catch (AxionException expected) {
424: // expected
425: }
426: }
427:
428: public void testMissingDriverProperty() throws Exception {
429: // Null driver test
430: try {
431: Properties props = new Properties();
432: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
433: "jdbc:axiondb:testdb2:testdb2");
434: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
435: "ignored");
436: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
437: "ignored");
438: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
439:
440: fail("Expected AxionException due to null driver class");
441: } catch (Exception expected) {
442: // Expected AxionException due to unrecognized property name.
443:
444: }
445: }
446:
447: public void testBadLoaderType() throws Exception {
448: Properties props = new Properties();
449: props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
450: "org.axiondb.jdbc.AxionDriver");
451: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
452: "jdbc:axiondb:testdb2:testdb2");
453: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
454: "ignored");
455: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
456: "ignored");
457: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
458:
459: ExternalTableFactory factory = new ExternalTableFactory();
460: props = new Properties();
461:
462: try {
463: factory.assertValidProperty(props);
464: fail("Expected Exception");
465: } catch (Exception e) {
466: // excepted
467: }
468:
469: try {
470: factory.assertValidProperty(null);
471: fail("Expected Exception");
472: } catch (Exception e) {
473: // excepted
474: }
475:
476: props.setProperty(ExternalTable.PROP_DB, "axiondb");
477:
478: try {
479: factory.assertValidProperty(props);
480: fail("Expected Exception");
481: } catch (Exception e) {
482: // excepted
483: }
484:
485: props.setProperty(ExternalTable.PROP_LOADTYPE, "bogus");
486: props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
487: List columns = new ArrayList(2);
488: columns.add(new Column("ID", new IntegerType()));
489: columns.add(new Column("NAME", new CharacterVaryingType(10)));
490:
491: try {
492: _externalTable = (ExternalAxionDBTable) factory
493: .createTable(_db, "bogus");
494: fail("Expected Exception");
495: } catch (Exception e) {
496: // excepted
497: }
498:
499: try {
500: _externalTable = (ExternalAxionDBTable) factory
501: .createTable(_db, "bogus", props, columns);
502: fail("Expected Exception");
503: } catch (Exception e) {
504: // excepted
505: }
506: }
507:
508: public void testBadDriverClass() throws Exception {
509: // bad driver class
510: try {
511: Properties props = new Properties();
512: props.setProperty(
513: ExternalConnectionProvider.PROP_DRIVERCLASS,
514: "org.axiondb.AxionDriver");
515: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
516: "jdbc:axiondb:testdb2:testdb2");
517: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
518: "ignored");
519: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
520: "ignored");
521: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
522:
523: props = new Properties();
524: props.setProperty(ExternalTable.PROP_DB, "axiondb");
525: props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
526: props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
527: List columns = new ArrayList(2);
528: columns.add(new Column("ID", new IntegerType()));
529: columns
530: .add(new Column("NAME",
531: new CharacterVaryingType(10)));
532:
533: ExternalTableFactory factory = new ExternalTableFactory();
534: _externalTable = (ExternalAxionDBTable) factory
535: .createTable(_db, "FOO24", props, columns);
536: fail("Expected AxionException due to bad driver class");
537: } catch (Exception expected) {
538: // Expected AxionException due to unrecognized property name.
539: }
540: }
541:
542: public void testBadUrlProperty() throws Exception {
543: // bad url
544: try {
545: Properties props = new Properties();
546: props.setProperty(
547: ExternalConnectionProvider.PROP_DRIVERCLASS,
548: "org.axiondb.jdbc.AxionDriver");
549: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
550: "jdbc");
551: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
552: "ignored");
553: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
554: "ignored");
555: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
556:
557: props = new Properties();
558: props.setProperty(ExternalTable.PROP_DB, "axiondb");
559: props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
560: props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
561: List columns = new ArrayList(2);
562: columns.add(new Column("ID", new IntegerType()));
563: columns
564: .add(new Column("NAME",
565: new CharacterVaryingType(10)));
566:
567: ExternalTableFactory factory = new ExternalTableFactory();
568: _externalTable = (ExternalAxionDBTable) factory
569: .createTable(_db, "FOO24", props, columns);
570: fail("Expected AxionException due to bad driver class");
571: } catch (Exception expected) {
572: // Expected AxionException due to unrecognized property name.
573: }
574: }
575:
576: public void testAddRow() throws Exception {
577: createExternalTable("FOO");
578: }
579:
580: public void testNoNewColumnsAfterRowsAdded() throws Exception {
581: }
582:
583: public void testGetColumnByIndex() throws Exception {
584: createExternalTable("FOO");
585: assertEquals("ID", _externalTable.getColumn(0).getName());
586: assertEquals("NAME", _externalTable.getColumn(1).getName());
587: }
588:
589: public void testGetColumnByIndexBadIndex() throws Exception {
590: createExternalTable("FOO");
591: try {
592: _externalTable.getColumn(-1);
593: fail("Expected IndexOutOfBoundsException");
594: } catch (IndexOutOfBoundsException e) {
595: // expected
596: }
597:
598: try {
599: _externalTable.getColumn(3);
600: fail("Expected IndexOutOfBoundsException");
601: } catch (IndexOutOfBoundsException e) {
602: // expected
603: }
604: }
605:
606: public void testGetColumnByName() throws Exception {
607: createExternalTable("FOO");
608: assertTrue(_externalTable.getColumn("ID").getDataType() instanceof IntegerType);
609: assertTrue(_externalTable.getColumn("NAME").getDataType() instanceof CharacterVaryingType);
610: }
611:
612: public void testGetColumnByNameBadName() throws Exception {
613: createExternalTable("FOO");
614: assertNull(_externalTable.getColumn("FOO"));
615: assertNull(_externalTable.getColumn("ID1"));
616: }
617:
618: public void testDataTypes() throws Exception {
619: Properties props = new Properties();
620: props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
621: "org.axiondb.jdbc.AxionDriver");
622: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
623: "jdbc:axiondb:testdb2:testdb2");
624: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
625: "ignored");
626: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
627: "ignored");
628: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
629:
630: props = new Properties();
631: props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
632: props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
633: props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
634: props.setProperty(ExternalTable.PROP_VENDOR, "AXION");
635:
636: ExternalTableLoader loader = new ExternalAxionDBTableLoader();
637: _externalTable = (ExternalAxionDBTable) loader.createTable(_db,
638: "FOO");
639:
640: _externalTable.addColumn(new Column("ID", new IntegerType()));
641: _externalTable.addColumn(new Column("NAME",
642: new CharacterVaryingType(30)));
643:
644: _externalTable.loadExternalTable(props);
645:
646: Object[][] values = new Object[][] {
647: new Object[] { new Integer(17), new Integer(0),
648: new Integer(5575), null },
649: new Object[] { "", "A String", "Another String", null }, };
650:
651: Random random = new Random();
652: int numRows = 7;
653:
654: for (int i = 0; i < numRows; i++) {
655: Row row = new SimpleRow(_externalTable.getColumnCount());
656: for (int j = 0; j < _externalTable.getColumnCount(); j++) {
657: row.set(j, values[j][random.nextInt(values[j].length)]);
658: }
659: _externalTable.addRow(row);
660: }
661:
662: RowIterator iter = _externalTable.getRowIterator(true);
663: assertNotNull(iter);
664: for (int i = 0; i < numRows; i++) {
665: assertTrue(iter.hasNext());
666: assertNotNull(iter.next());
667: }
668: assertTrue(!iter.hasNext());
669: }
670:
671: public void testRemoteUpdate() throws Exception {
672: Properties props = new Properties();
673: props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
674: "org.axiondb.jdbc.AxionDriver");
675: props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
676: "jdbc:axiondb:testdb2:testdb2");
677: props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
678: "ignored");
679: props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
680: "ignored");
681: _db.createDatabaseLink(new DatabaseLink("axiondb", props));
682:
683: props = new Properties();
684: props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
685: props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
686: props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
687: props.setProperty(ExternalTable.PROP_VENDOR, "AXION");
688:
689: ExternalTableLoader loader = new ExternalAxionDBTableLoader();
690: _externalTable = (ExternalAxionDBTable) loader.createTable(_db,
691: "FOO");
692:
693: _externalTable.addColumn(new Column("ID", new IntegerType()));
694: _externalTable.addColumn(new Column("NAME",
695: new CharacterVaryingType(20)));
696:
697: _externalTable.loadExternalTable(props);
698:
699: final String stringTemplate = "My ID is ";
700: Object[][] values = new Object[][] {
701: new Object[] { new Integer(1), new Integer(2),
702: new Integer(46), new Integer(100) },
703: new Object[] { null, null, null, null } };
704:
705: Random random = new Random();
706: int numRows = 7;
707:
708: for (int i = 0; i < numRows; i++) {
709: Row row = new SimpleRow(_externalTable.getColumnCount());
710: for (int j = 0; j < _externalTable.getColumnCount(); j++) {
711: row.set(j, values[j][random.nextInt(values[j].length)]);
712: }
713: _externalTable.addRow(row);
714: }
715:
716: RowIterator iter = _externalTable.getRowIterator(true);
717: assertNotNull(iter);
718: for (int i = 0; i < numRows; i++) {
719: assertTrue(iter.hasNext());
720: assertNotNull(iter.next());
721: }
722: assertTrue(!iter.hasNext());
723:
724: RowIterator modIter = _externalTable.getRowIterator(false);
725: while (modIter.hasNext()) {
726: Row oldRow = modIter.next();
727: Row newRow = new SimpleRow(_externalTable.getColumnCount());
728: newRow.set(0, oldRow.get(0));
729: newRow.set(1, stringTemplate + oldRow.get(0));
730:
731: _externalTable.updateRow(oldRow, newRow);
732: }
733:
734: iter = _externalTable.getRowIterator(true);
735: assertNotNull(iter);
736: for (int i = 0; i < numRows; i++) {
737: assertTrue(iter.hasNext());
738: Row row = iter.next();
739: assertNotNull(row);
740: assertEquals(stringTemplate + row.get(0), row.get(1));
741: }
742: assertTrue(!iter.hasNext());
743: }
744: }
|