Source Code Cross Referenced for TestDbQueryManager.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » database » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.database 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003:         * Distributed under the terms of either:
0004:         * - the common development and distribution license (CDDL), v1.0; or
0005:         * - the GNU Lesser General Public License, v2.1 or later
0006:         * $Id: TestDbQueryManager.java 3784 2007-06-11 16:44:35Z gbevin $
0007:         */
0008:        package com.uwyn.rife.database;
0009:
0010:        import com.uwyn.rife.database.queries.*;
0011:
0012:        import com.uwyn.rife.database.exceptions.DatabaseException;
0013:        import com.uwyn.rife.template.Template;
0014:        import com.uwyn.rife.template.TemplateFactory;
0015:        import com.uwyn.rife.tools.ExceptionUtils;
0016:        import com.uwyn.rife.tools.FileUtils;
0017:        import com.uwyn.rife.tools.InnerClassException;
0018:        import com.uwyn.rife.tools.InputStreamUser;
0019:        import com.uwyn.rife.tools.ReaderUser;
0020:        import com.uwyn.rife.tools.exceptions.ControlFlowRuntimeException;
0021:        import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
0022:        import java.io.InputStream;
0023:        import java.io.Reader;
0024:        import java.io.UnsupportedEncodingException;
0025:        import java.sql.Blob;
0026:        import java.sql.ResultSet;
0027:        import java.sql.SQLException;
0028:        import java.util.Arrays;
0029:        import java.util.Calendar;
0030:        import java.util.List;
0031:        import junit.framework.TestCase;
0032:
0033:        public class TestDbQueryManager extends TestCase {
0034:            private Datasource mDatasource = null;
0035:
0036:            public TestDbQueryManager(Datasource datasource,
0037:                    String datasourceName, String name) {
0038:                super (name);
0039:                mDatasource = datasource;
0040:            }
0041:
0042:            public void setUp() {
0043:            }
0044:
0045:            public void tearDown() {
0046:                try {
0047:                    DbConnection connection = mDatasource.getConnection();
0048:
0049:                    // drop the test table
0050:                    DbStatement statement = connection.createStatement();
0051:                    try {
0052:                        try {
0053:                            statement.executeUpdate(new DropTable(mDatasource)
0054:                                    .table("tbltest"));
0055:                        } catch (DatabaseException e) { /* don't do anything */
0056:                        }
0057:                    } finally {
0058:                        try {
0059:                            statement.close();
0060:                        } catch (DatabaseException e) { /* don't do anything */
0061:                        }
0062:                    }
0063:
0064:                    connection.close();
0065:                } catch (DatabaseException e) {
0066:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0067:                }
0068:            }
0069:
0070:            public void testIllegalInstantiation() {
0071:                try {
0072:                    new DbQueryManager(null);
0073:                    fail();
0074:                } catch (IllegalArgumentException e) {
0075:                    assertTrue(true);
0076:                }
0077:            }
0078:
0079:            public void testInstantiation() {
0080:                DbQueryManager manager = new DbQueryManager(mDatasource);
0081:                assertNotNull(manager);
0082:                assertSame(manager.getDatasource(), mDatasource);
0083:            }
0084:
0085:            public void testIllegalExecuteUpdateSql() {
0086:                DbQueryManager manager = new DbQueryManager(mDatasource);
0087:                try {
0088:                    manager.executeUpdate((String) null);
0089:                    fail();
0090:                } catch (IllegalArgumentException e) {
0091:                    assertTrue(true);
0092:                }
0093:            }
0094:
0095:            public void testTransactionUserCommit() {
0096:                final DbQueryManager manager = new DbQueryManager(mDatasource);
0097:                String create = "CREATE TABLE tbltest (id INTEGER, stringcol VARCHAR(255))";
0098:                manager.executeUpdate(create);
0099:                try {
0100:                    final String insert = "INSERT INTO tbltest VALUES (232, 'somestring')";
0101:                    final Select select = new Select(mDatasource).from(
0102:                            "tbltest").field("count(*)");
0103:
0104:                    if (manager.getConnection().supportsTransactions()
0105:                            && !mDatasource.getAliasedDriver().equals(
0106:                                    "com.mysql.jdbc.Driver")
0107:                            && !mDatasource.getAliasedDriver().equals(
0108:                                    "org.apache.derby.jdbc.EmbeddedDriver")
0109:                            && !mDatasource.getAliasedDriver().equals(
0110:                                    "in.co.daffodil.db.jdbc.DaffodilDBDriver")) {
0111:                        manager
0112:                                .inTransaction(new DbTransactionUserWithoutResult() {
0113:                                    public void useTransactionWithoutResult()
0114:                                            throws InnerClassException {
0115:                                        manager.executeUpdate(insert);
0116:                                        assertEquals(1, manager
0117:                                                .executeGetFirstInt(select));
0118:
0119:                                        manager
0120:                                                .inTransaction(new DbTransactionUserWithoutResult() {
0121:                                                    public void useTransactionWithoutResult()
0122:                                                            throws InnerClassException {
0123:                                                        manager
0124:                                                                .inTransaction(new DbTransactionUserWithoutResult() {
0125:                                                                    public void useTransactionWithoutResult()
0126:                                                                            throws InnerClassException {
0127:                                                                        manager
0128:                                                                                .executeUpdate(insert);
0129:                                                                        assertEquals(
0130:                                                                                2,
0131:                                                                                manager
0132:                                                                                        .executeGetFirstInt(select));
0133:                                                                    }
0134:                                                                });
0135:
0136:                                                        manager
0137:                                                                .executeUpdate(insert);
0138:                                                        assertEquals(
0139:                                                                3,
0140:                                                                manager
0141:                                                                        .executeGetFirstInt(select));
0142:                                                    }
0143:                                                });
0144:
0145:                                        assertEquals(3, manager
0146:                                                .executeGetFirstInt(select));
0147:
0148:                                        // ensure that the transaction isn't committed yet
0149:                                        // since this should only happen after the last transaction user
0150:                                        Thread other_thread = new Thread() {
0151:                                            public void run() {
0152:                                                // HsqlDB only has read-uncommitted transactionisolation
0153:                                                if ("org.hsqldb.jdbcDriver"
0154:                                                        .equals(mDatasource
0155:                                                                .getAliasedDriver())) {
0156:                                                    assertEquals(
0157:                                                            3,
0158:                                                            manager
0159:                                                                    .executeGetFirstInt(select));
0160:                                                }
0161:                                                // all the rest should be fully isolated
0162:                                                else {
0163:                                                    assertEquals(
0164:                                                            0,
0165:                                                            manager
0166:                                                                    .executeGetFirstInt(select));
0167:                                                }
0168:
0169:                                                synchronized (this ) {
0170:                                                    this .notifyAll();
0171:                                                }
0172:                                            }
0173:                                        };
0174:
0175:                                        other_thread.start();
0176:                                        while (other_thread.isAlive()) {
0177:                                            synchronized (other_thread) {
0178:                                                try {
0179:                                                    other_thread.wait();
0180:                                                } catch (InterruptedException e) {
0181:                                                }
0182:                                            }
0183:                                        }
0184:                                    }
0185:                                });
0186:                        assertEquals(3, manager.executeGetFirstInt(select));
0187:                    }
0188:                } catch (DatabaseException e) {
0189:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0190:                }
0191:            }
0192:
0193:            public void testTransactionUserRecommendedRollback() {
0194:                final DbQueryManager manager = new DbQueryManager(mDatasource);
0195:                String create = "CREATE TABLE tbltest (id INTEGER, stringcol VARCHAR(255))";
0196:                manager.executeUpdate(create);
0197:                try {
0198:                    final String insert = "INSERT INTO tbltest VALUES (232, 'somestring')";
0199:                    final Select select = new Select(mDatasource).from(
0200:                            "tbltest").field("count(*)");
0201:
0202:                    if (manager.getConnection().supportsTransactions()
0203:                            && false == mDatasource.getAliasedDriver().equals(
0204:                                    "com.mysql.jdbc.Driver")) {
0205:                        manager
0206:                                .inTransaction(new DbTransactionUserWithoutResult() {
0207:                                    public void useTransactionWithoutResult()
0208:                                            throws InnerClassException {
0209:                                        manager.executeUpdate(insert);
0210:                                        assertEquals(1, manager
0211:                                                .executeGetFirstInt(select));
0212:
0213:                                        manager
0214:                                                .inTransaction(new DbTransactionUserWithoutResult() {
0215:                                                    public void useTransactionWithoutResult()
0216:                                                            throws InnerClassException {
0217:                                                        manager
0218:                                                                .inTransaction(new DbTransactionUserWithoutResult() {
0219:                                                                    public void useTransactionWithoutResult()
0220:                                                                            throws InnerClassException {
0221:                                                                        manager
0222:                                                                                .executeUpdate(insert);
0223:                                                                        rollback();
0224:                                                                    }
0225:                                                                });
0226:
0227:                                                        manager
0228:                                                                .executeUpdate(insert);
0229:                                                        fail();
0230:                                                    }
0231:                                                });
0232:
0233:                                        fail();
0234:                                    }
0235:                                });
0236:                        assertEquals(0, manager.executeGetFirstInt(select));
0237:                    }
0238:                } catch (DatabaseException e) {
0239:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0240:                }
0241:            }
0242:
0243:            public void testTransactionUserRuntimeException() {
0244:                final DbQueryManager manager = new DbQueryManager(mDatasource);
0245:                String create = "CREATE TABLE tbltest (id INTEGER, stringcol VARCHAR(255))";
0246:                manager.executeUpdate(create);
0247:                try {
0248:                    final String insert = "INSERT INTO tbltest VALUES (232, 'somestring')";
0249:                    final Select select = new Select(mDatasource).from(
0250:                            "tbltest").field("count(*)");
0251:
0252:                    if (manager.getConnection().supportsTransactions()
0253:                            && false == mDatasource.getAliasedDriver().equals(
0254:                                    "com.mysql.jdbc.Driver")) {
0255:                        try {
0256:                            manager
0257:                                    .inTransaction(new DbTransactionUserWithoutResult() {
0258:                                        public void useTransactionWithoutResult()
0259:                                                throws InnerClassException {
0260:                                            manager.executeUpdate(insert);
0261:                                            assertEquals(1, manager
0262:                                                    .executeGetFirstInt(select));
0263:
0264:                                            manager
0265:                                                    .inTransaction(new DbTransactionUserWithoutResult() {
0266:                                                        public void useTransactionWithoutResult()
0267:                                                                throws InnerClassException {
0268:                                                            manager
0269:                                                                    .inTransaction(new DbTransactionUserWithoutResult() {
0270:                                                                        public void useTransactionWithoutResult()
0271:                                                                                throws InnerClassException {
0272:                                                                            manager
0273:                                                                                    .executeUpdate(insert);
0274:                                                                            throw new RuntimeException(
0275:                                                                                    "something happened");
0276:                                                                        }
0277:                                                                    });
0278:
0279:                                                            manager
0280:                                                                    .executeUpdate(insert);
0281:                                                            fail();
0282:                                                        }
0283:                                                    });
0284:
0285:                                            fail();
0286:                                        }
0287:                                    });
0288:
0289:                            fail();
0290:                        } catch (RuntimeException e) {
0291:                            assertEquals("something happened", e.getMessage());
0292:                        }
0293:
0294:                        assertEquals(0, manager.executeGetFirstInt(select));
0295:                    }
0296:                } catch (DatabaseException e) {
0297:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0298:                }
0299:            }
0300:
0301:            public void testTransactionUserRegularRollback() {
0302:                final DbQueryManager manager = new DbQueryManager(mDatasource);
0303:                String create = "CREATE TABLE tbltest (id INTEGER, stringcol VARCHAR(255))";
0304:                manager.executeUpdate(create);
0305:                try {
0306:                    final String insert = "INSERT INTO tbltest VALUES (232, 'somestring')";
0307:                    final Select select = new Select(mDatasource).from(
0308:                            "tbltest").field("count(*)");
0309:
0310:                    if (manager.getConnection().supportsTransactions()
0311:                            && false == mDatasource.getAliasedDriver().equals(
0312:                                    "com.mysql.jdbc.Driver")) {
0313:                        manager
0314:                                .inTransaction(new DbTransactionUserWithoutResult() {
0315:                                    public void useTransactionWithoutResult()
0316:                                            throws InnerClassException {
0317:                                        manager.executeUpdate(insert);
0318:                                        assertEquals(1, manager
0319:                                                .executeGetFirstInt(select));
0320:
0321:                                        manager.getConnection().rollback();
0322:                                    }
0323:                                });
0324:                        assertEquals(0, manager.executeGetFirstInt(select));
0325:                    }
0326:                } catch (DatabaseException e) {
0327:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0328:                }
0329:            }
0330:
0331:            public void testTransactionUserCommittingException() {
0332:                final DbQueryManager manager = new DbQueryManager(mDatasource);
0333:                String create = "CREATE TABLE tbltest (id INTEGER, stringcol VARCHAR(255))";
0334:                manager.executeUpdate(create);
0335:                try {
0336:                    final String insert = "INSERT INTO tbltest VALUES (232, 'somestring')";
0337:                    final Select select = new Select(mDatasource).from(
0338:                            "tbltest").field("count(*)");
0339:
0340:                    if (manager.getConnection().supportsTransactions()
0341:                            && false == mDatasource.getAliasedDriver().equals(
0342:                                    "com.mysql.jdbc.Driver")) {
0343:                        try {
0344:                            manager
0345:                                    .inTransaction(new DbTransactionUserWithoutResult() {
0346:                                        public void useTransactionWithoutResult()
0347:                                                throws InnerClassException {
0348:                                            manager.executeUpdate(insert);
0349:                                            assertEquals(1, manager
0350:                                                    .executeGetFirstInt(select));
0351:
0352:                                            manager
0353:                                                    .inTransaction(new DbTransactionUserWithoutResult() {
0354:                                                        public void useTransactionWithoutResult()
0355:                                                                throws InnerClassException {
0356:                                                            manager
0357:                                                                    .inTransaction(new DbTransactionUserWithoutResult() {
0358:                                                                        public void useTransactionWithoutResult()
0359:                                                                                throws InnerClassException {
0360:                                                                            manager
0361:                                                                                    .executeUpdate(insert);
0362:                                                                            throw new TestComittingRuntimeException(
0363:                                                                                    "something happened");
0364:                                                                        }
0365:                                                                    });
0366:
0367:                                                            manager
0368:                                                                    .executeUpdate(insert);
0369:                                                            fail();
0370:                                                        }
0371:                                                    });
0372:
0373:                                            fail();
0374:                                        }
0375:                                    });
0376:
0377:                            fail();
0378:                        } catch (RuntimeException e) {
0379:                            assertEquals("something happened", e.getMessage());
0380:                        }
0381:
0382:                        assertEquals(2, manager.executeGetFirstInt(select));
0383:                    }
0384:                } catch (DatabaseException e) {
0385:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0386:                }
0387:            }
0388:
0389:            public class TestComittingRuntimeException extends RuntimeException
0390:                    implements  ControlFlowRuntimeException {
0391:                public TestComittingRuntimeException(String message) {
0392:                    super (message);
0393:                }
0394:            }
0395:
0396:            public void testExecuteUpdateSqlSuccess() {
0397:                DbQueryManager manager = new DbQueryManager(mDatasource);
0398:                try {
0399:                    CreateTable create_query = new CreateTable(mDatasource);
0400:                    create_query.table("tbltest").column("column1",
0401:                            String.class, 50);
0402:                    manager.executeUpdate(create_query.getSql());
0403:
0404:                    Insert insert_query = new Insert(mDatasource);
0405:                    insert_query.into("tbltest").field("column1", "sometext");
0406:                    assertEquals(1, manager
0407:                            .executeUpdate(insert_query.getSql()));
0408:                } catch (DatabaseException e) {
0409:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0410:                }
0411:            }
0412:
0413:            public void testIllegalExecuteUpdateBuilder() {
0414:                DbQueryManager manager = new DbQueryManager(mDatasource);
0415:                try {
0416:                    manager.executeUpdate((Query) null);
0417:                    fail();
0418:                } catch (IllegalArgumentException e) {
0419:                    assertTrue(true);
0420:                }
0421:            }
0422:
0423:            public void testExecuteUpdateBuilderSuccess() {
0424:                DbQueryManager manager = new DbQueryManager(mDatasource);
0425:                try {
0426:                    CreateTable create_query = new CreateTable(mDatasource);
0427:                    create_query.table("tbltest").column("column1",
0428:                            String.class, 50);
0429:                    manager.executeUpdate(create_query);
0430:
0431:                    Insert insert_query = new Insert(mDatasource);
0432:                    insert_query.into("tbltest").field("column1", "sometext");
0433:                    assertEquals(1, manager.executeUpdate(insert_query));
0434:                } catch (DatabaseException e) {
0435:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0436:                }
0437:            }
0438:
0439:            public void testExecuteUpdateBuilderError() {
0440:                DbQueryManager manager = new DbQueryManager(mDatasource);
0441:                try {
0442:                    CreateTable create_query = new CreateTable(mDatasource);
0443:                    create_query.table("tbltest").column("column1",
0444:                            String.class, 50);
0445:                    manager.executeUpdate(create_query);
0446:
0447:                    Insert insert_query = new Insert(mDatasource);
0448:                    insert_query.into("tbltest").field("column2", "sometext");
0449:                    try {
0450:                        manager.executeUpdate(insert_query);
0451:                        fail();
0452:                    } catch (DatabaseException e) {
0453:                        assertTrue(true);
0454:                    }
0455:                } catch (DatabaseException e) {
0456:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0457:                }
0458:            }
0459:
0460:            public void testIllegalExecuteUpdateHandler() {
0461:                DbQueryManager manager = new DbQueryManager(mDatasource);
0462:                try {
0463:                    manager.executeUpdate(null, null);
0464:                    fail();
0465:                } catch (IllegalArgumentException e) {
0466:                    assertTrue(true);
0467:                }
0468:            }
0469:
0470:            public void testExecuteUpdateHandler() {
0471:                DbQueryManager manager = new DbQueryManager(mDatasource);
0472:                try {
0473:                    CreateTable create_query = new CreateTable(mDatasource);
0474:                    create_query.table("tbltest").column("name", String.class,
0475:                            50);
0476:                    manager.executeUpdate(create_query);
0477:
0478:                    Insert insert_query = new Insert(mDatasource);
0479:                    insert_query.into("tbltest").fieldParameter("name");
0480:                    assertEquals(1, manager.executeUpdate(insert_query,
0481:                            new DbPreparedStatementHandler() {
0482:                                public void setParameters(
0483:                                        DbPreparedStatement statement) {
0484:                                    statement.setString("name", "me");
0485:                                }
0486:                            }));
0487:
0488:                    assertEquals("me", manager
0489:                            .executeGetFirstString(new Select(mDatasource)
0490:                                    .from("tbltest")));
0491:
0492:                    manager.executeUpdate(new Delete(mDatasource)
0493:                            .from("tbltest"));
0494:
0495:                    insert_query = new Insert(mDatasource);
0496:                    insert_query.into("tbltest").field("name", "me2");
0497:                    assertEquals(1, manager.executeUpdate(insert_query, null));
0498:
0499:                    assertEquals("me2", manager
0500:                            .executeGetFirstString(new Select(mDatasource)
0501:                                    .from("tbltest")));
0502:                } catch (DatabaseException e) {
0503:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0504:                }
0505:            }
0506:
0507:            public void testIllegalExecuteHasResultRows() {
0508:                DbQueryManager manager = new DbQueryManager(mDatasource);
0509:                try {
0510:                    manager.executeHasResultRows((Select) null);
0511:                    fail();
0512:                } catch (IllegalArgumentException e) {
0513:                    assertTrue(true);
0514:                }
0515:            }
0516:
0517:            public void testExecuteReadQueryString() {
0518:                DbQueryManager manager = new DbQueryManager(mDatasource);
0519:                try {
0520:                    CreateTable create_query = new CreateTable(mDatasource);
0521:                    create_query.table("tbltest").column("name", String.class,
0522:                            50);
0523:                    manager.executeUpdate(create_query);
0524:
0525:                    manager.executeUpdate(new Insert(mDatasource).into(
0526:                            "tbltest").field("name", "me"));
0527:
0528:                    assertTrue(manager
0529:                            .executeHasResultRows(new ReadQueryString(
0530:                                    "SELECT name FROM tbltest WHERE name = 'me'")));
0531:
0532:                    assertTrue(manager.executeHasResultRows(
0533:                            new ReadQueryString(
0534:                                    "SELECT name FROM tbltest WHERE name = ?"),
0535:                            new DbPreparedStatementHandler() {
0536:                                public void setParameters(
0537:                                        DbPreparedStatement statement) {
0538:                                    statement.setString(1, "me");
0539:                                }
0540:                            }));
0541:
0542:                    manager.executeUpdate(new Delete(mDatasource)
0543:                            .from("tbltest"));
0544:
0545:                    assertFalse(manager
0546:                            .executeHasResultRows(new ReadQueryString(
0547:                                    "SELECT name FROM tbltest WHERE name = 'me'")));
0548:
0549:                    assertFalse(manager.executeHasResultRows(
0550:                            new ReadQueryString(
0551:                                    "SELECT name FROM tbltest WHERE name = ?"),
0552:                            new DbPreparedStatementHandler() {
0553:                                public void setParameters(
0554:                                        DbPreparedStatement statement) {
0555:                                    statement.setString(1, "me");
0556:                                }
0557:                            }));
0558:                } catch (DatabaseException e) {
0559:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0560:                }
0561:            }
0562:
0563:            public void testExecuteReadQueryTemplate() {
0564:                DbQueryManager manager = new DbQueryManager(mDatasource);
0565:                try {
0566:                    CreateTable create_query = new CreateTable(mDatasource);
0567:                    create_query.table("tbltest").column("name", String.class,
0568:                            50);
0569:                    manager.executeUpdate(create_query);
0570:
0571:                    manager.executeUpdate(new Insert(mDatasource).into(
0572:                            "tbltest").field("name", "me"));
0573:
0574:                    Template template1 = TemplateFactory.SQL
0575:                            .get("readquery_blocks");
0576:                    template1.setValue("name", template1.getEncoder().encode(
0577:                            "me"));
0578:                    assertTrue(manager
0579:                            .executeHasResultRows(new ReadQueryTemplate(
0580:                                    template1, "query1")));
0581:
0582:                    Template template2 = TemplateFactory.SQL
0583:                            .get("readquery_content");
0584:                    template2.setValue("name", template2.getEncoder().encode(
0585:                            "me"));
0586:                    assertTrue(manager
0587:                            .executeHasResultRows(new ReadQueryTemplate(
0588:                                    template2)));
0589:
0590:                    assertTrue(manager.executeHasResultRows(
0591:                            new ReadQueryTemplate(template1, "query2"),
0592:                            new DbPreparedStatementHandler() {
0593:                                public void setParameters(
0594:                                        DbPreparedStatement statement) {
0595:                                    statement.setString(1, "me");
0596:                                }
0597:                            }));
0598:
0599:                    manager.executeUpdate(new Delete(mDatasource)
0600:                            .from("tbltest"));
0601:
0602:                    assertFalse(manager
0603:                            .executeHasResultRows(new ReadQueryTemplate(
0604:                                    template1, "query1")));
0605:
0606:                    assertFalse(manager.executeHasResultRows(
0607:                            new ReadQueryTemplate(template1, "query2"),
0608:                            new DbPreparedStatementHandler() {
0609:                                public void setParameters(
0610:                                        DbPreparedStatement statement) {
0611:                                    statement.setString(1, "me");
0612:                                }
0613:                            }));
0614:                } catch (DatabaseException e) {
0615:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0616:                }
0617:            }
0618:
0619:            public void testExecuteHasResultRows() {
0620:                DbQueryManager manager = new DbQueryManager(mDatasource);
0621:                try {
0622:                    CreateTable create_query = new CreateTable(mDatasource);
0623:                    create_query.table("tbltest").column("name", String.class,
0624:                            50);
0625:                    manager.executeUpdate(create_query);
0626:
0627:                    manager.executeUpdate(new Insert(mDatasource).into(
0628:                            "tbltest").field("name", "me"));
0629:
0630:                    Select select_query = null;
0631:                    select_query = new Select(mDatasource);
0632:                    select_query.from("tbltest").field("name").where("name",
0633:                            "=", "me");
0634:                    assertTrue(manager.executeHasResultRows(select_query));
0635:
0636:                    select_query = new Select(mDatasource);
0637:                    select_query.from("tbltest").field("name").whereParameter(
0638:                            "name", "=");
0639:                    assertTrue(manager.executeHasResultRows(select_query,
0640:                            new DbPreparedStatementHandler() {
0641:                                public void setParameters(
0642:                                        DbPreparedStatement statement) {
0643:                                    statement.setString("name", "me");
0644:                                }
0645:                            }));
0646:
0647:                    manager.executeUpdate(new Delete(mDatasource)
0648:                            .from("tbltest"));
0649:
0650:                    select_query = new Select(mDatasource);
0651:                    select_query.from("tbltest").field("name").where("name",
0652:                            "=", "me");
0653:                    assertFalse(manager.executeHasResultRows(select_query));
0654:
0655:                    select_query = new Select(mDatasource);
0656:                    select_query.from("tbltest").field("name").whereParameter(
0657:                            "name", "=");
0658:                    assertFalse(manager.executeHasResultRows(select_query,
0659:                            new DbPreparedStatementHandler() {
0660:                                public void setParameters(
0661:                                        DbPreparedStatement statement) {
0662:                                    statement.setString("name", "me");
0663:                                }
0664:                            }));
0665:                } catch (DatabaseException e) {
0666:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0667:                }
0668:            }
0669:
0670:            public void testExecuteHasResultRowsConcludeErrors() {
0671:                DbQueryManager manager = new DbQueryManager(mDatasource);
0672:                try {
0673:                    CreateTable create_query = new CreateTable(mDatasource);
0674:                    create_query.table("tbltest").column("name", String.class,
0675:                            50);
0676:                    manager.executeUpdate(create_query);
0677:
0678:                    Select select_query = null;
0679:                    select_query = new Select(mDatasource);
0680:                    select_query.from("tbltest").field("name").where("name",
0681:                            "=", "me");
0682:                    try {
0683:                        manager.executeHasResultRows(select_query,
0684:                                new DbPreparedStatementHandler() {
0685:                                    public Object concludeResults(
0686:                                            DbResultSet resultSet)
0687:                                            throws SQLException {
0688:                                        return resultSet.getString("unknown");
0689:                                    }
0690:                                });
0691:                        fail();
0692:                    } catch (DatabaseException e) {
0693:                        assertTrue(true);
0694:                    }
0695:                } catch (DatabaseException e) {
0696:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0697:                }
0698:            }
0699:
0700:            public void testIllegalExecuteGetFirstString() {
0701:                DbQueryManager manager = new DbQueryManager(mDatasource);
0702:                try {
0703:                    manager.executeGetFirstString(null);
0704:                    fail();
0705:                } catch (IllegalArgumentException e) {
0706:                    assertTrue(true);
0707:                }
0708:            }
0709:
0710:            public void testExecuteGetFirstString() {
0711:                DbQueryManager manager = new DbQueryManager(mDatasource);
0712:                try {
0713:                    CreateTable create_query = new CreateTable(mDatasource);
0714:                    create_query.table("tbltest").column("firstcol",
0715:                            String.class, 50).column("lastcol", String.class,
0716:                            50);
0717:                    manager.executeUpdate(create_query);
0718:
0719:                    Select select_query = null;
0720:                    select_query = new Select(mDatasource);
0721:                    select_query.from("tbltest").field("firstcol").where(
0722:                            "lastcol", "=", "Doe");
0723:
0724:                    assertNull(manager.executeGetFirstString(select_query));
0725:
0726:                    manager.executeUpdate(new Insert(mDatasource).into(
0727:                            "tbltest")
0728:                            .fields(
0729:                                    new String[] { "firstcol", "John",
0730:                                            "lastcol", "Doe" }));
0731:                    manager.executeUpdate(new Insert(mDatasource).into(
0732:                            "tbltest").fields(
0733:                            new String[] { "firstcol", "Piet", "lastcol",
0734:                                    "Smith" }));
0735:
0736:                    assertEquals("John", manager
0737:                            .executeGetFirstString(select_query));
0738:
0739:                    select_query = new Select(mDatasource);
0740:                    select_query.from("tbltest").field("firstcol")
0741:                            .whereParameter("lastcol", "=");
0742:                    assertEquals("Piet", manager.executeGetFirstString(
0743:                            select_query, new DbPreparedStatementHandler() {
0744:                                public void setParameters(
0745:                                        DbPreparedStatement statement) {
0746:                                    statement.setString("lastcol", "Smith");
0747:                                }
0748:                            }));
0749:                } catch (DatabaseException e) {
0750:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0751:                }
0752:            }
0753:
0754:            public void testExecuteGetFirstStringConcludeErrors() {
0755:                DbQueryManager manager = new DbQueryManager(mDatasource);
0756:                try {
0757:                    CreateTable create_query = new CreateTable(mDatasource);
0758:                    create_query.table("tbltest").column("name", String.class,
0759:                            50);
0760:                    manager.executeUpdate(create_query);
0761:
0762:                    Select select_query = null;
0763:                    select_query = new Select(mDatasource);
0764:                    select_query.from("tbltest").field("name").where("name",
0765:                            "=", "me");
0766:                    try {
0767:                        manager.executeGetFirstString(select_query,
0768:                                new DbPreparedStatementHandler() {
0769:                                    public Object concludeResults(
0770:                                            DbResultSet resultSet)
0771:                                            throws SQLException {
0772:                                        return resultSet.getString("unknown");
0773:                                    }
0774:                                });
0775:                        fail();
0776:                    } catch (DatabaseException e) {
0777:                        assertTrue(true);
0778:                    }
0779:                } catch (DatabaseException e) {
0780:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0781:                }
0782:            }
0783:
0784:            public void testIllegalExecuteGetFirstBoolean() {
0785:                DbQueryManager manager = new DbQueryManager(mDatasource);
0786:                try {
0787:                    manager.executeGetFirstBoolean(null);
0788:                    fail();
0789:                } catch (IllegalArgumentException e) {
0790:                    assertTrue(true);
0791:                }
0792:            }
0793:
0794:            public void testExecuteGetFirstBoolean() {
0795:                DbQueryManager manager = new DbQueryManager(mDatasource);
0796:                try {
0797:                    CreateTable create_query = new CreateTable(mDatasource);
0798:                    create_query.table("tbltest").column("datacol",
0799:                            boolean.class).column("lastcol", String.class, 50);
0800:                    manager.executeUpdate(create_query);
0801:
0802:                    Select select_query = null;
0803:                    select_query = new Select(mDatasource);
0804:                    select_query.from("tbltest").field("datacol").where(
0805:                            "lastcol", "=", "Doe");
0806:
0807:                    assertEquals(false, manager
0808:                            .executeGetFirstBoolean(select_query));
0809:
0810:                    manager.executeUpdate(new Insert(mDatasource).into(
0811:                            "tbltest").fields(
0812:                            new Object[] { "datacol", new Boolean(true),
0813:                                    "lastcol", "Doe" }));
0814:                    manager.executeUpdate(new Insert(mDatasource).into(
0815:                            "tbltest").fields(
0816:                            new Object[] { "datacol", new Boolean(false),
0817:                                    "lastcol", "Smith" }));
0818:
0819:                    assertEquals(true, manager
0820:                            .executeGetFirstBoolean(select_query));
0821:
0822:                    select_query = new Select(mDatasource);
0823:                    select_query.from("tbltest").field("datacol")
0824:                            .whereParameter("lastcol", "=");
0825:                    assertEquals(false, manager.executeGetFirstBoolean(
0826:                            select_query, new DbPreparedStatementHandler() {
0827:                                public void setParameters(
0828:                                        DbPreparedStatement statement) {
0829:                                    statement.setString("lastcol", "Smith");
0830:                                }
0831:                            }));
0832:                } catch (DatabaseException e) {
0833:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0834:                }
0835:            }
0836:
0837:            public void testExecuteGetFirstBooleanConcludeErrors() {
0838:                DbQueryManager manager = new DbQueryManager(mDatasource);
0839:                try {
0840:                    CreateTable create_query = new CreateTable(mDatasource);
0841:                    create_query.table("tbltest").column("name", String.class,
0842:                            50);
0843:                    manager.executeUpdate(create_query);
0844:
0845:                    Select select_query = null;
0846:                    select_query = new Select(mDatasource);
0847:                    select_query.from("tbltest").field("name").where("name",
0848:                            "=", "me");
0849:                    try {
0850:                        manager.executeGetFirstBoolean(select_query,
0851:                                new DbPreparedStatementHandler() {
0852:                                    public Object concludeResults(
0853:                                            DbResultSet resultSet)
0854:                                            throws SQLException {
0855:                                        resultSet.getBoolean("unknown");
0856:                                        return null;
0857:                                    }
0858:                                });
0859:                        fail();
0860:                    } catch (DatabaseException e) {
0861:                        assertTrue(true);
0862:                    }
0863:                } catch (DatabaseException e) {
0864:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0865:                }
0866:            }
0867:
0868:            public void testIllegalExecuteGetFirstByte() {
0869:                DbQueryManager manager = new DbQueryManager(mDatasource);
0870:                try {
0871:                    manager.executeGetFirstByte(null);
0872:                    fail();
0873:                } catch (IllegalArgumentException e) {
0874:                    assertTrue(true);
0875:                }
0876:            }
0877:
0878:            public void testExecuteGetFirstByte() {
0879:                DbQueryManager manager = new DbQueryManager(mDatasource);
0880:                try {
0881:                    CreateTable create_query = new CreateTable(mDatasource);
0882:                    create_query.table("tbltest").column("datacol", byte.class)
0883:                            .column("lastcol", String.class, 50);
0884:                    manager.executeUpdate(create_query);
0885:
0886:                    Select select_query = null;
0887:                    select_query = new Select(mDatasource);
0888:                    select_query.from("tbltest").field("datacol").where(
0889:                            "lastcol", "=", "Doe");
0890:
0891:                    assertEquals(-1, manager.executeGetFirstByte(select_query));
0892:
0893:                    manager.executeUpdate(new Insert(mDatasource).into(
0894:                            "tbltest").fields(
0895:                            new Object[] { "datacol", new Byte((byte) 12),
0896:                                    "lastcol", "Doe" }));
0897:                    manager.executeUpdate(new Insert(mDatasource).into(
0898:                            "tbltest").fields(
0899:                            new Object[] { "datacol", new Byte((byte) 23),
0900:                                    "lastcol", "Smith" }));
0901:
0902:                    assertEquals(12, manager.executeGetFirstByte(select_query));
0903:
0904:                    select_query = new Select(mDatasource);
0905:                    select_query.from("tbltest").field("datacol")
0906:                            .whereParameter("lastcol", "=");
0907:                    assertEquals(23, manager.executeGetFirstByte(select_query,
0908:                            new DbPreparedStatementHandler() {
0909:                                public void setParameters(
0910:                                        DbPreparedStatement statement) {
0911:                                    statement.setString("lastcol", "Smith");
0912:                                }
0913:                            }));
0914:                } catch (DatabaseException e) {
0915:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0916:                }
0917:            }
0918:
0919:            public void testExecuteGetFirstByteConcludeErrors() {
0920:                DbQueryManager manager = new DbQueryManager(mDatasource);
0921:                try {
0922:                    CreateTable create_query = new CreateTable(mDatasource);
0923:                    create_query.table("tbltest").column("name", String.class,
0924:                            50);
0925:                    manager.executeUpdate(create_query);
0926:
0927:                    Select select_query = null;
0928:                    select_query = new Select(mDatasource);
0929:                    select_query.from("tbltest").field("name").where("name",
0930:                            "=", "me");
0931:                    try {
0932:                        manager.executeGetFirstByte(select_query,
0933:                                new DbPreparedStatementHandler() {
0934:                                    public Object concludeResults(
0935:                                            DbResultSet resultSet)
0936:                                            throws SQLException {
0937:                                        resultSet.getByte("unknown");
0938:                                        return null;
0939:                                    }
0940:                                });
0941:                        fail();
0942:                    } catch (DatabaseException e) {
0943:                        assertTrue(true);
0944:                    }
0945:                } catch (DatabaseException e) {
0946:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0947:                }
0948:            }
0949:
0950:            public void testIllegalExecuteGetFirstShort() {
0951:                DbQueryManager manager = new DbQueryManager(mDatasource);
0952:                try {
0953:                    manager.executeGetFirstShort(null);
0954:                    fail();
0955:                } catch (IllegalArgumentException e) {
0956:                    assertTrue(true);
0957:                }
0958:            }
0959:
0960:            public void testExecuteGetFirstShort() {
0961:                DbQueryManager manager = new DbQueryManager(mDatasource);
0962:                try {
0963:                    CreateTable create_query = new CreateTable(mDatasource);
0964:                    create_query.table("tbltest")
0965:                            .column("datacol", short.class).column("lastcol",
0966:                                    String.class, 50);
0967:                    manager.executeUpdate(create_query);
0968:
0969:                    Select select_query = null;
0970:                    select_query = new Select(mDatasource);
0971:                    select_query.from("tbltest").field("datacol").where(
0972:                            "lastcol", "=", "Doe");
0973:
0974:                    assertEquals(-1, manager.executeGetFirstShort(select_query));
0975:
0976:                    manager.executeUpdate(new Insert(mDatasource).into(
0977:                            "tbltest").fields(
0978:                            new Object[] { "datacol", new Short((short) 98),
0979:                                    "lastcol", "Doe" }));
0980:                    manager.executeUpdate(new Insert(mDatasource).into(
0981:                            "tbltest").fields(
0982:                            new Object[] { "datacol", new Short((short) 243),
0983:                                    "lastcol", "Smith" }));
0984:
0985:                    assertEquals(98, manager.executeGetFirstShort(select_query));
0986:
0987:                    select_query = new Select(mDatasource);
0988:                    select_query.from("tbltest").field("datacol")
0989:                            .whereParameter("lastcol", "=");
0990:                    assertEquals(243, manager.executeGetFirstShort(
0991:                            select_query, new DbPreparedStatementHandler() {
0992:                                public void setParameters(
0993:                                        DbPreparedStatement statement) {
0994:                                    statement.setString("lastcol", "Smith");
0995:                                }
0996:                            }));
0997:                } catch (DatabaseException e) {
0998:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0999:                }
1000:            }
1001:
1002:            public void testExecuteGetFirstShortConcludeErrors() {
1003:                DbQueryManager manager = new DbQueryManager(mDatasource);
1004:                try {
1005:                    CreateTable create_query = new CreateTable(mDatasource);
1006:                    create_query.table("tbltest").column("name", String.class,
1007:                            50);
1008:                    manager.executeUpdate(create_query);
1009:
1010:                    Select select_query = null;
1011:                    select_query = new Select(mDatasource);
1012:                    select_query.from("tbltest").field("name").where("name",
1013:                            "=", "me");
1014:                    try {
1015:                        manager.executeGetFirstShort(select_query,
1016:                                new DbPreparedStatementHandler() {
1017:                                    public Object concludeResults(
1018:                                            DbResultSet resultSet)
1019:                                            throws SQLException {
1020:                                        resultSet.getShort("unknown");
1021:                                        return null;
1022:                                    }
1023:                                });
1024:                        fail();
1025:                    } catch (DatabaseException e) {
1026:                        assertTrue(true);
1027:                    }
1028:                } catch (DatabaseException e) {
1029:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1030:                }
1031:            }
1032:
1033:            public void testIllegalExecuteGetFirstInt() {
1034:                DbQueryManager manager = new DbQueryManager(mDatasource);
1035:                try {
1036:                    manager.executeGetFirstInt(null);
1037:                    fail();
1038:                } catch (IllegalArgumentException e) {
1039:                    assertTrue(true);
1040:                }
1041:            }
1042:
1043:            public void testExecuteGetFirstInt() {
1044:                DbQueryManager manager = new DbQueryManager(mDatasource);
1045:                try {
1046:                    CreateTable create_query = new CreateTable(mDatasource);
1047:                    create_query.table("tbltest").column("datacol", int.class)
1048:                            .column("lastcol", String.class, 50);
1049:                    manager.executeUpdate(create_query);
1050:
1051:                    Select select_query = null;
1052:                    select_query = new Select(mDatasource);
1053:                    select_query.from("tbltest").field("datacol").where(
1054:                            "lastcol", "=", "Doe");
1055:
1056:                    assertEquals(-1, manager.executeGetFirstInt(select_query));
1057:
1058:                    manager.executeUpdate(new Insert(mDatasource).into(
1059:                            "tbltest").fields(
1060:                            new Object[] { "datacol", new Integer(827),
1061:                                    "lastcol", "Doe" }));
1062:                    manager.executeUpdate(new Insert(mDatasource).into(
1063:                            "tbltest").fields(
1064:                            new Object[] { "datacol", new Integer(154),
1065:                                    "lastcol", "Smith" }));
1066:
1067:                    assertEquals(827, manager.executeGetFirstInt(select_query));
1068:
1069:                    select_query = new Select(mDatasource);
1070:                    select_query.from("tbltest").field("datacol")
1071:                            .whereParameter("lastcol", "=");
1072:                    assertEquals(154, manager.executeGetFirstInt(select_query,
1073:                            new DbPreparedStatementHandler() {
1074:                                public void setParameters(
1075:                                        DbPreparedStatement statement) {
1076:                                    statement.setString("lastcol", "Smith");
1077:                                }
1078:                            }));
1079:                } catch (DatabaseException e) {
1080:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1081:                }
1082:            }
1083:
1084:            public void testExecuteGetFirstIntConcludeErrors() {
1085:                DbQueryManager manager = new DbQueryManager(mDatasource);
1086:                try {
1087:                    CreateTable create_query = new CreateTable(mDatasource);
1088:                    create_query.table("tbltest").column("name", String.class,
1089:                            50);
1090:                    manager.executeUpdate(create_query);
1091:
1092:                    Select select_query = null;
1093:                    select_query = new Select(mDatasource);
1094:                    select_query.from("tbltest").field("name").where("name",
1095:                            "=", "me");
1096:                    try {
1097:                        manager.executeGetFirstInt(select_query,
1098:                                new DbPreparedStatementHandler() {
1099:                                    public Object concludeResults(
1100:                                            DbResultSet resultSet)
1101:                                            throws SQLException {
1102:                                        resultSet.getInt("unknown");
1103:                                        return null;
1104:                                    }
1105:                                });
1106:                        fail();
1107:                    } catch (DatabaseException e) {
1108:                        assertTrue(true);
1109:                    }
1110:                } catch (DatabaseException e) {
1111:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1112:                }
1113:            }
1114:
1115:            public void testIllegalExecuteGetFirstLong() {
1116:                DbQueryManager manager = new DbQueryManager(mDatasource);
1117:                try {
1118:                    manager.executeGetFirstLong(null);
1119:                    fail();
1120:                } catch (IllegalArgumentException e) {
1121:                    assertTrue(true);
1122:                }
1123:            }
1124:
1125:            public void testExecuteGetFirstLong() {
1126:                DbQueryManager manager = new DbQueryManager(mDatasource);
1127:                try {
1128:                    CreateTable create_query = new CreateTable(mDatasource);
1129:                    create_query.table("tbltest").column("datacol", long.class)
1130:                            .column("lastcol", String.class, 50);
1131:                    manager.executeUpdate(create_query);
1132:
1133:                    Select select_query = null;
1134:                    select_query = new Select(mDatasource);
1135:                    select_query.from("tbltest").field("datacol").where(
1136:                            "lastcol", "=", "Doe");
1137:
1138:                    assertEquals(-1, manager.executeGetFirstLong(select_query));
1139:
1140:                    manager.executeUpdate(new Insert(mDatasource).into(
1141:                            "tbltest").fields(
1142:                            new Object[] { "datacol", new Long(92873),
1143:                                    "lastcol", "Doe" }));
1144:                    manager.executeUpdate(new Insert(mDatasource).into(
1145:                            "tbltest").fields(
1146:                            new Object[] { "datacol", new Long(14873),
1147:                                    "lastcol", "Smith" }));
1148:
1149:                    assertEquals(92873, manager
1150:                            .executeGetFirstLong(select_query));
1151:
1152:                    select_query = new Select(mDatasource);
1153:                    select_query.from("tbltest").field("datacol")
1154:                            .whereParameter("lastcol", "=");
1155:                    assertEquals(14873, manager.executeGetFirstLong(
1156:                            select_query, new DbPreparedStatementHandler() {
1157:                                public void setParameters(
1158:                                        DbPreparedStatement statement) {
1159:                                    statement.setString("lastcol", "Smith");
1160:                                }
1161:                            }));
1162:                } catch (DatabaseException e) {
1163:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1164:                }
1165:            }
1166:
1167:            public void testExecuteGetFirstLongConcludeErrors() {
1168:                DbQueryManager manager = new DbQueryManager(mDatasource);
1169:                try {
1170:                    CreateTable create_query = new CreateTable(mDatasource);
1171:                    create_query.table("tbltest").column("name", String.class,
1172:                            50);
1173:                    manager.executeUpdate(create_query);
1174:
1175:                    Select select_query = null;
1176:                    select_query = new Select(mDatasource);
1177:                    select_query.from("tbltest").field("name").where("name",
1178:                            "=", "me");
1179:                    try {
1180:                        manager.executeGetFirstLong(select_query,
1181:                                new DbPreparedStatementHandler() {
1182:                                    public Object concludeResults(
1183:                                            DbResultSet resultSet)
1184:                                            throws SQLException {
1185:                                        resultSet.getLong("unknown");
1186:                                        return null;
1187:                                    }
1188:                                });
1189:                        fail();
1190:                    } catch (DatabaseException e) {
1191:                        assertTrue(true);
1192:                    }
1193:                } catch (DatabaseException e) {
1194:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1195:                }
1196:            }
1197:
1198:            public void testIllegalExecuteGetFirstFloat() {
1199:                DbQueryManager manager = new DbQueryManager(mDatasource);
1200:                try {
1201:                    manager.executeGetFirstFloat(null);
1202:                    fail();
1203:                } catch (IllegalArgumentException e) {
1204:                    assertTrue(true);
1205:                }
1206:            }
1207:
1208:            public void testExecuteGetFirstFloat() {
1209:                DbQueryManager manager = new DbQueryManager(mDatasource);
1210:                try {
1211:                    CreateTable create_query = new CreateTable(mDatasource);
1212:                    create_query.table("tbltest")
1213:                            .column("datacol", float.class).column("lastcol",
1214:                                    String.class, 50);
1215:                    manager.executeUpdate(create_query);
1216:
1217:                    Select select_query = null;
1218:                    select_query = new Select(mDatasource);
1219:                    select_query.from("tbltest").field("datacol").where(
1220:                            "lastcol", "=", "Doe");
1221:
1222:                    assertEquals(-1.0f, manager
1223:                            .executeGetFirstFloat(select_query));
1224:
1225:                    manager.executeUpdate(new Insert(mDatasource).into(
1226:                            "tbltest").fields(
1227:                            new Object[] { "datacol", new Float(12.4),
1228:                                    "lastcol", "Doe" }));
1229:                    manager.executeUpdate(new Insert(mDatasource).into(
1230:                            "tbltest").fields(
1231:                            new Object[] { "datacol", new Float(23.5),
1232:                                    "lastcol", "Smith" }));
1233:
1234:                    assertEquals(12.4f, manager
1235:                            .executeGetFirstFloat(select_query));
1236:
1237:                    select_query = new Select(mDatasource);
1238:                    select_query.from("tbltest").field("datacol")
1239:                            .whereParameter("lastcol", "=");
1240:                    assertEquals(23.5f, manager.executeGetFirstFloat(
1241:                            select_query, new DbPreparedStatementHandler() {
1242:                                public void setParameters(
1243:                                        DbPreparedStatement statement) {
1244:                                    statement.setString("lastcol", "Smith");
1245:                                }
1246:                            }));
1247:                } catch (DatabaseException e) {
1248:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1249:                }
1250:            }
1251:
1252:            public void testExecuteGetFirstFloatConcludeErrors() {
1253:                DbQueryManager manager = new DbQueryManager(mDatasource);
1254:                try {
1255:                    CreateTable create_query = new CreateTable(mDatasource);
1256:                    create_query.table("tbltest").column("name", String.class,
1257:                            50);
1258:                    manager.executeUpdate(create_query);
1259:
1260:                    Select select_query = null;
1261:                    select_query = new Select(mDatasource);
1262:                    select_query.from("tbltest").field("name").where("name",
1263:                            "=", "me");
1264:                    try {
1265:                        manager.executeGetFirstFloat(select_query,
1266:                                new DbPreparedStatementHandler() {
1267:                                    public Object concludeResults(
1268:                                            DbResultSet resultSet)
1269:                                            throws SQLException {
1270:                                        resultSet.getFloat("unknown");
1271:                                        return null;
1272:                                    }
1273:                                });
1274:                        fail();
1275:                    } catch (DatabaseException e) {
1276:                        assertTrue(true);
1277:                    }
1278:                } catch (DatabaseException e) {
1279:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1280:                }
1281:            }
1282:
1283:            public void testIllegalExecuteGetFirstDouble() {
1284:                DbQueryManager manager = new DbQueryManager(mDatasource);
1285:                try {
1286:                    manager.executeGetFirstDouble(null);
1287:                    fail();
1288:                } catch (IllegalArgumentException e) {
1289:                    assertTrue(true);
1290:                }
1291:            }
1292:
1293:            public void testExecuteGetFirstDouble() {
1294:                DbQueryManager manager = new DbQueryManager(mDatasource);
1295:                try {
1296:                    CreateTable create_query = new CreateTable(mDatasource);
1297:                    create_query.table("tbltest").column("datacol",
1298:                            double.class).column("lastcol", String.class, 50);
1299:                    manager.executeUpdate(create_query);
1300:
1301:                    Select select_query = null;
1302:                    select_query = new Select(mDatasource);
1303:                    select_query.from("tbltest").field("datacol").where(
1304:                            "lastcol", "=", "Doe");
1305:
1306:                    assertEquals(-1.0d, manager
1307:                            .executeGetFirstDouble(select_query));
1308:
1309:                    manager.executeUpdate(new Insert(mDatasource).into(
1310:                            "tbltest").fields(
1311:                            new Object[] { "datacol", new Double(287.52),
1312:                                    "lastcol", "Doe" }));
1313:                    manager.executeUpdate(new Insert(mDatasource).into(
1314:                            "tbltest").fields(
1315:                            new Object[] { "datacol", new Double(1984.328),
1316:                                    "lastcol", "Smith" }));
1317:
1318:                    assertEquals(287.52d, manager
1319:                            .executeGetFirstDouble(select_query), 0.001);
1320:
1321:                    select_query = new Select(mDatasource);
1322:                    select_query.from("tbltest").field("datacol")
1323:                            .whereParameter("lastcol", "=");
1324:                    assertEquals(1984.328d, manager.executeGetFirstDouble(
1325:                            select_query, new DbPreparedStatementHandler() {
1326:                                public void setParameters(
1327:                                        DbPreparedStatement statement) {
1328:                                    statement.setString("lastcol", "Smith");
1329:                                }
1330:                            }), 0.001);
1331:                } catch (DatabaseException e) {
1332:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1333:                }
1334:            }
1335:
1336:            public void testExecuteGetFirstDoubleConcludeErrors() {
1337:                DbQueryManager manager = new DbQueryManager(mDatasource);
1338:                try {
1339:                    CreateTable create_query = new CreateTable(mDatasource);
1340:                    create_query.table("tbltest").column("name", String.class,
1341:                            50);
1342:                    manager.executeUpdate(create_query);
1343:
1344:                    Select select_query = null;
1345:                    select_query = new Select(mDatasource);
1346:                    select_query.from("tbltest").field("name").where("name",
1347:                            "=", "me");
1348:                    try {
1349:                        manager.executeGetFirstDouble(select_query,
1350:                                new DbPreparedStatementHandler() {
1351:                                    public Object concludeResults(
1352:                                            DbResultSet resultSet)
1353:                                            throws SQLException {
1354:                                        resultSet.getDouble("unknown");
1355:                                        return null;
1356:                                    }
1357:                                });
1358:                        fail();
1359:                    } catch (DatabaseException e) {
1360:                        assertTrue(true);
1361:                    }
1362:                } catch (DatabaseException e) {
1363:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1364:                }
1365:            }
1366:
1367:            public void testIllegalExecuteGetFirstBytes() {
1368:                DbQueryManager manager = new DbQueryManager(mDatasource);
1369:                try {
1370:                    manager.executeGetFirstBytes(null);
1371:                    fail();
1372:                } catch (IllegalArgumentException e) {
1373:                    assertTrue(true);
1374:                }
1375:            }
1376:
1377:            public void testExecuteGetFirstBytes() {
1378:                DbQueryManager manager = new DbQueryManager(mDatasource);
1379:                try {
1380:                    CreateTable create_query = new CreateTable(mDatasource);
1381:                    if (mDatasource.getAliasedDriver().equals(
1382:                            "oracle.jdbc.driver.OracleDriver")) {
1383:                        create_query.table("tbltest").column("datacol",
1384:                                String.class).column("lastcol", String.class,
1385:                                50);
1386:                    } else {
1387:                        create_query.table("tbltest").column("datacol",
1388:                                Blob.class).column("lastcol", String.class, 50);
1389:                    }
1390:                    manager.executeUpdate(create_query);
1391:
1392:                    Select select_query = null;
1393:                    select_query = new Select(mDatasource);
1394:                    select_query.from("tbltest").field("datacol").where(
1395:                            "lastcol", "=", "Doe");
1396:
1397:                    assertNull(manager.executeGetFirstBytes(select_query));
1398:
1399:                    Insert insert = new Insert(mDatasource).into("tbltest")
1400:                            .fieldParameter("datacol")
1401:                            .fieldParameter("lastcol");
1402:                    manager.executeUpdate(insert,
1403:                            new DbPreparedStatementHandler() {
1404:                                public void setParameters(
1405:                                        DbPreparedStatement statement) {
1406:                                    if (mDatasource.getAliasedDriver().equals(
1407:                                            "oracle.jdbc.driver.OracleDriver")) {
1408:                                        statement.setString("datacol", "abc");
1409:                                    } else {
1410:                                        statement.setBytes("datacol", "abc"
1411:                                                .getBytes());
1412:                                    }
1413:                                    statement.setString("lastcol", "Doe");
1414:                                }
1415:                            });
1416:                    manager.executeUpdate(insert,
1417:                            new DbPreparedStatementHandler() {
1418:                                public void setParameters(
1419:                                        DbPreparedStatement statement) {
1420:                                    if (mDatasource.getAliasedDriver().equals(
1421:                                            "oracle.jdbc.driver.OracleDriver")) {
1422:                                        statement.setString("datacol", "def");
1423:                                    } else {
1424:                                        statement.setBytes("datacol", "def"
1425:                                                .getBytes());
1426:                                    }
1427:                                    statement.setString("lastcol", "Smith");
1428:                                }
1429:                            });
1430:
1431:                    byte[] result = null;
1432:                    result = manager.executeGetFirstBytes(select_query);
1433:                    assertTrue(Arrays.equals(new byte[] { 97, 98, 99 }, result));
1434:
1435:                    select_query = new Select(mDatasource);
1436:                    select_query.from("tbltest").field("datacol")
1437:                            .whereParameter("lastcol", "=");
1438:                    result = manager.executeGetFirstBytes(select_query,
1439:                            new DbPreparedStatementHandler() {
1440:                                public void setParameters(
1441:                                        DbPreparedStatement statement) {
1442:                                    statement.setString("lastcol", "Smith");
1443:                                }
1444:                            });
1445:                    assertTrue(Arrays.equals(new byte[] { 100, 101, 102 },
1446:                            result));
1447:                } catch (DatabaseException e) {
1448:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1449:                }
1450:            }
1451:
1452:            public void testExecuteGetFirstBytesConcludeErrors() {
1453:                DbQueryManager manager = new DbQueryManager(mDatasource);
1454:                try {
1455:                    CreateTable create_query = new CreateTable(mDatasource);
1456:                    create_query.table("tbltest").column("name", String.class,
1457:                            50);
1458:                    manager.executeUpdate(create_query);
1459:
1460:                    Select select_query = null;
1461:                    select_query = new Select(mDatasource);
1462:                    select_query.from("tbltest").field("name").where("name",
1463:                            "=", "me");
1464:                    try {
1465:                        manager.executeGetFirstBytes(select_query,
1466:                                new DbPreparedStatementHandler() {
1467:                                    public Object concludeResults(
1468:                                            DbResultSet resultSet)
1469:                                            throws SQLException {
1470:                                        resultSet.getBytes("unknown");
1471:                                        return null;
1472:                                    }
1473:                                });
1474:                        fail();
1475:                    } catch (DatabaseException e) {
1476:                        assertTrue(true);
1477:                    }
1478:                } catch (DatabaseException e) {
1479:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1480:                }
1481:            }
1482:
1483:            public void testIllegalExecuteGetFirstDate() {
1484:                DbQueryManager manager = new DbQueryManager(mDatasource);
1485:                try {
1486:                    manager.executeGetFirstDate(null);
1487:                    fail();
1488:                } catch (IllegalArgumentException e) {
1489:                    assertTrue(true);
1490:                }
1491:                try {
1492:                    manager.executeGetFirstDate(null, (Calendar) null);
1493:                    fail();
1494:                } catch (IllegalArgumentException e) {
1495:                    assertTrue(true);
1496:                }
1497:            }
1498:
1499:            public void testExecuteGetFirstDate() {
1500:                DbQueryManager manager = new DbQueryManager(mDatasource);
1501:                try {
1502:                    CreateTable create_query = new CreateTable(mDatasource);
1503:                    create_query.table("tbltest").column("datacol",
1504:                            java.sql.Date.class).column("lastcol",
1505:                            String.class, 50);
1506:                    manager.executeUpdate(create_query);
1507:
1508:                    Select select_query = null;
1509:                    select_query = new Select(mDatasource);
1510:                    select_query.from("tbltest").field("datacol").where(
1511:                            "lastcol", "=", "Doe");
1512:
1513:                    assertNull(manager.executeGetFirstDate(select_query));
1514:                    assertNull(manager.executeGetFirstDate(select_query,
1515:                            Calendar.getInstance()));
1516:
1517:                    Calendar cal1 = Calendar.getInstance();
1518:                    cal1.set(2003, 11, 12, 0, 0, 0);
1519:                    cal1.set(Calendar.MILLISECOND, 0);
1520:                    Calendar cal2 = Calendar.getInstance();
1521:                    cal2.set(2004, 2, 7, 0, 0, 0);
1522:                    cal2.set(Calendar.MILLISECOND, 0);
1523:                    manager.executeUpdate(new Insert(mDatasource).into(
1524:                            "tbltest").fields(
1525:                            new Object[] { "datacol",
1526:                                    new java.sql.Date(cal1.getTimeInMillis()),
1527:                                    "lastcol", "Doe" }));
1528:                    manager.executeUpdate(new Insert(mDatasource).into(
1529:                            "tbltest").fields(
1530:                            new Object[] { "datacol",
1531:                                    new java.sql.Date(cal2.getTimeInMillis()),
1532:                                    "lastcol", "Smith" }));
1533:
1534:                    assertEquals(cal1.getTimeInMillis(), manager
1535:                            .executeGetFirstDate(select_query).getTime());
1536:                    assertEquals(cal1.getTimeInMillis(), manager
1537:                            .executeGetFirstDate(select_query,
1538:                                    Calendar.getInstance()).getTime());
1539:
1540:                    select_query = new Select(mDatasource);
1541:                    select_query.from("tbltest").field("datacol")
1542:                            .whereParameter("lastcol", "=");
1543:                    assertEquals(cal2.getTimeInMillis(), manager
1544:                            .executeGetFirstDate(select_query,
1545:                                    new DbPreparedStatementHandler() {
1546:                                        public void setParameters(
1547:                                                DbPreparedStatement statement) {
1548:                                            statement.setString("lastcol",
1549:                                                    "Smith");
1550:                                        }
1551:                                    }).getTime());
1552:                    assertEquals(cal2.getTimeInMillis(), manager
1553:                            .executeGetFirstDate(select_query,
1554:                                    Calendar.getInstance(),
1555:                                    new DbPreparedStatementHandler() {
1556:                                        public void setParameters(
1557:                                                DbPreparedStatement statement) {
1558:                                            statement.setString("lastcol",
1559:                                                    "Smith");
1560:                                        }
1561:                                    }).getTime());
1562:                } catch (DatabaseException e) {
1563:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1564:                }
1565:            }
1566:
1567:            public void testExecuteGetFirstDateConcludeErrors() {
1568:                DbQueryManager manager = new DbQueryManager(mDatasource);
1569:                try {
1570:                    CreateTable create_query = new CreateTable(mDatasource);
1571:                    create_query.table("tbltest").column("name", String.class,
1572:                            50);
1573:                    manager.executeUpdate(create_query);
1574:
1575:                    Select select_query = null;
1576:                    select_query = new Select(mDatasource);
1577:                    select_query.from("tbltest").field("name").where("name",
1578:                            "=", "me");
1579:                    try {
1580:                        manager.executeGetFirstDate(select_query,
1581:                                new DbPreparedStatementHandler() {
1582:                                    public Object concludeResults(
1583:                                            DbResultSet resultSet)
1584:                                            throws SQLException {
1585:                                        return resultSet.getDate("unknown");
1586:                                    }
1587:                                });
1588:                        fail();
1589:                    } catch (DatabaseException e) {
1590:                        assertTrue(true);
1591:                    }
1592:                    try {
1593:                        manager.executeGetFirstDate(select_query, Calendar
1594:                                .getInstance(),
1595:                                new DbPreparedStatementHandler() {
1596:                                    public Object concludeResults(
1597:                                            DbResultSet resultSet)
1598:                                            throws SQLException {
1599:                                        return resultSet.getDate("unknown");
1600:                                    }
1601:                                });
1602:                        fail();
1603:                    } catch (DatabaseException e) {
1604:                        assertTrue(true);
1605:                    }
1606:                } catch (DatabaseException e) {
1607:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1608:                }
1609:            }
1610:
1611:            public void testIllegalExecuteGetFirstTime() {
1612:                DbQueryManager manager = new DbQueryManager(mDatasource);
1613:                try {
1614:                    manager.executeGetFirstTime(null);
1615:                    fail();
1616:                } catch (IllegalArgumentException e) {
1617:                    assertTrue(true);
1618:                }
1619:                try {
1620:                    manager.executeGetFirstTime(null, (Calendar) null);
1621:                    fail();
1622:                } catch (IllegalArgumentException e) {
1623:                    assertTrue(true);
1624:                }
1625:            }
1626:
1627:            public void testExecuteGetFirstTime() {
1628:                DbQueryManager manager = new DbQueryManager(mDatasource);
1629:                try {
1630:                    CreateTable create_query = new CreateTable(mDatasource);
1631:                    create_query.table("tbltest").column("datacol",
1632:                            java.sql.Time.class).column("lastcol",
1633:                            String.class, 50);
1634:                    manager.executeUpdate(create_query);
1635:
1636:                    Select select_query = null;
1637:                    select_query = new Select(mDatasource);
1638:                    select_query.from("tbltest").field("datacol").where(
1639:                            "lastcol", "=", "Doe");
1640:
1641:                    assertNull(manager.executeGetFirstTime(select_query));
1642:                    assertNull(manager.executeGetFirstTime(select_query,
1643:                            Calendar.getInstance()));
1644:
1645:                    Calendar cal1 = Calendar.getInstance();
1646:                    cal1.set(1970, 0, 1, 12, 5, 12);
1647:                    cal1.set(Calendar.MILLISECOND, 0);
1648:                    Calendar cal2 = Calendar.getInstance();
1649:                    cal2.set(1970, 0, 1, 23, 34, 27);
1650:                    cal2.set(Calendar.MILLISECOND, 0);
1651:                    manager.executeUpdate(new Insert(mDatasource).into(
1652:                            "tbltest").fields(
1653:                            new Object[] { "datacol",
1654:                                    new java.sql.Time(cal1.getTimeInMillis()),
1655:                                    "lastcol", "Doe" }));
1656:                    manager.executeUpdate(new Insert(mDatasource).into(
1657:                            "tbltest").fields(
1658:                            new Object[] { "datacol",
1659:                                    new java.sql.Time(cal2.getTimeInMillis()),
1660:                                    "lastcol", "Smith" }));
1661:
1662:                    assertEquals(cal1.getTimeInMillis(), manager
1663:                            .executeGetFirstTime(select_query).getTime());
1664:                    assertEquals(cal1.getTimeInMillis(), manager
1665:                            .executeGetFirstTime(select_query,
1666:                                    Calendar.getInstance()).getTime());
1667:
1668:                    select_query = new Select(mDatasource);
1669:                    select_query.from("tbltest").field("datacol")
1670:                            .whereParameter("lastcol", "=");
1671:                    assertEquals(cal2.getTimeInMillis(), manager
1672:                            .executeGetFirstTime(select_query,
1673:                                    new DbPreparedStatementHandler() {
1674:                                        public void setParameters(
1675:                                                DbPreparedStatement statement) {
1676:                                            statement.setString("lastcol",
1677:                                                    "Smith");
1678:                                        }
1679:                                    }).getTime());
1680:                    assertEquals(cal2.getTimeInMillis(), manager
1681:                            .executeGetFirstTime(select_query,
1682:                                    Calendar.getInstance(),
1683:                                    new DbPreparedStatementHandler() {
1684:                                        public void setParameters(
1685:                                                DbPreparedStatement statement) {
1686:                                            statement.setString("lastcol",
1687:                                                    "Smith");
1688:                                        }
1689:                                    }).getTime());
1690:                } catch (DatabaseException e) {
1691:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1692:                }
1693:            }
1694:
1695:            public void testExecuteGetFirstTimeConcludeErrors() {
1696:                DbQueryManager manager = new DbQueryManager(mDatasource);
1697:                try {
1698:                    CreateTable create_query = new CreateTable(mDatasource);
1699:                    create_query.table("tbltest").column("name", String.class,
1700:                            50);
1701:                    manager.executeUpdate(create_query);
1702:
1703:                    Select select_query = null;
1704:                    select_query = new Select(mDatasource);
1705:                    select_query.from("tbltest").field("name").where("name",
1706:                            "=", "me");
1707:                    try {
1708:                        manager.executeGetFirstTime(select_query,
1709:                                new DbPreparedStatementHandler() {
1710:                                    public Object concludeResults(
1711:                                            DbResultSet resultSet)
1712:                                            throws SQLException {
1713:                                        return resultSet.getTime("unknown");
1714:                                    }
1715:                                });
1716:                        fail();
1717:                    } catch (DatabaseException e) {
1718:                        assertTrue(true);
1719:                    }
1720:                    try {
1721:                        manager.executeGetFirstTime(select_query, Calendar
1722:                                .getInstance(),
1723:                                new DbPreparedStatementHandler() {
1724:                                    public Object concludeResults(
1725:                                            DbResultSet resultSet)
1726:                                            throws SQLException {
1727:                                        return resultSet.getTime("unknown");
1728:                                    }
1729:                                });
1730:                        fail();
1731:                    } catch (DatabaseException e) {
1732:                        assertTrue(true);
1733:                    }
1734:                } catch (DatabaseException e) {
1735:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1736:                }
1737:            }
1738:
1739:            public void testIllegalExecuteGetFirstTimestamp() {
1740:                DbQueryManager manager = new DbQueryManager(mDatasource);
1741:                try {
1742:                    manager.executeGetFirstTimestamp(null);
1743:                    fail();
1744:                } catch (IllegalArgumentException e) {
1745:                    assertTrue(true);
1746:                }
1747:                try {
1748:                    manager.executeGetFirstTimestamp(null, (Calendar) null);
1749:                    fail();
1750:                } catch (IllegalArgumentException e) {
1751:                    assertTrue(true);
1752:                }
1753:            }
1754:
1755:            public void testExecuteGetFirstTimestamp() {
1756:                DbQueryManager manager = new DbQueryManager(mDatasource);
1757:                try {
1758:                    CreateTable create_query = new CreateTable(mDatasource);
1759:                    create_query.table("tbltest").column("datacol",
1760:                            java.sql.Timestamp.class).column("lastcol",
1761:                            String.class, 50);
1762:                    manager.executeUpdate(create_query);
1763:
1764:                    Select select_query = null;
1765:                    select_query = new Select(mDatasource);
1766:                    select_query.from("tbltest").field("datacol").where(
1767:                            "lastcol", "=", "Doe");
1768:
1769:                    assertNull(manager.executeGetFirstTimestamp(select_query));
1770:                    assertNull(manager.executeGetFirstTimestamp(select_query,
1771:                            Calendar.getInstance()));
1772:
1773:                    Calendar cal1 = Calendar.getInstance();
1774:                    cal1.set(2003, 11, 12, 8, 10, 8);
1775:                    cal1.set(Calendar.MILLISECOND, 0);
1776:                    Calendar cal2 = Calendar.getInstance();
1777:                    cal2.set(2004, 2, 7, 21, 34, 12);
1778:                    cal2.set(Calendar.MILLISECOND, 0);
1779:                    manager.executeUpdate(new Insert(mDatasource).into(
1780:                            "tbltest").fields(
1781:                            new Object[] {
1782:                                    "datacol",
1783:                                    new java.sql.Timestamp(cal1
1784:                                            .getTimeInMillis()), "lastcol",
1785:                                    "Doe" }));
1786:                    manager.executeUpdate(new Insert(mDatasource).into(
1787:                            "tbltest").fields(
1788:                            new Object[] {
1789:                                    "datacol",
1790:                                    new java.sql.Timestamp(cal2
1791:                                            .getTimeInMillis()), "lastcol",
1792:                                    "Smith" }));
1793:
1794:                    assertEquals(cal1.getTimeInMillis(), manager
1795:                            .executeGetFirstTimestamp(select_query).getTime());
1796:                    assertEquals(cal1.getTimeInMillis(), manager
1797:                            .executeGetFirstTimestamp(select_query,
1798:                                    Calendar.getInstance()).getTime());
1799:
1800:                    select_query = new Select(mDatasource);
1801:                    select_query.from("tbltest").field("datacol")
1802:                            .whereParameter("lastcol", "=");
1803:                    assertEquals(cal2.getTimeInMillis(), manager
1804:                            .executeGetFirstTimestamp(select_query,
1805:                                    new DbPreparedStatementHandler() {
1806:                                        public void setParameters(
1807:                                                DbPreparedStatement statement) {
1808:                                            statement.setString("lastcol",
1809:                                                    "Smith");
1810:                                        }
1811:                                    }).getTime());
1812:                    assertEquals(cal2.getTimeInMillis(), manager
1813:                            .executeGetFirstTimestamp(select_query,
1814:                                    Calendar.getInstance(),
1815:                                    new DbPreparedStatementHandler() {
1816:                                        public void setParameters(
1817:                                                DbPreparedStatement statement) {
1818:                                            statement.setString("lastcol",
1819:                                                    "Smith");
1820:                                        }
1821:                                    }).getTime());
1822:                } catch (DatabaseException e) {
1823:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1824:                }
1825:            }
1826:
1827:            public void testExecuteGetFirstTimestampConcludeErrors() {
1828:                DbQueryManager manager = new DbQueryManager(mDatasource);
1829:                try {
1830:                    CreateTable create_query = new CreateTable(mDatasource);
1831:                    create_query.table("tbltest").column("name", String.class,
1832:                            50);
1833:                    manager.executeUpdate(create_query);
1834:
1835:                    Select select_query = null;
1836:                    select_query = new Select(mDatasource);
1837:                    select_query.from("tbltest").field("name").where("name",
1838:                            "=", "me");
1839:                    try {
1840:                        manager.executeGetFirstTimestamp(select_query,
1841:                                new DbPreparedStatementHandler() {
1842:                                    public Object concludeResults(
1843:                                            DbResultSet resultSet)
1844:                                            throws SQLException {
1845:                                        return resultSet
1846:                                                .getTimestamp("unknown");
1847:                                    }
1848:                                });
1849:                        fail();
1850:                    } catch (DatabaseException e) {
1851:                        assertTrue(true);
1852:                    }
1853:                    try {
1854:                        manager.executeGetFirstTimestamp(select_query, Calendar
1855:                                .getInstance(),
1856:                                new DbPreparedStatementHandler() {
1857:                                    public Object concludeResults(
1858:                                            DbResultSet resultSet)
1859:                                            throws SQLException {
1860:                                        return resultSet
1861:                                                .getTimestamp("unknown");
1862:                                    }
1863:                                });
1864:                        fail();
1865:                    } catch (DatabaseException e) {
1866:                        assertTrue(true);
1867:                    }
1868:                } catch (DatabaseException e) {
1869:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1870:                }
1871:            }
1872:
1873:            public void testIllegalExecuteGetFirstAsciiStream() {
1874:                DbQueryManager manager = new DbQueryManager(mDatasource);
1875:                try {
1876:                    manager.executeUseFirstAsciiStream(null, null);
1877:                    fail();
1878:                } catch (IllegalArgumentException e) {
1879:                    assertTrue(true);
1880:                }
1881:                try {
1882:                    manager.executeUseFirstAsciiStream(new Select(mDatasource)
1883:                            .from("tbltest"), null);
1884:                    fail();
1885:                } catch (IllegalArgumentException e) {
1886:                    assertTrue(true);
1887:                }
1888:            }
1889:
1890:            public void testExecuteGetFirstAsciiStream() {
1891:                DbQueryManager manager = new DbQueryManager(mDatasource);
1892:                try {
1893:                    CreateTable create_query = new CreateTable(mDatasource);
1894:                    create_query.table("tbltest").column("firstcol",
1895:                            String.class, 50).column("lastcol", String.class,
1896:                            50);
1897:                    manager.executeUpdate(create_query);
1898:
1899:                    Select select_query = null;
1900:                    select_query = new Select(mDatasource);
1901:                    select_query.from("tbltest").field("firstcol").where(
1902:                            "lastcol", "=", "Doe");
1903:
1904:                    manager.executeUseFirstAsciiStream(select_query,
1905:                            new InputStreamUser() {
1906:                                public Object useInputStream(InputStream stream)
1907:                                        throws InnerClassException {
1908:                                    assertNull(stream);
1909:
1910:                                    return null;
1911:                                }
1912:                            });
1913:
1914:                    manager.executeUpdate(new Insert(mDatasource).into(
1915:                            "tbltest")
1916:                            .fields(
1917:                                    new String[] { "firstcol", "John",
1918:                                            "lastcol", "Doe" }));
1919:                    manager.executeUpdate(new Insert(mDatasource).into(
1920:                            "tbltest").fields(
1921:                            new String[] { "firstcol", "Piet", "lastcol",
1922:                                    "Smith" }));
1923:
1924:                    manager.executeUseFirstAsciiStream(select_query,
1925:                            new InputStreamUser() {
1926:                                public Object useInputStream(InputStream stream)
1927:                                        throws InnerClassException {
1928:                                    assertNotNull(stream);
1929:                                    try {
1930:                                        assertEquals("John", FileUtils
1931:                                                .readString(stream));
1932:                                    } catch (FileUtilsErrorException e) {
1933:                                        assertTrue(ExceptionUtils
1934:                                                .getExceptionStackTrace(e),
1935:                                                false);
1936:                                    }
1937:
1938:                                    return null;
1939:                                }
1940:                            });
1941:
1942:                    select_query = new Select(mDatasource);
1943:                    select_query.from("tbltest").field("firstcol")
1944:                            .whereParameter("lastcol", "=");
1945:                    manager.executeUseFirstAsciiStream(select_query,
1946:                            new InputStreamUser() {
1947:                                public Object useInputStream(InputStream stream)
1948:                                        throws InnerClassException {
1949:                                    assertNotNull(stream);
1950:                                    try {
1951:                                        assertEquals("Piet", FileUtils
1952:                                                .readString(stream));
1953:                                    } catch (FileUtilsErrorException e) {
1954:                                        assertTrue(ExceptionUtils
1955:                                                .getExceptionStackTrace(e),
1956:                                                false);
1957:                                    }
1958:
1959:                                    return null;
1960:                                }
1961:                            }, new DbPreparedStatementHandler() {
1962:                                public void setParameters(
1963:                                        DbPreparedStatement statement) {
1964:                                    statement.setString("lastcol", "Smith");
1965:                                }
1966:                            });
1967:                } catch (DatabaseException e) {
1968:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1969:                }
1970:            }
1971:
1972:            public void testExecuteGetFirstAsciiStreamConcludeErrors() {
1973:                DbQueryManager manager = new DbQueryManager(mDatasource);
1974:                try {
1975:                    CreateTable create_query = new CreateTable(mDatasource);
1976:                    create_query.table("tbltest").column("name", String.class,
1977:                            50);
1978:                    manager.executeUpdate(create_query);
1979:
1980:                    Select select_query = null;
1981:                    select_query = new Select(mDatasource);
1982:                    select_query.from("tbltest").field("name").where("name",
1983:                            "=", "me");
1984:                    try {
1985:                        manager.executeUseFirstAsciiStream(select_query,
1986:                                new InputStreamUser() {
1987:                                    public Object useInputStream(
1988:                                            InputStream stream)
1989:                                            throws InnerClassException {
1990:                                        assertNotNull(stream);
1991:
1992:                                        return null;
1993:                                    }
1994:                                }, new DbPreparedStatementHandler() {
1995:                                    public Object concludeResults(
1996:                                            DbResultSet resultSet)
1997:                                            throws SQLException {
1998:                                        return resultSet.getString("unknown");
1999:                                    }
2000:                                });
2001:                        fail();
2002:                    } catch (DatabaseException e) {
2003:                        assertTrue(true);
2004:                    }
2005:                } catch (DatabaseException e) {
2006:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2007:                }
2008:            }
2009:
2010:            public void testIllegalExecuteGetFirstCharacterStream() {
2011:                DbQueryManager manager = new DbQueryManager(mDatasource);
2012:                try {
2013:                    manager.executeUseFirstCharacterStream(null, null);
2014:                    fail();
2015:                } catch (IllegalArgumentException e) {
2016:                    assertTrue(true);
2017:                }
2018:                try {
2019:                    manager.executeUseFirstCharacterStream(new Select(
2020:                            mDatasource).from("tbltest"), null);
2021:                    fail();
2022:                } catch (IllegalArgumentException e) {
2023:                    assertTrue(true);
2024:                }
2025:            }
2026:
2027:            public void testExecuteGetFirstCharacterStream() {
2028:                DbQueryManager manager = new DbQueryManager(mDatasource);
2029:                try {
2030:                    CreateTable create_query = new CreateTable(mDatasource);
2031:                    create_query.table("tbltest").column("firstcol",
2032:                            String.class, 50).column("lastcol", String.class,
2033:                            50);
2034:                    manager.executeUpdate(create_query);
2035:
2036:                    Select select_query = null;
2037:                    select_query = new Select(mDatasource);
2038:                    select_query.from("tbltest").field("firstcol").where(
2039:                            "lastcol", "=", "Doe");
2040:
2041:                    manager.executeUseFirstCharacterStream(select_query,
2042:                            new ReaderUser() {
2043:                                public Object useReader(Reader reader)
2044:                                        throws InnerClassException {
2045:                                    assertNull(reader);
2046:
2047:                                    return null;
2048:                                }
2049:                            });
2050:
2051:                    manager.executeUpdate(new Insert(mDatasource).into(
2052:                            "tbltest")
2053:                            .fields(
2054:                                    new String[] { "firstcol", "John",
2055:                                            "lastcol", "Doe" }));
2056:                    manager.executeUpdate(new Insert(mDatasource).into(
2057:                            "tbltest").fields(
2058:                            new String[] { "firstcol", "Piet", "lastcol",
2059:                                    "Smith" }));
2060:
2061:                    manager.executeUseFirstCharacterStream(select_query,
2062:                            new ReaderUser() {
2063:                                public Object useReader(Reader reader)
2064:                                        throws InnerClassException {
2065:                                    assertNotNull(reader);
2066:
2067:                                    try {
2068:                                        assertEquals("John", FileUtils
2069:                                                .readString(reader));
2070:                                    } catch (FileUtilsErrorException e) {
2071:                                        assertTrue(ExceptionUtils
2072:                                                .getExceptionStackTrace(e),
2073:                                                false);
2074:                                    }
2075:
2076:                                    return null;
2077:                                }
2078:                            });
2079:
2080:                    select_query = new Select(mDatasource);
2081:                    select_query.from("tbltest").field("firstcol")
2082:                            .whereParameter("lastcol", "=");
2083:                    manager.executeUseFirstCharacterStream(select_query,
2084:                            new ReaderUser() {
2085:                                public Object useReader(Reader reader)
2086:                                        throws InnerClassException {
2087:                                    assertNotNull(reader);
2088:
2089:                                    try {
2090:                                        assertEquals("Piet", FileUtils
2091:                                                .readString(reader));
2092:                                    } catch (FileUtilsErrorException e) {
2093:                                        assertTrue(ExceptionUtils
2094:                                                .getExceptionStackTrace(e),
2095:                                                false);
2096:                                    }
2097:
2098:                                    return null;
2099:                                }
2100:                            }, new DbPreparedStatementHandler() {
2101:                                public void setParameters(
2102:                                        DbPreparedStatement statement) {
2103:                                    statement.setString("lastcol", "Smith");
2104:                                }
2105:                            });
2106:                } catch (DatabaseException e) {
2107:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2108:                }
2109:            }
2110:
2111:            public void testExecuteGetFirstCharacterStreamConcludeErrors() {
2112:                DbQueryManager manager = new DbQueryManager(mDatasource);
2113:                try {
2114:                    CreateTable create_query = new CreateTable(mDatasource);
2115:                    create_query.table("tbltest").column("name", String.class,
2116:                            50);
2117:                    manager.executeUpdate(create_query);
2118:
2119:                    Select select_query = null;
2120:                    select_query = new Select(mDatasource);
2121:                    select_query.from("tbltest").field("name").where("name",
2122:                            "=", "me");
2123:                    try {
2124:                        manager.executeUseFirstCharacterStream(select_query,
2125:                                new ReaderUser() {
2126:                                    public Object useReader(Reader reader)
2127:                                            throws InnerClassException {
2128:                                        assertNotNull(reader);
2129:
2130:                                        return null;
2131:                                    }
2132:                                }, new DbPreparedStatementHandler() {
2133:                                    public Object concludeResults(
2134:                                            DbResultSet resultSet)
2135:                                            throws SQLException {
2136:                                        return resultSet.getString("unknown");
2137:                                    }
2138:                                });
2139:                        fail();
2140:                    } catch (DatabaseException e) {
2141:                        assertTrue(true);
2142:                    }
2143:                } catch (DatabaseException e) {
2144:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2145:                }
2146:            }
2147:
2148:            public void testIllegalExecuteGetFirstBinaryStream() {
2149:                DbQueryManager manager = new DbQueryManager(mDatasource);
2150:                try {
2151:                    manager.executeUseFirstBinaryStream(null, null);
2152:                    fail();
2153:                } catch (IllegalArgumentException e) {
2154:                    assertTrue(true);
2155:                }
2156:                try {
2157:                    manager.executeUseFirstBinaryStream(new Select(mDatasource)
2158:                            .from("tbltest"), null);
2159:                    fail();
2160:                } catch (IllegalArgumentException e) {
2161:                    assertTrue(true);
2162:                }
2163:            }
2164:
2165:            public void testExecuteGetFirstBinaryStream() {
2166:                DbQueryManager manager = new DbQueryManager(mDatasource);
2167:                try {
2168:                    CreateTable create_query = new CreateTable(mDatasource);
2169:                    if (mDatasource.getAliasedDriver().equals(
2170:                            "org.apache.derby.jdbc.EmbeddedDriver")
2171:                            || mDatasource.getAliasedDriver().equals(
2172:                                    "com.mckoi.JDBCDriver")) {
2173:                        create_query.table("tbltest").column("firstcol",
2174:                                Blob.class).column("lastcol", String.class, 50);
2175:                    } else {
2176:                        create_query.table("tbltest").column("firstcol",
2177:                                String.class).column("lastcol", String.class,
2178:                                50);
2179:                    }
2180:                    manager.executeUpdate(create_query);
2181:
2182:                    Select select_query = null;
2183:                    select_query = new Select(mDatasource);
2184:                    select_query.from("tbltest").field("firstcol").where(
2185:                            "lastcol", "=", "Doe");
2186:
2187:                    manager.executeUseFirstBinaryStream(select_query,
2188:                            new InputStreamUser() {
2189:                                public Object useInputStream(InputStream stream)
2190:                                        throws InnerClassException {
2191:                                    assertNull(stream);
2192:
2193:                                    return null;
2194:                                }
2195:                            });
2196:
2197:                    manager.executeUpdate(new Insert(mDatasource).into(
2198:                            "tbltest").fieldParameter("firstcol").field(
2199:                            "lastcol", "Doe"),
2200:                            new DbPreparedStatementHandler() {
2201:                                public void setParameters(
2202:                                        DbPreparedStatement statement) {
2203:                                    if (mDatasource
2204:                                            .getAliasedDriver()
2205:                                            .equals(
2206:                                                    "org.apache.derby.jdbc.EmbeddedDriver")
2207:                                            || mDatasource
2208:                                                    .getAliasedDriver()
2209:                                                    .equals(
2210:                                                            "com.mckoi.JDBCDriver")
2211:                                            || mDatasource.getAliasedDriver()
2212:                                                    .equals("org.h2.Driver")) {
2213:                                        try {
2214:                                            statement.setBytes("firstcol",
2215:                                                    "John".getBytes("UTF-8"));
2216:                                        } catch (UnsupportedEncodingException e) {
2217:                                            assertTrue(ExceptionUtils
2218:                                                    .getExceptionStackTrace(e),
2219:                                                    false);
2220:                                        }
2221:                                    } else {
2222:                                        statement.setString("firstcol", "John");
2223:                                    }
2224:                                }
2225:                            });
2226:                    manager.executeUpdate(new Insert(mDatasource).into(
2227:                            "tbltest").fieldParameter("firstcol").field(
2228:                            "lastcol", "Smith"),
2229:                            new DbPreparedStatementHandler() {
2230:                                public void setParameters(
2231:                                        DbPreparedStatement statement) {
2232:                                    if (mDatasource
2233:                                            .getAliasedDriver()
2234:                                            .equals(
2235:                                                    "org.apache.derby.jdbc.EmbeddedDriver")
2236:                                            || mDatasource
2237:                                                    .getAliasedDriver()
2238:                                                    .equals(
2239:                                                            "com.mckoi.JDBCDriver")
2240:                                            || mDatasource.getAliasedDriver()
2241:                                                    .equals("org.h2.Driver")) {
2242:                                        try {
2243:                                            statement.setBytes("firstcol",
2244:                                                    "Piet".getBytes("UTF-8"));
2245:                                        } catch (UnsupportedEncodingException e) {
2246:                                            assertTrue(ExceptionUtils
2247:                                                    .getExceptionStackTrace(e),
2248:                                                    false);
2249:                                        }
2250:                                    } else {
2251:                                        statement.setString("firstcol", "Piet");
2252:                                    }
2253:                                }
2254:                            });
2255:
2256:                    manager.executeUseFirstBinaryStream(select_query,
2257:                            new InputStreamUser() {
2258:                                public Object useInputStream(InputStream stream)
2259:                                        throws InnerClassException {
2260:                                    assertNotNull(stream);
2261:                                    try {
2262:                                        assertEquals("John", FileUtils
2263:                                                .readString(stream, "UTF-8"));
2264:                                    } catch (FileUtilsErrorException e) {
2265:                                        assertTrue(ExceptionUtils
2266:                                                .getExceptionStackTrace(e),
2267:                                                false);
2268:                                    }
2269:
2270:                                    return null;
2271:                                }
2272:                            });
2273:
2274:                    select_query = new Select(mDatasource);
2275:                    select_query.from("tbltest").field("firstcol")
2276:                            .whereParameter("lastcol", "=");
2277:                    manager.executeUseFirstBinaryStream(select_query,
2278:                            new InputStreamUser() {
2279:                                public Object useInputStream(InputStream stream)
2280:                                        throws InnerClassException {
2281:                                    assertNotNull(stream);
2282:                                    try {
2283:                                        assertEquals("Piet", FileUtils
2284:                                                .readString(stream));
2285:                                    } catch (FileUtilsErrorException e) {
2286:                                        assertTrue(ExceptionUtils
2287:                                                .getExceptionStackTrace(e),
2288:                                                false);
2289:                                    }
2290:
2291:                                    return null;
2292:                                }
2293:                            }, new DbPreparedStatementHandler() {
2294:                                public void setParameters(
2295:                                        DbPreparedStatement statement) {
2296:                                    statement.setString("lastcol", "Smith");
2297:                                }
2298:                            });
2299:                } catch (DatabaseException e) {
2300:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2301:                }
2302:            }
2303:
2304:            public void testExecuteGetFirstBinaryStreamConcludeErrors() {
2305:                DbQueryManager manager = new DbQueryManager(mDatasource);
2306:                try {
2307:                    CreateTable create_query = new CreateTable(mDatasource);
2308:                    create_query.table("tbltest").column("name", String.class,
2309:                            50);
2310:                    manager.executeUpdate(create_query);
2311:
2312:                    Select select_query = null;
2313:                    select_query = new Select(mDatasource);
2314:                    select_query.from("tbltest").field("name").where("name",
2315:                            "=", "me");
2316:                    try {
2317:                        manager.executeUseFirstBinaryStream(select_query,
2318:                                new InputStreamUser() {
2319:                                    public Object useInputStream(
2320:                                            InputStream stream)
2321:                                            throws InnerClassException {
2322:                                        assertNotNull(stream);
2323:
2324:                                        return null;
2325:                                    }
2326:                                }, new DbPreparedStatementHandler() {
2327:                                    public Object concludeResults(
2328:                                            DbResultSet resultSet)
2329:                                            throws SQLException {
2330:                                        return resultSet.getString("unknown");
2331:                                    }
2332:                                });
2333:                        fail();
2334:                    } catch (DatabaseException e) {
2335:                        assertTrue(true);
2336:                    }
2337:                } catch (DatabaseException e) {
2338:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2339:                }
2340:            }
2341:
2342:            public void testIllegalExecuteFetchFirst() {
2343:                DbQueryManager manager = new DbQueryManager(mDatasource);
2344:                try {
2345:                    manager.executeFetchFirst(null, null);
2346:                    fail();
2347:                } catch (IllegalArgumentException e) {
2348:                    assertTrue(true);
2349:                }
2350:            }
2351:
2352:            public void testExecuteFetchFirst() {
2353:                DbQueryManager manager = new DbQueryManager(mDatasource);
2354:                try {
2355:                    CreateTable create_query = new CreateTable(mDatasource);
2356:                    create_query.table("tbltest").column("datacol",
2357:                            String.class, 50).column("valuecol", String.class,
2358:                            50);
2359:                    manager.executeUpdate(create_query);
2360:
2361:                    Insert insert_query = new Insert(mDatasource);
2362:                    insert_query.into("tbltest").field("datacol", "sometext")
2363:                            .field("valuecol", "thevalue");
2364:                    assertEquals(1, manager.executeUpdate(insert_query));
2365:
2366:                    Select select_query = new Select(mDatasource);
2367:                    select_query.from("tbltest").field("datacol");
2368:
2369:                    DbRowProcessorSuccess processor = null;
2370:
2371:                    processor = new DbRowProcessorSuccess();
2372:                    assertTrue(manager.executeFetchFirst(select_query,
2373:                            processor));
2374:                    assertEquals(processor.getCounter(), 1);
2375:                    assertTrue(manager.executeFetchFirst(select_query,
2376:                            processor));
2377:                    assertEquals(processor.getCounter(), 2);
2378:
2379:                    select_query.whereParameter("valuecol", "=");
2380:
2381:                    processor = new DbRowProcessorSuccess();
2382:                    assertTrue(manager.executeFetchFirst(select_query,
2383:                            processor, new DbPreparedStatementHandler() {
2384:                                public void setParameters(
2385:                                        DbPreparedStatement statement) {
2386:                                    statement.setString("valuecol", "thevalue");
2387:                                }
2388:                            }));
2389:                    assertEquals(processor.getCounter(), 1);
2390:
2391:                    processor = new DbRowProcessorSuccess();
2392:                    assertFalse(manager.executeFetchFirst(select_query,
2393:                            processor, new DbPreparedStatementHandler() {
2394:                                public void setParameters(
2395:                                        DbPreparedStatement statement) {
2396:                                    statement.setString("valuecol",
2397:                                            "not present");
2398:                                }
2399:                            }));
2400:                    assertEquals(processor.getCounter(), 0);
2401:                } catch (DatabaseException e) {
2402:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2403:                }
2404:            }
2405:
2406:            public void testExecuteFetchFirstConcludeError() {
2407:                DbQueryManager manager = new DbQueryManager(mDatasource);
2408:                try {
2409:                    CreateTable create_query = new CreateTable(mDatasource);
2410:                    create_query.table("tbltest").column("datacol",
2411:                            String.class, 50).column("valuecol", String.class,
2412:                            50);
2413:                    manager.executeUpdate(create_query);
2414:
2415:                    Select select_query = new Select(mDatasource);
2416:                    select_query.from("tbltest").field("datacol");
2417:
2418:                    try {
2419:                        manager.executeFetchFirst(select_query, null,
2420:                                new DbPreparedStatementHandler() {
2421:                                    public Object concludeResults(
2422:                                            DbResultSet resultSet)
2423:                                            throws SQLException {
2424:                                        return resultSet.getString("unknown");
2425:                                    }
2426:                                });
2427:                        fail();
2428:                    } catch (DatabaseException e) {
2429:                        assertTrue(true);
2430:                    }
2431:                } catch (DatabaseException e) {
2432:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2433:                }
2434:            }
2435:
2436:            public void testIllegalExecuteFetchFirstBean() {
2437:                DbQueryManager manager = new DbQueryManager(mDatasource);
2438:                try {
2439:                    manager.executeFetchFirstBean(null, null);
2440:                    fail();
2441:                } catch (IllegalArgumentException e) {
2442:                    assertTrue(true);
2443:                }
2444:            }
2445:
2446:            public void testExecuteFetchFirstBean() {
2447:                DbQueryManager manager = new DbQueryManager(mDatasource);
2448:                try {
2449:                    CreateTable create_query = new CreateTable(mDatasource);
2450:                    create_query.table("tbltest").columns(
2451:                            BeanImplConstrained.class);
2452:                    manager.executeUpdate(create_query);
2453:
2454:                    Insert insert_query = new Insert(mDatasource);
2455:                    insert_query.into("tbltest").fields(
2456:                            BeanImplConstrained.getPopulatedBean());
2457:                    assertEquals(1, manager.executeUpdate(insert_query));
2458:
2459:                    Select select_query = new Select(mDatasource);
2460:                    select_query.from("tbltest");
2461:
2462:                    BeanImplConstrained bean = null;
2463:
2464:                    bean = manager.executeFetchFirstBean(select_query,
2465:                            BeanImplConstrained.class);
2466:                    assertNotNull(bean);
2467:
2468:                    BeanImplConstrained bean_populated = BeanImplConstrained
2469:                            .getPopulatedBean();
2470:                    assertEquals(bean.getPropertyString(), bean_populated
2471:                            .getPropertyString());
2472:                    assertEquals(bean.getPropertyStringbuffer().toString(),
2473:                            bean_populated.getPropertyStringbuffer().toString());
2474:                    // don't compare milliseconds since each db stores it differently
2475:                    assertEquals(
2476:                            (bean.getPropertyDate().getTime() / 1000) * 1000,
2477:                            (bean_populated.getPropertyDate().getTime() / 1000) * 1000);
2478:                    assertEquals((bean.getPropertyCalendar().getTime()
2479:                            .getTime() / 1000) * 1000,
2480:                            (bean_populated.getPropertyCalendar().getTime()
2481:                                    .getTime() / 1000) * 1000);
2482:                    assertEquals(
2483:                            (bean.getPropertyTimestamp().getTime() / 1000) * 1000,
2484:                            (bean_populated.getPropertyTimestamp().getTime() / 1000) * 1000);
2485:                    assertEquals(bean.getPropertySqlDate().toString(),
2486:                            bean_populated.getPropertySqlDate().toString());
2487:                    assertEquals(bean.getPropertyTime().toString(),
2488:                            bean_populated.getPropertyTime().toString());
2489:                    assertEquals(bean.isPropertyBoolean(), bean_populated
2490:                            .isPropertyBoolean());
2491:                    assertEquals(bean.getPropertyChar(), bean_populated
2492:                            .getPropertyChar());
2493:                    assertFalse(bean.getPropertyByte() == bean_populated
2494:                            .getPropertyByte()); // byte is not saved
2495:                    assertEquals(bean.getPropertyDouble(), bean_populated
2496:                            .getPropertyDouble(), 0.001);
2497:                    assertEquals(bean.getPropertyFloat(), bean_populated
2498:                            .getPropertyFloat(), 0.001);
2499:                    assertEquals(bean.getPropertyDoubleObject().doubleValue(),
2500:                            bean_populated.getPropertyDoubleObject()
2501:                                    .doubleValue(), 0.01);
2502:                    assertEquals(bean.getPropertyFloatObject().floatValue(),
2503:                            bean_populated.getPropertyFloatObject()
2504:                                    .floatValue(), 0.01);
2505:                    assertEquals(bean.getPropertyInt(), bean_populated
2506:                            .getPropertyInt());
2507:                    assertFalse(bean.getPropertyLong() == bean_populated
2508:                            .getPropertyLong()); // long is not persistent
2509:                    assertEquals(bean.getPropertyShort(), bean_populated
2510:                            .getPropertyShort());
2511:                    assertEquals(bean.getPropertyBigDecimal(), bean_populated
2512:                            .getPropertyBigDecimal());
2513:
2514:                    select_query.whereParameter("propertyString", "=");
2515:
2516:                    bean = manager.executeFetchFirstBean(select_query,
2517:                            BeanImplConstrained.class,
2518:                            new DbPreparedStatementHandler() {
2519:                                public void setParameters(
2520:                                        DbPreparedStatement statement) {
2521:                                    statement.setString("propertyString",
2522:                                            "someotherstring");
2523:                                }
2524:                            });
2525:                    assertNotNull(bean);
2526:                    assertEquals(bean.getPropertyString(), bean_populated
2527:                            .getPropertyString());
2528:                    assertEquals(bean.getPropertyStringbuffer().toString(),
2529:                            bean_populated.getPropertyStringbuffer().toString());
2530:                    assertEquals(
2531:                            (bean.getPropertyDate().getTime() / 1000) * 1000,
2532:                            (bean_populated.getPropertyDate().getTime() / 1000) * 1000);
2533:                    assertEquals((bean.getPropertyCalendar().getTime()
2534:                            .getTime() / 1000) * 1000,
2535:                            (bean_populated.getPropertyCalendar().getTime()
2536:                                    .getTime() / 1000) * 1000);
2537:                    assertEquals(
2538:                            (bean.getPropertyTimestamp().getTime() / 1000) * 1000,
2539:                            (bean_populated.getPropertyTimestamp().getTime() / 1000) * 1000);
2540:                    assertEquals(bean.getPropertySqlDate().toString(),
2541:                            bean_populated.getPropertySqlDate().toString());
2542:                    assertEquals(bean.getPropertyTime().toString(),
2543:                            bean_populated.getPropertyTime().toString());
2544:                    assertEquals(bean.isPropertyBoolean(), bean_populated
2545:                            .isPropertyBoolean());
2546:                    assertEquals(bean.getPropertyChar(), bean_populated
2547:                            .getPropertyChar());
2548:                    assertFalse(bean.getPropertyByte() == bean_populated
2549:                            .getPropertyByte()); // byte is not saved
2550:                    assertEquals(bean.getPropertyDouble(), bean_populated
2551:                            .getPropertyDouble(), 0.001);
2552:                    assertEquals(bean.getPropertyFloat(), bean_populated
2553:                            .getPropertyFloat(), 0.001);
2554:                    assertEquals(bean.getPropertyDoubleObject().doubleValue(),
2555:                            bean_populated.getPropertyDoubleObject()
2556:                                    .doubleValue(), 0.01);
2557:                    assertEquals(bean.getPropertyFloatObject().floatValue(),
2558:                            bean_populated.getPropertyFloatObject()
2559:                                    .floatValue(), 0.01);
2560:                    assertEquals(bean.getPropertyInt(), bean_populated
2561:                            .getPropertyInt());
2562:                    assertFalse(bean.getPropertyLong() == bean_populated
2563:                            .getPropertyLong()); // long is not persistent
2564:                    assertEquals(bean.getPropertyShort(), bean_populated
2565:                            .getPropertyShort());
2566:                    assertEquals(bean.getPropertyBigDecimal(), bean_populated
2567:                            .getPropertyBigDecimal());
2568:
2569:                    bean = manager.executeFetchFirstBean(select_query,
2570:                            BeanImplConstrained.class,
2571:                            new DbPreparedStatementHandler() {
2572:                                public void setParameters(
2573:                                        DbPreparedStatement statement) {
2574:                                    statement.setString("propertyString",
2575:                                            "not present");
2576:                                }
2577:                            });
2578:                    assertNull(bean);
2579:                } catch (DatabaseException e) {
2580:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2581:                }
2582:            }
2583:
2584:            public void testExecuteFetchFirstBeanConcludeError() {
2585:                DbQueryManager manager = new DbQueryManager(mDatasource);
2586:                try {
2587:                    CreateTable create_query = new CreateTable(mDatasource);
2588:                    create_query.table("tbltest").columns(
2589:                            BeanImplConstrained.class);
2590:                    manager.executeUpdate(create_query);
2591:
2592:                    Select select_query = new Select(mDatasource);
2593:                    select_query.from("tbltest");
2594:
2595:                    try {
2596:                        manager.executeFetchFirstBean(select_query,
2597:                                BeanImplConstrained.class,
2598:                                new DbPreparedStatementHandler() {
2599:                                    public Object concludeResults(
2600:                                            DbResultSet resultSet)
2601:                                            throws SQLException {
2602:                                        return resultSet.getString("unknown");
2603:                                    }
2604:                                });
2605:                        fail();
2606:                    } catch (DatabaseException e) {
2607:                        assertTrue(true);
2608:                    }
2609:                } catch (DatabaseException e) {
2610:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2611:                }
2612:            }
2613:
2614:            public void testIllegalExecuteFetchAll() {
2615:                DbQueryManager manager = new DbQueryManager(mDatasource);
2616:                try {
2617:                    manager.executeFetchAll(null, null);
2618:                    fail();
2619:                } catch (IllegalArgumentException e) {
2620:                    assertTrue(true);
2621:                }
2622:            }
2623:
2624:            public void testExecuteFetchAll() {
2625:                DbQueryManager manager = new DbQueryManager(mDatasource);
2626:                try {
2627:                    CreateTable create_query = new CreateTable(mDatasource);
2628:                    create_query.table("tbltest").column("datacol",
2629:                            String.class, 50).column("valuecol", String.class,
2630:                            50);
2631:                    manager.executeUpdate(create_query);
2632:
2633:                    Insert insert_query = new Insert(mDatasource);
2634:                    insert_query.into("tbltest").field("datacol", "sometext1")
2635:                            .field("valuecol", "thevalue1");
2636:                    assertEquals(1, manager.executeUpdate(insert_query));
2637:                    insert_query.clear();
2638:                    insert_query.into("tbltest").field("datacol", "sometext2")
2639:                            .field("valuecol", "thevalue2");
2640:                    assertEquals(1, manager.executeUpdate(insert_query));
2641:                    insert_query.clear();
2642:                    insert_query.into("tbltest").field("datacol", "sometext2b")
2643:                            .field("valuecol", "thevalue2");
2644:                    assertEquals(1, manager.executeUpdate(insert_query));
2645:
2646:                    Select select_query = new Select(mDatasource);
2647:                    select_query.from("tbltest").field("datacol");
2648:
2649:                    DbRowProcessorSuccess processor = null;
2650:
2651:                    processor = new DbRowProcessorSuccess();
2652:                    assertTrue(manager.executeFetchAll(select_query, processor));
2653:                    assertEquals(processor.getCounter(), 2); // limited to maximum 2 by the rowprocessor
2654:
2655:                    select_query.whereParameter("valuecol", "=");
2656:
2657:                    processor = new DbRowProcessorSuccess();
2658:                    assertTrue(manager.executeFetchAll(select_query, processor,
2659:                            new DbPreparedStatementHandler() {
2660:                                public void setParameters(
2661:                                        DbPreparedStatement statement) {
2662:                                    statement
2663:                                            .setString("valuecol", "thevalue2");
2664:                                }
2665:                            }));
2666:                    assertEquals(processor.getCounter(), 2);
2667:
2668:                    processor = new DbRowProcessorSuccess();
2669:                    assertFalse(manager.executeFetchAll(select_query,
2670:                            processor, new DbPreparedStatementHandler() {
2671:                                public void setParameters(
2672:                                        DbPreparedStatement statement) {
2673:                                    statement.setString("valuecol",
2674:                                            "not present");
2675:                                }
2676:                            }));
2677:                    assertEquals(processor.getCounter(), 0);
2678:                } catch (DatabaseException e) {
2679:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2680:                }
2681:            }
2682:
2683:            public void testExecuteFetchAllConcludeError() {
2684:                DbQueryManager manager = new DbQueryManager(mDatasource);
2685:                try {
2686:                    CreateTable create_query = new CreateTable(mDatasource);
2687:                    create_query.table("tbltest").column("datacol",
2688:                            String.class, 50).column("valuecol", String.class,
2689:                            50);
2690:                    manager.executeUpdate(create_query);
2691:
2692:                    Select select_query = new Select(mDatasource);
2693:                    select_query.from("tbltest").field("datacol");
2694:
2695:                    try {
2696:                        DbRowProcessorSuccess processor = new DbRowProcessorSuccess();
2697:                        manager.executeFetchAll(select_query, processor,
2698:                                new DbPreparedStatementHandler() {
2699:                                    public Object concludeResults(
2700:                                            DbResultSet resultSet)
2701:                                            throws SQLException {
2702:                                        return resultSet.getString("unknown");
2703:                                    }
2704:                                });
2705:                        fail();
2706:                    } catch (DatabaseException e) {
2707:                        assertTrue(true);
2708:                    }
2709:                } catch (DatabaseException e) {
2710:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2711:                }
2712:            }
2713:
2714:            public void testIllegalExecuteFetchAllBeans() {
2715:                DbQueryManager manager = new DbQueryManager(mDatasource);
2716:                try {
2717:                    manager.executeFetchAllBeans(null, null);
2718:                    fail();
2719:                } catch (IllegalArgumentException e) {
2720:                    assertTrue(true);
2721:                }
2722:            }
2723:
2724:            public void testExecuteFetchAllBeans() {
2725:                DbQueryManager manager = new DbQueryManager(mDatasource);
2726:                try {
2727:                    CreateTable create_query = new CreateTable(mDatasource);
2728:                    create_query.table("tbltest").columns(
2729:                            BeanImplConstrained.class);
2730:                    manager.executeUpdate(create_query);
2731:
2732:                    BeanImplConstrained bean = null;
2733:                    Insert insert_query = new Insert(mDatasource);
2734:                    bean = BeanImplConstrained.getPopulatedBean();
2735:                    bean.setPropertyString("someotherstring");
2736:                    bean.setPropertyStringbuffer(new StringBuffer(
2737:                            "someotherstringbuf1"));
2738:                    insert_query.into("tbltest").fields(bean);
2739:                    assertEquals(1, manager.executeUpdate(insert_query));
2740:                    insert_query.clear();
2741:                    bean = BeanImplConstrained.getPopulatedBean();
2742:                    bean.setPropertyString("one");
2743:                    bean.setPropertyStringbuffer(new StringBuffer(
2744:                            "someotherstringbuf2"));
2745:                    insert_query.into("tbltest").fields(bean);
2746:                    assertEquals(1, manager.executeUpdate(insert_query));
2747:                    insert_query.clear();
2748:                    bean = BeanImplConstrained.getPopulatedBean();
2749:                    bean.setPropertyString("tw''o");
2750:                    bean.setPropertyStringbuffer(new StringBuffer(
2751:                            "someotherstringbuf3"));
2752:                    insert_query.into("tbltest").fields(bean);
2753:                    assertEquals(1, manager.executeUpdate(insert_query));
2754:
2755:                    Select select_query = new Select(mDatasource);
2756:                    select_query.from("tbltest");
2757:
2758:                    BeanImplConstrained bean_populated = BeanImplConstrained
2759:                            .getPopulatedBean();
2760:                    List<BeanImplConstrained> beans = null;
2761:
2762:                    beans = manager.executeFetchAllBeans(select_query,
2763:                            BeanImplConstrained.class);
2764:                    assertNotNull(beans);
2765:                    assertEquals(beans.size(), 3);
2766:                    for (BeanImplConstrained bean2 : beans) {
2767:                        assertTrue(bean2.getPropertyString().equals(
2768:                                "someotherstring")
2769:                                || bean2.getPropertyString().equals("one")
2770:                                || bean2.getPropertyString().equals("tw''o"));
2771:                        assertTrue(bean2.getPropertyStringbuffer().toString()
2772:                                .equals("someotherstringbuf1")
2773:                                || bean2.getPropertyStringbuffer().toString()
2774:                                        .equals("someotherstringbuf2")
2775:                                || bean2.getPropertyStringbuffer().toString()
2776:                                        .equals("someotherstringbuf3"));
2777:                        // don't compare milliseconds since each db stores it differently
2778:                        assertEquals(
2779:                                (bean2.getPropertyDate().getTime() / 1000) * 1000,
2780:                                (bean_populated.getPropertyDate().getTime() / 1000) * 1000);
2781:                        assertEquals((bean2.getPropertyCalendar().getTime()
2782:                                .getTime() / 1000) * 1000,
2783:                                (bean_populated.getPropertyCalendar().getTime()
2784:                                        .getTime() / 1000) * 1000);
2785:                        assertEquals(
2786:                                (bean2.getPropertyTimestamp().getTime() / 1000) * 1000,
2787:                                (bean_populated.getPropertyTimestamp()
2788:                                        .getTime() / 1000) * 1000);
2789:                        assertEquals(bean2.getPropertySqlDate().toString(),
2790:                                bean_populated.getPropertySqlDate().toString());
2791:                        assertEquals(bean2.getPropertyTime().toString(),
2792:                                bean_populated.getPropertyTime().toString());
2793:                        assertEquals(bean2.isPropertyBoolean(), bean_populated
2794:                                .isPropertyBoolean());
2795:                        assertEquals(bean2.getPropertyChar(), bean_populated
2796:                                .getPropertyChar());
2797:                        assertFalse(bean2.getPropertyByte() == bean_populated
2798:                                .getPropertyByte()); // byte is not saved
2799:                        assertEquals(bean2.getPropertyDouble(), bean_populated
2800:                                .getPropertyDouble(), 0.001);
2801:                        assertEquals(bean2.getPropertyFloat(), bean_populated
2802:                                .getPropertyFloat(), 0.001);
2803:                        assertEquals(bean2.getPropertyDoubleObject()
2804:                                .doubleValue(), bean_populated
2805:                                .getPropertyDoubleObject().doubleValue(), 0.01);
2806:                        assertEquals(bean2.getPropertyFloatObject()
2807:                                .floatValue(), bean_populated
2808:                                .getPropertyFloatObject().floatValue(), 0.01);
2809:                        assertEquals(bean2.getPropertyInt(), bean_populated
2810:                                .getPropertyInt());
2811:                        assertFalse(bean2.getPropertyLong() == bean_populated
2812:                                .getPropertyLong()); // long is not persistent
2813:                        assertEquals(bean2.getPropertyShort(), bean_populated
2814:                                .getPropertyShort());
2815:                        assertEquals(bean2.getPropertyBigDecimal(),
2816:                                bean_populated.getPropertyBigDecimal());
2817:                    }
2818:
2819:                    select_query.whereParameter("propertyString", "=");
2820:
2821:                    beans = manager.executeFetchAllBeans(select_query,
2822:                            BeanImplConstrained.class,
2823:                            new DbPreparedStatementHandler() {
2824:                                public void setParameters(
2825:                                        DbPreparedStatement statement) {
2826:                                    statement
2827:                                            .setString("propertyString", "one");
2828:                                }
2829:                            });
2830:                    assertNotNull(beans);
2831:                    assertEquals(beans.size(), 1);
2832:                    BeanImplConstrained bean2 = beans.get(0);
2833:                    assertEquals(bean2.getPropertyString(), "one");
2834:                    assertEquals(bean2.getPropertyStringbuffer().toString(),
2835:                            "someotherstringbuf2");
2836:                    // don't compare milliseconds since each db stores it differently
2837:                    assertEquals(
2838:                            (bean2.getPropertyDate().getTime() / 1000) * 1000,
2839:                            (bean_populated.getPropertyDate().getTime() / 1000) * 1000);
2840:                    assertEquals((bean2.getPropertyCalendar().getTime()
2841:                            .getTime() / 1000) * 1000,
2842:                            (bean_populated.getPropertyCalendar().getTime()
2843:                                    .getTime() / 1000) * 1000);
2844:                    assertEquals(
2845:                            (bean2.getPropertyTimestamp().getTime() / 1000) * 1000,
2846:                            (bean_populated.getPropertyTimestamp().getTime() / 1000) * 1000);
2847:                    assertEquals(bean2.getPropertySqlDate().toString(),
2848:                            bean_populated.getPropertySqlDate().toString());
2849:                    assertEquals(bean2.getPropertyTime().toString(),
2850:                            bean_populated.getPropertyTime().toString());
2851:                    assertEquals(bean2.isPropertyBoolean(), bean_populated
2852:                            .isPropertyBoolean());
2853:                    assertEquals(bean2.getPropertyChar(), bean_populated
2854:                            .getPropertyChar());
2855:                    assertFalse(bean2.getPropertyByte() == bean_populated
2856:                            .getPropertyByte()); // byte is not saved
2857:                    assertEquals(bean2.getPropertyDouble(), bean_populated
2858:                            .getPropertyDouble(), 0.001);
2859:                    assertEquals(bean2.getPropertyFloat(), bean_populated
2860:                            .getPropertyFloat(), 0.001);
2861:                    assertEquals(bean2.getPropertyDoubleObject().doubleValue(),
2862:                            bean_populated.getPropertyDoubleObject()
2863:                                    .doubleValue(), 0.01);
2864:                    assertEquals(bean2.getPropertyFloatObject().floatValue(),
2865:                            bean_populated.getPropertyFloatObject()
2866:                                    .floatValue(), 0.01);
2867:                    assertEquals(bean2.getPropertyInt(), bean_populated
2868:                            .getPropertyInt());
2869:                    assertFalse(bean2.getPropertyLong() == bean_populated
2870:                            .getPropertyLong()); // long is not persistent
2871:                    assertEquals(bean2.getPropertyShort(), bean_populated
2872:                            .getPropertyShort());
2873:                    assertEquals(bean2.getPropertyBigDecimal(), bean_populated
2874:                            .getPropertyBigDecimal());
2875:
2876:                    beans = manager.executeFetchAllBeans(select_query,
2877:                            BeanImplConstrained.class,
2878:                            new DbPreparedStatementHandler() {
2879:                                public void setParameters(
2880:                                        DbPreparedStatement statement) {
2881:                                    statement.setString("propertyString",
2882:                                            "not present");
2883:                                }
2884:                            });
2885:                    assertNotNull(beans);
2886:                    assertEquals(beans.size(), 0);
2887:                } catch (DatabaseException e) {
2888:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2889:                }
2890:            }
2891:
2892:            public void testExecuteFetchAllBeansConcludeError() {
2893:                DbQueryManager manager = new DbQueryManager(mDatasource);
2894:                try {
2895:                    CreateTable create_query = new CreateTable(mDatasource);
2896:                    create_query.table("tbltest").columns(
2897:                            BeanImplConstrained.class);
2898:                    manager.executeUpdate(create_query);
2899:
2900:                    Select select_query = new Select(mDatasource);
2901:                    select_query.from("tbltest");
2902:
2903:                    try {
2904:                        manager.executeFetchAllBeans(select_query,
2905:                                BeanImplConstrained.class,
2906:                                new DbPreparedStatementHandler() {
2907:                                    public Object concludeResults(
2908:                                            DbResultSet resultSet)
2909:                                            throws SQLException {
2910:                                        return resultSet.getString("unknown");
2911:                                    }
2912:                                });
2913:                        fail();
2914:                    } catch (DatabaseException e) {
2915:                        assertTrue(true);
2916:                    }
2917:                } catch (DatabaseException e) {
2918:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2919:                }
2920:            }
2921:
2922:            public void testIllegalExecuteQueryDbPreparedStatementHandler() {
2923:                DbQueryManager manager = new DbQueryManager(mDatasource);
2924:                try {
2925:                    manager.executeQuery((Select) null,
2926:                            (DbPreparedStatementHandler) null);
2927:                    fail();
2928:                } catch (IllegalArgumentException e) {
2929:                    assertTrue(true);
2930:                }
2931:            }
2932:
2933:            public void testExecuteQueryDbPreparedStatementHandler() {
2934:                DbQueryManager manager = new DbQueryManager(mDatasource);
2935:                try {
2936:                    CreateTable create_query = new CreateTable(mDatasource);
2937:                    create_query.table("tbltest").column("firstcol",
2938:                            String.class, 50).column("lastcol", String.class,
2939:                            50);
2940:                    manager.executeUpdate(create_query);
2941:
2942:                    Select select_query = null;
2943:                    select_query = new Select(mDatasource);
2944:                    select_query.from("tbltest").where("lastcol", "=", "Doe");
2945:
2946:                    assertNull(manager.executeQuery(select_query,
2947:                            (DbPreparedStatementHandler) null));
2948:
2949:                    manager.executeUpdate(new Insert(mDatasource).into(
2950:                            "tbltest")
2951:                            .fields(
2952:                                    new String[] { "firstcol", "John",
2953:                                            "lastcol", "Doe" }));
2954:                    manager.executeUpdate(new Insert(mDatasource).into(
2955:                            "tbltest").fields(
2956:                            new String[] { "firstcol", "Piet", "lastcol",
2957:                                    "Smith" }));
2958:
2959:                    select_query = new Select(mDatasource);
2960:                    select_query.from("tbltest").whereParameter("lastcol", "=");
2961:                    assertEquals("Piet Smith", manager.executeQuery(
2962:                            select_query, new DbPreparedStatementHandler() {
2963:                                public void setParameters(
2964:                                        DbPreparedStatement statement) {
2965:                                    statement.setString("lastcol", "Smith");
2966:                                }
2967:
2968:                                public Object concludeResults(
2969:                                        DbResultSet resultSet)
2970:                                        throws SQLException {
2971:                                    if (resultSet.next()) {
2972:                                        return resultSet.getString("firstcol")
2973:                                                + " "
2974:                                                + resultSet
2975:                                                        .getString("lastcol");
2976:                                    }
2977:
2978:                                    return null;
2979:                                }
2980:                            }));
2981:                } catch (DatabaseException e) {
2982:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2983:                }
2984:            }
2985:
2986:            public void testExecuteQueryDbPreparedStatementHandlerConcludeErrors() {
2987:                DbQueryManager manager = new DbQueryManager(mDatasource);
2988:                try {
2989:                    CreateTable create_query = new CreateTable(mDatasource);
2990:                    create_query.table("tbltest").column("name", String.class,
2991:                            50);
2992:                    manager.executeUpdate(create_query);
2993:
2994:                    Select select_query = null;
2995:                    select_query = new Select(mDatasource);
2996:                    select_query.from("tbltest");
2997:                    try {
2998:                        manager.executeQuery(select_query,
2999:                                new DbPreparedStatementHandler() {
3000:                                    public Object concludeResults(
3001:                                            DbResultSet resultSet)
3002:                                            throws SQLException {
3003:                                        return resultSet.getString("unknown");
3004:                                    }
3005:                                });
3006:                        fail();
3007:                    } catch (DatabaseException e) {
3008:                        assertTrue(true);
3009:                    }
3010:                } catch (DatabaseException e) {
3011:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3012:                }
3013:            }
3014:
3015:            public void testIllegalExecuteQueryDbResultSetHandler() {
3016:                DbQueryManager manager = new DbQueryManager(mDatasource);
3017:                try {
3018:                    manager.executeQuery((Select) null,
3019:                            (DbResultSetHandler) null);
3020:                    fail();
3021:                } catch (IllegalArgumentException e) {
3022:                    assertTrue(true);
3023:                }
3024:            }
3025:
3026:            public void testExecuteQueryDbResultSetHandler() {
3027:                DbQueryManager manager = new DbQueryManager(mDatasource);
3028:                try {
3029:                    CreateTable create_query = new CreateTable(mDatasource);
3030:                    create_query.table("tbltest").column("firstcol",
3031:                            String.class, 50).column("lastcol", String.class,
3032:                            50);
3033:                    manager.executeUpdate(create_query);
3034:
3035:                    Select select_query = null;
3036:                    select_query = new Select(mDatasource);
3037:                    select_query.from("tbltest").where("lastcol", "=", "Doe");
3038:
3039:                    assertNull(manager.executeQuery(select_query,
3040:                            (DbResultSetHandler) null));
3041:
3042:                    manager.executeUpdate(new Insert(mDatasource).into(
3043:                            "tbltest")
3044:                            .fields(
3045:                                    new String[] { "firstcol", "John",
3046:                                            "lastcol", "Doe" }));
3047:                    manager.executeUpdate(new Insert(mDatasource).into(
3048:                            "tbltest").fields(
3049:                            new String[] { "firstcol", "Piet", "lastcol",
3050:                                    "Smith" }));
3051:
3052:                    select_query = new Select(mDatasource);
3053:                    select_query.from("tbltest").where("lastcol", "=", "Doe");
3054:                    assertEquals("John Doe", manager.executeQuery(select_query,
3055:                            new DbResultSetHandler() {
3056:                                public Object concludeResults(
3057:                                        DbResultSet resultSet)
3058:                                        throws SQLException {
3059:                                    if (resultSet.next()) {
3060:                                        return resultSet.getString("firstcol")
3061:                                                + " "
3062:                                                + resultSet
3063:                                                        .getString("lastcol");
3064:                                    }
3065:
3066:                                    return null;
3067:                                }
3068:                            }));
3069:                } catch (DatabaseException e) {
3070:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3071:                }
3072:            }
3073:
3074:            public void testExecuteQueryDbResultSetHandlerConcludeErrors() {
3075:                DbQueryManager manager = new DbQueryManager(mDatasource);
3076:                try {
3077:                    CreateTable create_query = new CreateTable(mDatasource);
3078:                    create_query.table("tbltest").column("name", String.class,
3079:                            50);
3080:                    manager.executeUpdate(create_query);
3081:
3082:                    Select select_query = null;
3083:                    select_query = new Select(mDatasource);
3084:                    select_query.from("tbltest");
3085:                    try {
3086:                        manager.executeQuery(select_query,
3087:                                new DbResultSetHandler() {
3088:                                    public Object concludeResults(
3089:                                            DbResultSet resultSet)
3090:                                            throws SQLException {
3091:                                        return resultSet.getString("unknown");
3092:                                    }
3093:                                });
3094:                        fail();
3095:                    } catch (DatabaseException e) {
3096:                        assertTrue(true);
3097:                    }
3098:                } catch (DatabaseException e) {
3099:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3100:                }
3101:            }
3102:
3103:            public void testReserveConnection() {
3104:                final DbQueryManager manager = new DbQueryManager(mDatasource);
3105:                try {
3106:                    assertEquals("test", manager
3107:                            .reserveConnection(new DbConnectionUser() {
3108:                                public Object useConnection(
3109:                                        final DbConnection connection) {
3110:                                    assertSame(manager.getConnection(),
3111:                                            connection);
3112:                                    new Thread() {
3113:                                        public void run() {
3114:                                            assertNotSame(manager
3115:                                                    .getConnection(),
3116:                                                    connection);
3117:                                        }
3118:                                    }.start();
3119:                                    return "test";
3120:                                }
3121:                            }));
3122:                } catch (DatabaseException e) {
3123:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3124:                }
3125:            }
3126:
3127:            public void testIllegalExecuteQuerySql() {
3128:                DbQueryManager manager = new DbQueryManager(mDatasource);
3129:                try {
3130:                    manager.executeQuery((ReadQuery) null);
3131:                    fail();
3132:                } catch (IllegalArgumentException e) {
3133:                    assertTrue(true);
3134:                }
3135:            }
3136:
3137:            public void testExecuteQueryBuilderSuccess() {
3138:                DbQueryManager manager = new DbQueryManager(mDatasource);
3139:                try {
3140:                    CreateTable create_query = new CreateTable(mDatasource);
3141:                    create_query.table("tbltest").column("column1",
3142:                            String.class, 50);
3143:                    manager.executeUpdate(create_query);
3144:
3145:                    Insert insert_query = new Insert(mDatasource);
3146:                    insert_query.into("tbltest").field("column1", "sometext");
3147:                    assertEquals(1, manager.executeUpdate(insert_query));
3148:
3149:                    Select select_query = new Select(mDatasource);
3150:                    select_query.from("tbltest").field("column1");
3151:                    DbStatement statement = manager.executeQuery(select_query);
3152:                    try {
3153:                        assertNotNull(statement);
3154:                    } finally {
3155:                        statement.close();
3156:                    }
3157:                } catch (DatabaseException e) {
3158:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3159:                }
3160:            }
3161:
3162:            public void testExecuteQueryBuilderError() {
3163:                DbQueryManager manager = new DbQueryManager(mDatasource);
3164:                try {
3165:                    CreateTable create_query = new CreateTable(mDatasource);
3166:                    create_query.table("tbltest").column("column1",
3167:                            String.class, 50);
3168:                    manager.executeUpdate(create_query);
3169:
3170:                    Insert insert_query = new Insert(mDatasource);
3171:                    insert_query.into("tbltest").field("column1", "sometext");
3172:                    assertEquals(1, manager.executeUpdate(insert_query));
3173:
3174:                    Select select_query = new Select(mDatasource);
3175:                    select_query.from("tbltest").field("column2");
3176:                    try {
3177:                        manager.executeQuery(select_query);
3178:                        fail();
3179:                    } catch (DatabaseException e) {
3180:                        assertTrue(true);
3181:                    }
3182:                } catch (DatabaseException e) {
3183:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3184:                }
3185:            }
3186:
3187:            public void testIllegalFetch() {
3188:                DbQueryManager manager = new DbQueryManager(mDatasource);
3189:                try {
3190:                    manager.fetch((ResultSet) null, null);
3191:                    fail();
3192:                } catch (IllegalArgumentException e) {
3193:                    assertTrue(true);
3194:                }
3195:            }
3196:
3197:            public void testFetchSuccess() {
3198:                DbQueryManager manager = new DbQueryManager(mDatasource);
3199:                try {
3200:                    CreateTable create_query = new CreateTable(mDatasource);
3201:                    create_query.table("tbltest").column("column1",
3202:                            String.class, 50);
3203:                    manager.executeUpdate(create_query);
3204:
3205:                    Insert insert_query = new Insert(mDatasource);
3206:                    insert_query.into("tbltest").field("column1", "sometext");
3207:                    assertEquals(1, manager.executeUpdate(insert_query));
3208:
3209:                    Select select_query = new Select(mDatasource);
3210:                    select_query.from("tbltest").field("column1");
3211:
3212:                    DbRowProcessorSuccess processor = new DbRowProcessorSuccess();
3213:                    DbStatement statement = null;
3214:                    DbResultSet resultset = null;
3215:                    try {
3216:                        statement = manager.executeQuery(select_query);
3217:                        resultset = statement.getResultSet();
3218:                        assertTrue(manager.fetch(resultset, processor));
3219:                        assertEquals(processor.getCounter(), 1);
3220:                        assertFalse(manager.fetch(resultset, processor));
3221:                        assertEquals(processor.getCounter(), 1);
3222:                    } finally {
3223:                        statement.close();
3224:                    }
3225:
3226:                    statement = manager.executeQuery(select_query);
3227:                    try {
3228:                        resultset = statement.getResultSet();
3229:                        assertTrue(manager.fetch(resultset));
3230:                        assertFalse(manager.fetch(resultset));
3231:                    } finally {
3232:                        statement.close();
3233:                    }
3234:                } catch (DatabaseException e) {
3235:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3236:                }
3237:            }
3238:
3239:            public void testFetchError() {
3240:                DbQueryManager manager = new DbQueryManager(mDatasource);
3241:                try {
3242:                    CreateTable create_query = new CreateTable(mDatasource);
3243:                    create_query.table("tbltest").column("column1",
3244:                            String.class, 50);
3245:                    manager.executeUpdate(create_query);
3246:
3247:                    Insert insert_query = new Insert(mDatasource);
3248:                    insert_query.into("tbltest").field("column1", "sometext");
3249:                    assertEquals(1, manager.executeUpdate(insert_query));
3250:
3251:                    Select select_query = new Select(mDatasource);
3252:                    select_query.from("tbltest").field("column1");
3253:
3254:                    DbStatement statement1 = manager.executeQuery(select_query);
3255:                    try {
3256:                        manager.fetch(statement1.getResultSet(),
3257:                                new DbRowProcessorError());
3258:                        fail();
3259:                    } catch (DatabaseException e) {
3260:                        assertTrue(true);
3261:                    } finally {
3262:                        statement1.close();
3263:                    }
3264:                } catch (DatabaseException e) {
3265:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3266:                }
3267:            }
3268:
3269:            public void testIllegalFetchAll() {
3270:                DbQueryManager manager = new DbQueryManager(mDatasource);
3271:                try {
3272:                    manager.fetchAll((ResultSet) null, null);
3273:                    fail();
3274:                } catch (IllegalArgumentException e) {
3275:                    assertTrue(true);
3276:                }
3277:            }
3278:
3279:            public void testFetchAllSuccess() {
3280:                DbQueryManager manager = new DbQueryManager(mDatasource);
3281:                try {
3282:                    CreateTable create_query = new CreateTable(mDatasource);
3283:                    create_query.table("tbltest").column("column1",
3284:                            String.class, 50);
3285:                    manager.executeUpdate(create_query);
3286:
3287:                    Insert insert_query = new Insert(mDatasource);
3288:                    insert_query.into("tbltest").field("column1", "sometext");
3289:                    assertEquals(1, manager.executeUpdate(insert_query));
3290:
3291:                    insert_query = new Insert(mDatasource);
3292:                    insert_query.into("tbltest").field("column1", "sometext2");
3293:                    assertEquals(1, manager.executeUpdate(insert_query));
3294:
3295:                    insert_query = new Insert(mDatasource);
3296:                    insert_query.into("tbltest").field("column1", "sometext2");
3297:                    assertEquals(1, manager.executeUpdate(insert_query));
3298:
3299:                    Select select_query = new Select(mDatasource);
3300:                    select_query.from("tbltest").field("column1");
3301:
3302:                    DbRowProcessorSuccess processor = new DbRowProcessorSuccess();
3303:                    DbStatement statement = manager.executeQuery(select_query);
3304:                    try {
3305:                        assertTrue(manager.fetchAll(statement.getResultSet(),
3306:                                processor));
3307:                    } finally {
3308:                        statement.close();
3309:                    }
3310:                    assertEquals(processor.getCounter(), 2);
3311:                } catch (DatabaseException e) {
3312:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3313:                }
3314:            }
3315:
3316:            public void testFetchAllError() {
3317:                DbQueryManager manager = new DbQueryManager(mDatasource);
3318:                try {
3319:                    CreateTable create_query = new CreateTable(mDatasource);
3320:                    create_query.table("tbltest").column("column1",
3321:                            String.class, 50);
3322:                    manager.executeUpdate(create_query);
3323:
3324:                    Insert insert_query = new Insert(mDatasource);
3325:                    insert_query.into("tbltest").field("column1", "sometext");
3326:                    assertEquals(1, manager.executeUpdate(insert_query));
3327:
3328:                    insert_query = new Insert(mDatasource);
3329:                    insert_query.into("tbltest").field("column1", "sometext2");
3330:                    assertEquals(1, manager.executeUpdate(insert_query));
3331:
3332:                    insert_query = new Insert(mDatasource);
3333:                    insert_query.into("tbltest").field("column1", "sometext2");
3334:                    assertEquals(1, manager.executeUpdate(insert_query));
3335:
3336:                    Select select_query = new Select(mDatasource);
3337:                    select_query.from("tbltest").field("column1");
3338:
3339:                    try {
3340:                        DbStatement statement = manager
3341:                                .executeQuery(select_query);
3342:                        try {
3343:                            manager.fetchAll(statement.getResultSet(),
3344:                                    new DbRowProcessorError());
3345:                        } finally {
3346:                            statement.close();
3347:                        }
3348:                        fail();
3349:                    } catch (DatabaseException e) {
3350:                        assertTrue(true);
3351:                    }
3352:                } catch (DatabaseException e) {
3353:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3354:                }
3355:            }
3356:
3357:            public void testClone() {
3358:                DbQueryManager manager = new DbQueryManager(mDatasource);
3359:
3360:                CreateTable create_query = new CreateTable(mDatasource);
3361:                create_query.table("tbltest").column("column1", String.class,
3362:                        50);
3363:                manager.executeUpdate(create_query);
3364:
3365:                DbQueryManager manager2 = (DbQueryManager) manager.clone();
3366:                DbPreparedStatement statement = null;
3367:                try {
3368:                    statement = manager2.getConnection().getPreparedStatement(
3369:                            new Insert(mDatasource).into("tbltest")
3370:                                    .fieldParameter("column1"));
3371:                    assertNotNull(statement);
3372:                } catch (DatabaseException e) {
3373:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
3374:                } finally {
3375:                    statement.close();
3376:                }
3377:            }
3378:
3379:            class DbRowProcessorSuccess extends DbRowProcessor {
3380:                private int mCounter = 0;
3381:
3382:                public DbRowProcessorSuccess() {
3383:                }
3384:
3385:                public boolean processRow(ResultSet resultSet)
3386:                        throws SQLException {
3387:                    if (2 == mCounter) {
3388:                        return false;
3389:                    }
3390:
3391:                    mCounter++;
3392:                    return true;
3393:                }
3394:
3395:                public int getCounter() {
3396:                    return mCounter;
3397:                }
3398:            }
3399:
3400:            class DbRowProcessorError extends DbRowProcessor {
3401:                public DbRowProcessorError() {
3402:                }
3403:
3404:                public boolean processRow(ResultSet resultSet)
3405:                        throws SQLException {
3406:                    resultSet.getString("inexistant_column");
3407:                    return false;
3408:                }
3409:            }
3410:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.