Source Code Cross Referenced for TestExternalDatabaseTable.java in  » Database-DBMS » axion » org » axiondb » engine » tables » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » axion » org.axiondb.engine.tables 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TestExternalDatabaseTable.java,v 1.14 2005/12/26 20:33:25 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.Index;
062:        import org.axiondb.Row;
063:        import org.axiondb.RowIterator;
064:        import org.axiondb.Table;
065:        import org.axiondb.TableIdentifier;
066:        import org.axiondb.TransactableTable;
067:        import org.axiondb.constraints.NotNullConstraint;
068:        import org.axiondb.constraints.NullConstraint;
069:        import org.axiondb.constraints.PrimaryKeyConstraint;
070:        import org.axiondb.constraints.UniqueConstraint;
071:        import org.axiondb.engine.Databases;
072:        import org.axiondb.engine.commands.RemountCommand;
073:        import org.axiondb.engine.rows.SimpleRow;
074:        import org.axiondb.io.FileUtil;
075:        import org.axiondb.types.CharacterVaryingType;
076:        import org.axiondb.types.IntegerType;
077:
078:        /**
079:         * @version $Revision: 1.14 $ $Date: 2005/12/26 20:33:25 $
080:         * @author Rodney Waldhoff
081:         * @author Ahimanikya Satapathy
082:         * @author Jonathan Giron
083:         */
084:        public class TestExternalDatabaseTable extends TestCase {
085:
086:            //------------------------------------------------------------ Conventional
087:
088:            public TestExternalDatabaseTable(String testName) {
089:                super (testName);
090:            }
091:
092:            public static Test suite() {
093:                TestSuite suite = new TestSuite(TestExternalDatabaseTable.class);
094:                return suite;
095:            }
096:
097:            //--------------------------------------------------------------- Lifecycle
098:
099:            private Database _db;
100:            private Table _table = null;
101:            private ExternalDatabaseTable _externalTable = null;
102:            private File _dbDir = new File(new File("."), "testdb2");
103:
104:            public void setUp() throws Exception {
105:                _dbDir.mkdirs();
106:                _db = Databases.getOrCreateDatabase("testdb2", _dbDir);
107:                _table = new DiskTable("FOO24", _db);
108:                addColumns(_table);
109:                _db.addTable(_table);
110:            }
111:
112:            public void tearDown() throws Exception {
113:                _table.shutdown();
114:                _table = null;
115:
116:                if (_externalTable != null) {
117:                    _externalTable.drop();
118:                    _externalTable = null;
119:                }
120:
121:                if (_db.hasDatabaseLink("AXIONDB")) {
122:                    _db.dropDatabaseLink("AXIONDB");
123:                }
124:
125:                _db.shutdown();
126:                FileUtil.delete(_dbDir);
127:            }
128:
129:            private void createExternalTable(String name) throws Exception {
130:                createExternalTable("FOO", "", "");
131:            }
132:
133:            private void createExternalTable(String name, String where)
134:                    throws Exception {
135:                createExternalTable("FOO", where, "");
136:            }
137:
138:            private void createExternalTable(String name, String where,
139:                    String orderby) throws Exception {
140:                String rtable = "FOO24";
141:                Properties props = new Properties();
142:                props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
143:                        "org.axiondb.jdbc.AxionDriver");
144:                props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
145:                        "jdbc:axiondb:testdb2:testdb2");
146:                props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
147:                        "ignored");
148:                props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
149:                        "ignored");
150:                _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
151:
152:                props = new Properties();
153:                props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
154:                props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
155:                props.setProperty(ExternalTable.PROP_WHERE, where);
156:                props.setProperty(ExternalTable.PROP_ORDERBY, orderby);
157:                props.setProperty(ExternalTable.PROP_REMOTETABLE, rtable);
158:                props.setProperty(ExternalTable.PROP_CREATE_IF_NOT_EXIST,
159:                        Boolean.TRUE.toString());
160:                List columns = new ArrayList(2);
161:                Column id = new Column("ID", new IntegerType());
162:                id.setSqlType("integer");
163:                columns.add(id);
164:
165:                Column colname = new Column("NAME",
166:                        new CharacterVaryingType(10));
167:                colname.setSqlType("varchar");
168:                columns.add(colname);
169:
170:                ExternalTableFactory factory = new ExternalTableFactory();
171:                _externalTable = (ExternalDatabaseTable) factory.createTable(
172:                        _db, name, props, columns);
173:                addRow();
174:            }
175:
176:            private void addColumns(Table t) throws Exception {
177:                Column id = new Column("ID", new IntegerType());
178:                id.setSqlType("integer");
179:                t.addColumn(id);
180:
181:                Column name = new Column("NAME", new CharacterVaryingType(20));
182:                name.setSqlType("varchar");
183:                t.addColumn(name);
184:            }
185:
186:            private void addRow() throws Exception {
187:                {
188:                    Row row = new SimpleRow(2);
189:                    row.set(0, new Integer(1));
190:                    row.set(1, "one");
191:                    _externalTable.addRow(row);
192:                }
193:                {
194:                    Row row = new SimpleRow(2);
195:                    row.set(0, new Integer(2));
196:                    row.set(1, "two");
197:                    _externalTable.addRow(row);
198:                }
199:                _externalTable.commit();
200:            }
201:
202:            //------------------------------------------------------------------- Tests
203:
204:            public void testGetName() throws Exception {
205:                createExternalTable("FOO");
206:                assertEquals("FOO", _externalTable.getName());
207:            }
208:
209:            public void testToString() throws Exception {
210:                createExternalTable("FOO");
211:                assertNotNull(_externalTable.toString());
212:                RowIterator iter = _externalTable.getRowIterator(true);
213:                assertNotNull(iter);
214:                assertNotNull(iter.toString());
215:            }
216:
217:            public void testTableProperties() throws Exception {
218:                createExternalTable("FOO", "ID = 1");
219:                assertNotNull(_externalTable.getTableProperties());
220:                assertEquals("REMOTE", _externalTable.getTableProperties()
221:                        .getProperty(ExternalTable.PROP_LOADTYPE));
222:                assertEquals("AXIONDB", _externalTable.getTableProperties()
223:                        .getProperty(ExternalTable.PROP_DB));
224:                assertEquals("ID = 1", _externalTable.getTableProperties()
225:                        .getProperty(ExternalTable.PROP_WHERE));
226:
227:            }
228:
229:            public void testAddThenDropConstraint() throws Exception {
230:                createExternalTable("FOO");
231:                _db.addTable(_externalTable);
232:                PrimaryKeyConstraint pk = new PrimaryKeyConstraint("PK_FOO");
233:                pk.addSelectable(new ColumnIdentifier(
234:                        new TableIdentifier("FOO"), "ID"));
235:                _externalTable.addConstraint(pk);
236:                Column column = _externalTable.getColumn("ID");
237:
238:                try {
239:                    _externalTable.addConstraint(new PrimaryKeyConstraint(
240:                            "PK_BAR"));
241:                    fail("Expected AxionException");
242:                } catch (AxionException e) {
243:                    // expected
244:                }
245:                try {
246:                    _externalTable
247:                            .addConstraint(new NotNullConstraint("PK_FOO"));
248:                    fail("Expected AxionException");
249:                } catch (AxionException e) {
250:                    // expected
251:                }
252:                _externalTable
253:                        .removeConstraint("this constraint does not exist");
254:                _externalTable.removeConstraint("PRIMARYKEY");
255:                _externalTable.addConstraint(pk);
256:                _externalTable.removeConstraint("PK_FOO");
257:                _externalTable.removeConstraint("PRIMARYKEY"); // shd be silent
258:
259:                _externalTable.addConstraint(pk);
260:                _externalTable.addConstraint(new NotNullConstraint("NN_FOO"));
261:                _externalTable.removeConstraint("NN_FOO");
262:                _externalTable.addConstraint(new NullConstraint("N_FOO"));
263:                _externalTable.removeConstraint("N_FOO");
264:                _externalTable.addConstraint(new UniqueConstraint("U_BAR"));
265:                _externalTable.removeConstraint("U_BAR");
266:                _externalTable.removeConstraint(null);
267:                _db.dropTable(_externalTable.getName());
268:                _externalTable = null;
269:            }
270:
271:            public void testAddThenDropColumn() throws Exception {
272:                // TODO: Make this test pass
273:            }
274:
275:            public void testGetRowIterator() throws Exception {
276:                createExternalTable("FOO");
277:
278:                RowIterator iter = _externalTable.getRowIterator(true);
279:                assertNotNull(iter);
280:
281:                assertFalse(iter.hasPrevious());
282:
283:                assertTrue(iter.hasNext());
284:                assertNotNull(iter.next());
285:                assertNotNull(iter.current());
286:                assertTrue(iter.hasNext());
287:                assertNotNull(iter.next());
288:                assertNotNull(iter.current());
289:
290:                assertFalse(iter.hasNext());
291:
292:                iter.reset();
293:                assertFalse(iter.hasPrevious());
294:                assertTrue(iter.hasNext());
295:                assertNotNull(iter.next());
296:                assertTrue(iter.hasNext());
297:                assertNotNull(iter.next());
298:
299:                assertFalse(iter.hasNext());
300:
301:                assertTrue(iter.hasPrevious());
302:                assertNotNull(iter.previous());
303:                assertTrue(iter.hasPrevious());
304:                assertNotNull(iter.previous());
305:                assertFalse(iter.hasPrevious());
306:
307:                assertTrue(iter.hasNext());
308:                _externalTable.freeRowId(0); // does nothing
309:                assertNull(_externalTable.getRow(2));
310:            }
311:
312:            public void testGetMatchingRowsForNull() throws Exception {
313:                createExternalTable("FOO");
314:                RowIterator iter = _externalTable.getMatchingRows(null, null,
315:                        true);
316:                assertNotNull(iter);
317:            }
318:
319:            public void testDrop() throws Exception {
320:                createExternalTable("FOO");
321:                _externalTable.drop();
322:
323:                try {
324:                    _table.shutdown();
325:                    _externalTable.drop();
326:                    fail("Expected Exception");
327:                } catch (AxionException e) {
328:                    // expected
329:                }
330:
331:                // Note that remote table does exist,
332:                // so ExternalDatabaseTable should create one.
333:                createExternalTable("FOO");
334:                _externalTable.shutdown();
335:                _externalTable.shutdown(); // try again
336:                _externalTable.commit(); // does nothing if _conn is null
337:                _table.shutdown();
338:
339:                try {
340:                    _externalTable.drop();
341:                    fail("Expected Exception");
342:                } catch (AxionException e) {
343:                    // expected
344:                }
345:
346:                _externalTable = null;
347:
348:            }
349:
350:            public void testRollback() throws Exception {
351:                createExternalTable("FOO");
352:                TransactableTable tranTable = _externalTable
353:                        .makeTransactableTable();
354:                {
355:                    Row row = new SimpleRow(2);
356:                    row.set(0, new Integer(3));
357:                    row.set(1, "three");
358:                    tranTable.addRow(row);
359:                }
360:                tranTable.rollback();
361:                assertEquals(2, _externalTable.getRowCount());
362:
363:                _externalTable.remount();
364:                assertEquals(2, _externalTable.getRowCount());
365:
366:                RowIterator iter = _externalTable.getRowIterator(true);
367:                assertNotNull(iter);
368:                assertFalse(iter.hasPrevious());
369:
370:                assertTrue(iter.hasNext());
371:                assertNotNull(iter.next());
372:                assertNotNull(iter.current());
373:                assertTrue(iter.hasNext());
374:                assertNotNull(iter.next());
375:                assertNotNull(iter.current());
376:                assertFalse(iter.hasNext());
377:                {
378:                    Row row = new SimpleRow(2);
379:                    row.set(0, new Integer(3));
380:                    row.set(1, "three");
381:                    tranTable.addRow(row);
382:                }
383:                tranTable.commit();
384:                assertEquals(3, _externalTable.getRowCount());
385:
386:                iter = _externalTable.getRowIterator(true);
387:                assertNotNull(iter);
388:                assertFalse(iter.hasPrevious());
389:
390:                assertTrue(iter.hasNext());
391:                assertNotNull(iter.next());
392:                assertNotNull(iter.current());
393:
394:                assertTrue(iter.hasNext());
395:                assertNotNull(iter.next());
396:                assertNotNull(iter.current());
397:
398:                assertTrue(iter.hasNext());
399:                assertNotNull(iter.next());
400:                assertNotNull(iter.current());
401:
402:                assertFalse(iter.hasNext());
403:
404:                _externalTable.shutdown(); // try again
405:                _table.shutdown();
406:                _externalTable.rollback();
407:                _externalTable = null;
408:            }
409:
410:            public void testRemount() throws Exception {
411:                testAddRow();
412:                _db.addTable(_externalTable);
413:                ((ExternalTable) _externalTable).remount();
414:
415:                RowIterator iter = _externalTable.getRowIterator(true);
416:                assertNotNull(iter);
417:                assertTrue(iter.hasNext());
418:                assertNotNull(iter.next());
419:                assertTrue(iter.hasNext());
420:                assertNotNull(iter.next());
421:                assertTrue(!iter.hasNext());
422:
423:                _table.truncate();
424:                _table.shutdown();
425:
426:                RemountCommand cmd = new RemountCommand();
427:                cmd.setTable(new TableIdentifier(_externalTable.getName()));
428:                cmd.execute(_db);
429:                iter = _externalTable.getRowIterator(true);
430:                assertNotNull(iter);
431:                assertTrue(!iter.hasNext());
432:
433:            }
434:
435:            public void testTruncate() throws Exception {
436:                createExternalTable("FOO");
437:                _externalTable.truncate();
438:                _externalTable.apply(); // does nothing now
439:                addRow();
440:
441:                RowIterator iter = _externalTable.getRowIterator(true);
442:                assertNotNull(iter);
443:                assertFalse(iter.hasPrevious());
444:
445:                assertTrue(iter.hasNext());
446:                assertNotNull(iter.next());
447:                assertNotNull(iter.current());
448:                assertTrue(iter.hasNext());
449:                assertNotNull(iter.next());
450:                assertNotNull(iter.current());
451:                assertFalse(iter.hasNext());
452:                _externalTable.truncate();
453:
454:                iter = _externalTable.getRowIterator(true);
455:                assertNotNull(iter);
456:                assertFalse(iter.hasPrevious());
457:                assertFalse(iter.hasNext());
458:                assertNull(_externalTable.getRow(1));
459:
460:                addRow();
461:                iter = _externalTable.getRowIterator(true);
462:                assertTrue(iter.hasNext());
463:                assertNotNull(iter.next());
464:                assertNotNull(iter.current());
465:                assertTrue(iter.hasNext());
466:                assertNotNull(iter.next());
467:                assertNotNull(iter.current());
468:                assertFalse(iter.hasNext());
469:            }
470:
471:            public void testTableWithWhere() throws Exception {
472:                createExternalTable("FOO", "ID = 1");
473:
474:                RowIterator iter = _externalTable.getRowIterator(true);
475:                assertNotNull(iter);
476:                assertFalse(iter.hasPrevious());
477:
478:                assertTrue(iter.hasNext());
479:                assertNotNull(iter.next());
480:                assertNotNull(iter.current());
481:                assertFalse(iter.hasNext());
482:            }
483:
484:            public void testTableWithWOrderBy() throws Exception {
485:                createExternalTable("FOO", "ID > 0", "ID,NAME");
486:                _externalTable.truncate();
487:                {
488:                    Row row = new SimpleRow(2);
489:                    row.set(0, new Integer(2));
490:                    row.set(1, "two");
491:                    _externalTable.addRow(row);
492:                }
493:                {
494:                    Row row = new SimpleRow(2);
495:                    row.set(0, new Integer(1));
496:                    row.set(1, "one");
497:                    _externalTable.addRow(row);
498:                }
499:                {
500:                    Row row = new SimpleRow(2);
501:                    row.set(0, new Integer(2));
502:                    row.set(1, "aaa");
503:                    _externalTable.addRow(row);
504:                }
505:
506:                _externalTable.commit();
507:
508:                RowIterator iter = _externalTable.getRowIterator(true);
509:                assertNotNull(iter);
510:                assertFalse(iter.hasPrevious());
511:
512:                assertTrue(iter.hasNext());
513:                Row row = iter.next();
514:                assertEquals(new Integer(2), row.get(0));
515:                assertEquals("two", row.get(1));
516:
517:                assertTrue(iter.hasNext());
518:                row = iter.next();
519:                assertEquals(new Integer(1), row.get(0));
520:                assertEquals("one", row.get(1));
521:
522:                assertTrue(iter.hasNext());
523:                row = iter.next();
524:                assertEquals(new Integer(2), row.get(0));
525:                assertEquals("aaa", row.get(1));
526:
527:                assertFalse(iter.hasNext());
528:            }
529:
530:            public void testHasColumn() throws Exception {
531:                createExternalTable("FOO");
532:                ColumnIdentifier id = new ColumnIdentifier("ID");
533:
534:                assertTrue("Should have column", _externalTable.hasColumn(id));
535:                id.setTableIdentifier(new TableIdentifier("FOO"));
536:                assertTrue("Should have column", _externalTable.hasColumn(id));
537:
538:                id.setTableIdentifier(new TableIdentifier("BOGUS"));
539:                assertTrue("Should not have column", !_externalTable
540:                        .hasColumn(id));
541:            }
542:
543:            public void testInvalidPropertyKey() throws Exception {
544:                Properties badProps = new Properties();
545:                badProps.put(ExternalTable.PROP_LOADTYPE, "remote");
546:                badProps.put("UNKNOWN_PROPERTY", Boolean.TRUE);
547:                ExternalTableFactory factory = new ExternalTableFactory();
548:                try {
549:                    factory.createTable(_db, "BadTable", badProps,
550:                            new ArrayList());
551:                    fail("Expected AxionException due to unrecognized property name 'UNKNOWN_PROPERTY'");
552:                } catch (AxionException expected) {
553:                    // Expected AxionException due to unrecognized property name.
554:                }
555:            }
556:
557:            public void testMissingRequiredProperty() throws Exception {
558:                Properties badProps = new Properties();
559:                ExternalTableFactory factory = new ExternalTableFactory();
560:                try {
561:                    factory.createTable(_db, "BAD_TABLE", badProps,
562:                            new ArrayList());
563:                    fail("Expected AxionException");
564:                } catch (AxionException expected) {
565:                    // expected
566:                }
567:            }
568:
569:            public void testMissingDriverProperty() throws Exception {
570:                // Null driver test
571:                try {
572:                    Properties props = new Properties();
573:                    props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
574:                            "jdbc:axiondb:testdb2:testdb2");
575:                    props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
576:                            "ignored");
577:                    props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
578:                            "ignored");
579:                    _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
580:
581:                    fail("Expected AxionException due to null driver class");
582:                } catch (Exception expected) {
583:                    // Expected AxionException due to unrecognized property name.
584:
585:                }
586:            }
587:
588:            public void testBadLoaderType() throws Exception {
589:                Properties props = new Properties();
590:                props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
591:                        "org.axiondb.jdbc.AxionDriver");
592:                props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
593:                        "jdbc:axiondb:testdb2:testdb2");
594:                props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
595:                        "ignored");
596:                props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
597:                        "ignored");
598:                _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
599:
600:                ExternalTableFactory factory = new ExternalTableFactory();
601:                props = new Properties();
602:
603:                try {
604:                    factory.assertValidProperty(props);
605:                    fail("Expected Exception");
606:                } catch (Exception e) {
607:                    // excepted
608:                }
609:
610:                try {
611:                    factory.assertValidProperty(null);
612:                    fail("Expected Exception");
613:                } catch (Exception e) {
614:                    // excepted
615:                }
616:
617:                props.setProperty(ExternalTable.PROP_DB, "axiondb");
618:
619:                try {
620:                    factory.assertValidProperty(props);
621:                    fail("Expected Exception");
622:                } catch (Exception e) {
623:                    // excepted
624:                }
625:
626:                props.setProperty(ExternalTable.PROP_LOADTYPE, "BOGUS");
627:                props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
628:                List columns = new ArrayList(2);
629:                columns.add(new Column("ID", new IntegerType()));
630:                columns.add(new Column("NAME", new CharacterVaryingType(10)));
631:
632:                try {
633:                    _externalTable = (ExternalDatabaseTable) factory
634:                            .createTable(_db, "BOGUS");
635:                    fail("Expected Exception");
636:                } catch (Exception e) {
637:                    // excepted
638:                }
639:
640:                try {
641:                    _externalTable = (ExternalDatabaseTable) factory
642:                            .createTable(_db, "BOGUS", props, columns);
643:                    fail("Expected Exception");
644:                } catch (Exception e) {
645:                    // excepted
646:                }
647:            }
648:
649:            public void testBadDriverClass() throws Exception {
650:                // bad driver class
651:                try {
652:                    Properties props = new Properties();
653:                    props.setProperty(
654:                            ExternalConnectionProvider.PROP_DRIVERCLASS,
655:                            "org.axiondb.AxionDriver");
656:                    props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
657:                            "jdbc:axiondb:testdb2:testdb2");
658:                    props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
659:                            "ignored");
660:                    props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
661:                            "ignored");
662:                    _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
663:
664:                    props = new Properties();
665:                    props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
666:                    props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
667:                    props.setProperty(ExternalTable.PROP_REMOTETABLE, "foo24");
668:                    List columns = new ArrayList(2);
669:                    columns.add(new Column("ID", new IntegerType()));
670:                    columns
671:                            .add(new Column("NAME",
672:                                    new CharacterVaryingType(10)));
673:
674:                    ExternalTableFactory factory = new ExternalTableFactory();
675:                    _externalTable = (ExternalDatabaseTable) factory
676:                            .createTable(_db, "FOO24", props, columns);
677:                    fail("Expected AxionException due to bad driver class");
678:                } catch (Exception expected) {
679:                    // Expected AxionException due to unrecognized property name.
680:                }
681:            }
682:
683:            public void testBadUrlProperty() throws Exception {
684:                // bad url
685:                try {
686:                    Properties props = new Properties();
687:                    props.setProperty(
688:                            ExternalConnectionProvider.PROP_DRIVERCLASS,
689:                            "org.axiondb.jdbc.AxionDriver");
690:                    props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
691:                            "jdbc");
692:                    props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
693:                            "ignored");
694:                    props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
695:                            "ignored");
696:                    _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
697:
698:                    props = new Properties();
699:                    props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
700:                    props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
701:                    props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
702:                    List columns = new ArrayList(2);
703:                    columns.add(new Column("ID", new IntegerType()));
704:                    columns
705:                            .add(new Column("NAME",
706:                                    new CharacterVaryingType(10)));
707:
708:                    ExternalTableFactory factory = new ExternalTableFactory();
709:                    _externalTable = (ExternalDatabaseTable) factory
710:                            .createTable(_db, "FOO24", props, columns);
711:                    fail("Expected AxionException due to bad driver class");
712:                } catch (Exception expected) {
713:                    // Expected AxionException due to unrecognized property name.
714:                }
715:            }
716:
717:            public void testAddRow() throws Exception {
718:                createExternalTable("FOO");
719:            }
720:
721:            public void testNoNewColumnsAfterRowsAdded() throws Exception {
722:                createExternalTable("FOO");
723:                try {
724:                    _externalTable.addColumn(new Column("NAMETWO",
725:                            new CharacterVaryingType(10)));
726:                    fail("Expected AxionException");
727:                } catch (AxionException e) {
728:                    // expected
729:                }
730:            }
731:
732:            public void testGetColumnByIndex() throws Exception {
733:                createExternalTable("FOO");
734:                assertEquals("ID", _externalTable.getColumn(0).getName());
735:                assertEquals("NAME", _externalTable.getColumn(1).getName());
736:            }
737:
738:            public void testGetColumnByIndexBadIndex() throws Exception {
739:                createExternalTable("FOO");
740:                try {
741:                    _externalTable.getColumn(-1);
742:                    fail("Expected IndexOutOfBoundsException");
743:                } catch (IndexOutOfBoundsException e) {
744:                    // expected
745:                }
746:
747:                try {
748:                    _externalTable.getColumn(3);
749:                    fail("Expected IndexOutOfBoundsException");
750:                } catch (IndexOutOfBoundsException e) {
751:                    // expected
752:                }
753:            }
754:
755:            public void testGetColumnByName() throws Exception {
756:                createExternalTable("FOO");
757:                assertTrue(_externalTable.getColumn("ID").getDataType() instanceof  IntegerType);
758:                assertTrue(_externalTable.getColumn("NAME").getDataType() instanceof  CharacterVaryingType);
759:            }
760:
761:            public void testGetColumnByNameBadName() throws Exception {
762:                createExternalTable("FOO");
763:                assertNull(_externalTable.getColumn("FOO"));
764:                assertNull(_externalTable.getColumn("ID1"));
765:            }
766:
767:            public void testDataTypes() throws Exception {
768:                Properties props = new Properties();
769:                props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
770:                        "org.axiondb.jdbc.AxionDriver");
771:                props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
772:                        "jdbc:axiondb:testdb2:testdb2");
773:                props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
774:                        "ignored");
775:                props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
776:                        "ignored");
777:                _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
778:
779:                props = new Properties();
780:                props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
781:                props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
782:                props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
783:
784:                ExternalTableLoader loader = new ExternalDatabaseTableLoader();
785:                _externalTable = (ExternalDatabaseTable) loader.createTable(
786:                        _db, "FOO");
787:
788:                _externalTable.addColumn(new Column("ID", new IntegerType()));
789:                _externalTable.addColumn(new Column("NAME",
790:                        new CharacterVaryingType(30)));
791:
792:                _externalTable.loadExternalTable(props);
793:
794:                Object[][] values = new Object[][] {
795:                        new Object[] { new Integer(17), new Integer(0),
796:                                new Integer(5575), null },
797:                        new Object[] { "", "A String", "Another String", null }, };
798:
799:                Random random = new Random();
800:                int numRows = 7;
801:
802:                for (int i = 0; i < numRows; i++) {
803:                    Row row = new SimpleRow(_externalTable.getColumnCount());
804:                    for (int j = 0; j < _externalTable.getColumnCount(); j++) {
805:                        row.set(j, values[j][random.nextInt(values[j].length)]);
806:                    }
807:                    _externalTable.addRow(row);
808:                }
809:                _externalTable.commit();
810:
811:                RowIterator iter = _externalTable.getRowIterator(true);
812:                assertNotNull(iter);
813:                for (int i = 0; i < numRows; i++) {
814:                    assertTrue(iter.hasNext());
815:                    assertNotNull(iter.next());
816:                }
817:                assertTrue(!iter.hasNext());
818:            }
819:
820:            public void testRemoteUpdate() throws Exception {
821:                Properties props = new Properties();
822:                props.setProperty(ExternalConnectionProvider.PROP_DRIVERCLASS,
823:                        "org.axiondb.jdbc.AxionDriver");
824:                props.setProperty(ExternalConnectionProvider.PROP_JDBCURL,
825:                        "jdbc:axiondb:testdb2:testdb2");
826:                props.setProperty(ExternalConnectionProvider.PROP_USERNAME,
827:                        "ignored");
828:                props.setProperty(ExternalConnectionProvider.PROP_PASSWORD,
829:                        "ignored");
830:                _db.createDatabaseLink(new DatabaseLink("AXIONDB", props));
831:
832:                props = new Properties();
833:                props.setProperty(ExternalTable.PROP_DB, "AXIONDB");
834:                props.setProperty(ExternalTable.PROP_REMOTETABLE, "FOO24");
835:                props.setProperty(ExternalTable.PROP_LOADTYPE, "remote");
836:
837:                ExternalTableLoader loader = new ExternalDatabaseTableLoader();
838:                _externalTable = (ExternalDatabaseTable) loader.createTable(
839:                        _db, "FOO");
840:
841:                _externalTable.addColumn(new Column("ID", new IntegerType()));
842:                _externalTable.addColumn(new Column("NAME",
843:                        new CharacterVaryingType(20)));
844:
845:                _externalTable.loadExternalTable(props);
846:
847:                final String stringTemplate = "My ID is ";
848:                Object[][] values = new Object[][] {
849:                        new Object[] { new Integer(1), new Integer(2),
850:                                new Integer(46), new Integer(100) },
851:                        new Object[] { null, null, null, null } };
852:
853:                Random random = new Random();
854:                int numRows = 7;
855:
856:                for (int i = 0; i < numRows; i++) {
857:                    Row row = new SimpleRow(_externalTable.getColumnCount());
858:                    for (int j = 0; j < _externalTable.getColumnCount(); j++) {
859:                        row.set(j, values[j][random.nextInt(values[j].length)]);
860:                    }
861:                    _externalTable.addRow(row);
862:                }
863:                _externalTable.commit();
864:
865:                RowIterator iter = _externalTable.getRowIterator(true);
866:                assertNotNull(iter);
867:                for (int i = 0; i < numRows; i++) {
868:                    assertTrue(iter.hasNext());
869:                    assertNotNull(iter.next());
870:                }
871:                assertTrue(!iter.hasNext());
872:
873:                RowIterator modIter = _externalTable.getRowIterator();
874:                while (modIter.hasNext()) {
875:                    Row oldRow = modIter.next();
876:                    Row newRow = new SimpleRow(_externalTable.getColumnCount());
877:                    newRow.set(0, oldRow.get(0));
878:                    newRow.set(1, stringTemplate + oldRow.get(0));
879:
880:                    _externalTable.updateRow(oldRow, newRow);
881:                }
882:                _externalTable.commit();
883:
884:                iter = _externalTable.getRowIterator(true);
885:                assertNotNull(iter);
886:                for (int i = 0; i < numRows; i++) {
887:                    assertTrue(iter.hasNext());
888:                    Row row = iter.next();
889:                    assertNotNull(row);
890:                    assertEquals(stringTemplate + row.get(0), row.get(1));
891:                }
892:                assertTrue(!iter.hasNext());
893:            }
894:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.