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

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


0001:        /*
0002:         * $Id: TestAxionResultSet.java,v 1.17 2007/11/13 19:04:01 rwald Exp $
0003:         * =======================================================================
0004:         * Copyright (c) 2002-2005 Axion Development Team.  All rights reserved.
0005:         *  
0006:         * Redistribution and use in source and binary forms, with or without 
0007:         * modification, are permitted provided that the following conditions 
0008:         * are met:
0009:         * 
0010:         * 1. Redistributions of source code must retain the above 
0011:         *    copyright notice, this list of conditions and the following 
0012:         *    disclaimer. 
0013:         *   
0014:         * 2. Redistributions in binary form must reproduce the above copyright 
0015:         *    notice, this list of conditions and the following disclaimer in 
0016:         *    the documentation and/or other materials provided with the 
0017:         *    distribution. 
0018:         *   
0019:         * 3. The names "Tigris", "Axion", nor the names of its contributors may 
0020:         *    not be used to endorse or promote products derived from this 
0021:         *    software without specific prior written permission. 
0022:         *  
0023:         * 4. Products derived from this software may not be called "Axion", nor 
0024:         *    may "Tigris" or "Axion" appear in their names without specific prior
0025:         *    written permission.
0026:         *   
0027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
0028:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
0029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0030:         * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
0031:         * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
0032:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
0033:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
0034:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
0035:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
0036:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
0037:         * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038:         * =======================================================================
0039:         */
0040:
0041:        package org.axiondb.jdbc;
0042:
0043:        import java.io.File;
0044:        import java.io.InputStreamReader;
0045:        import java.math.BigDecimal;
0046:        import java.sql.Blob;
0047:        import java.sql.Clob;
0048:        import java.sql.Connection;
0049:        import java.sql.Date;
0050:        import java.sql.ResultSet;
0051:        import java.sql.SQLException;
0052:        import java.sql.Statement;
0053:        import java.sql.Time;
0054:        import java.sql.Timestamp;
0055:        import java.util.Calendar;
0056:        import java.util.TimeZone;
0057:
0058:        import junit.framework.Test;
0059:        import junit.framework.TestCase;
0060:        import junit.framework.TestSuite;
0061:        import junit.textui.TestRunner;
0062:
0063:        import org.axiondb.Database;
0064:        import org.axiondb.Table;
0065:        import org.axiondb.engine.Databases;
0066:        import org.axiondb.engine.tables.MemoryTable;
0067:
0068:        /**
0069:         * @version $Revision: 1.17 $ $Date: 2007/11/13 19:04:01 $
0070:         * @author Chuck Burdick
0071:         * @author Rodney Waldhoff
0072:         * @author Jonathan Giron
0073:         */
0074:        public class TestAxionResultSet extends TestCase {
0075:            // TODO: Revisit testUpdateXXX tests.
0076:            protected Table _table = null;
0077:            protected Connection _conn = null;
0078:            protected AxionStatement _stmt = null;
0079:            protected ResultSet _rset = null;
0080:
0081:            protected static int IMAX = 26;
0082:            protected static int JMAX = 10;
0083:
0084:            public TestAxionResultSet(String testName) {
0085:                super (testName);
0086:            }
0087:
0088:            public static void main(String args[]) {
0089:                TestRunner.run(suite());
0090:            }
0091:
0092:            public static Test suite() {
0093:                return new TestSuite(TestAxionResultSet.class);
0094:            }
0095:
0096:            public void setUp() throws Exception {
0097:                Database db = createDatabase();
0098:                _conn = new AxionConnection(db);
0099:            }
0100:
0101:            public void tearDown() throws Exception {
0102:                doCleanup();
0103:                dropDatabase();
0104:            }
0105:
0106:            public void testCreate() throws Exception {
0107:                createBasicTable();
0108:
0109:                assertNotNull("Should not be null", _rset);
0110:                boolean foundRows = false;
0111:                for (int i = 0; i < IMAX; i++) {
0112:                    for (int j = 0; j < JMAX; j++) {
0113:                        foundRows = true;
0114:                        assertTrue("Should have more rows", _rset.next());
0115:                        assertEquals("Should get letter back", String
0116:                                .valueOf((char) (65 + i)), _rset.getString(1));
0117:                        assertEquals("Should get number back", j, _rset
0118:                                .getInt(2));
0119:                    }
0120:                }
0121:                assertTrue("Should have found rows", foundRows);
0122:            }
0123:
0124:            public void testPrevious() throws Exception {
0125:                createBasicTable();
0126:                assertTrue("Should be able to reach last row in ResultSet",
0127:                        _rset.last());
0128:
0129:                _rset.afterLast();
0130:                assertTrue(_rset.isAfterLast());
0131:
0132:                boolean foundRows = false;
0133:                for (int i = IMAX - 1; i >= 0; i--) {
0134:                    for (int j = JMAX - 1; j >= 0; j--) {
0135:                        foundRows = true;
0136:                        assertTrue("Should have more rows going backwards",
0137:                                _rset.previous());
0138:                        assertEquals("Should get letter back", String
0139:                                .valueOf((char) (65 + i)), _rset.getString(1));
0140:                        assertEquals("Should get number back", j, _rset
0141:                                .getInt(2));
0142:                    }
0143:                }
0144:                assertTrue("Should have found rows", foundRows);
0145:            }
0146:
0147:            public void testGetType() throws Exception {
0148:                createBasicTable();
0149:                assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, _rset.getType());
0150:
0151:                Statement fwdOnlyStmt = _conn.createStatement();
0152:                ResultSet fwdOnlyRs = fwdOnlyStmt
0153:                        .executeQuery("select * from foo");
0154:                try {
0155:                    assertEquals(ResultSet.TYPE_FORWARD_ONLY, fwdOnlyRs
0156:                            .getType());
0157:                } finally {
0158:                    if (fwdOnlyRs != null) {
0159:                        fwdOnlyRs.close();
0160:                    }
0161:
0162:                    if (fwdOnlyStmt != null) {
0163:                        fwdOnlyStmt.close();
0164:                    }
0165:                }
0166:            }
0167:
0168:            public void testClearWarnings() throws Exception {
0169:                createBasicTable();
0170:
0171:                // currently clearWarnings is a no-op, but we can check that it doesn't throw an
0172:                // exception
0173:                _rset.clearWarnings();
0174:                assertNull(_rset.getWarnings());
0175:            }
0176:
0177:            public void testNegativeGets() throws Exception {
0178:                createBasicTable();
0179:
0180:                // rows overflow
0181:                try {
0182:                    _rset.getDate(100);
0183:                    fail("Expected SQLException");
0184:                } catch (SQLException e) {
0185:                    // expected
0186:                }
0187:
0188:                try {
0189:                    _rset.getInt(100);
0190:                    fail("Expected SQLException");
0191:                } catch (SQLException e) {
0192:                    // expected
0193:                }
0194:
0195:                try {
0196:                    _rset.getLong(100);
0197:                    fail("Expected SQLException");
0198:                } catch (SQLException e) {
0199:                    // expected
0200:                }
0201:
0202:                // wrong data type
0203:                _rset.beforeFirst();
0204:                for (int i = 0; i < IMAX; i++) {
0205:                    for (int j = 0; j < JMAX; j++) {
0206:                        assertTrue("Should have more rows", _rset.next());
0207:                        try {
0208:                            _rset.getDate(1);
0209:                            fail("Expected SQLException");
0210:                        } catch (SQLException e) {
0211:                            // expected
0212:                        }
0213:                    }
0214:                }
0215:            }
0216:
0217:            public void testNextThrowsExceptionAfterClose() throws Exception {
0218:                createBasicTable();
0219:
0220:                assertTrue(_rset.next());
0221:                _rset.close();
0222:                try {
0223:                    _rset.next();
0224:                    fail("Expected SQLException");
0225:                } catch (SQLException e) {
0226:                    // expected
0227:                }
0228:            }
0229:
0230:            public void testNegativeCursor() throws Exception {
0231:                AxionResultSet rset = new AxionResultSet(null, null, null);
0232:                try {
0233:                    rset.beforeFirst();
0234:                    fail("Expected SQLException");
0235:                } catch (SQLException e) {
0236:                    //expect
0237:                }
0238:
0239:                try {
0240:                    rset.next();
0241:                    fail("Expected SQLException");
0242:                } catch (SQLException e) {
0243:                    //expect
0244:                }
0245:            }
0246:
0247:            public void testCancelRowUpdates() throws Exception {
0248:                createUpdateTable();
0249:
0250:                _rset.next();
0251:                final Object oldValue1 = _rset.getObject(1);
0252:                final Object oldValue2 = _rset.getObject(2);
0253:                final Object oldValue3 = _rset.getObject(3);
0254:
0255:                _rset.updateObject(1, new Integer(Integer.MAX_VALUE));
0256:                _rset.updateObject(3, new Date(0L));
0257:                _rset.cancelRowUpdates();
0258:
0259:                // Check that old values are still there in the current row.
0260:                assertEquals(oldValue1, _rset.getObject(1));
0261:                assertEquals(oldValue2, _rset.getObject(2));
0262:                assertEquals(oldValue3, _rset.getObject(3));
0263:            }
0264:
0265:            public void testNegativeCancelRowUpdates() throws Exception {
0266:                createUpdateTable();
0267:                _rset.moveToInsertRow();
0268:
0269:                try {
0270:                    _rset.cancelRowUpdates();
0271:                    fail("Expected SQLException - cannot call cancelRowUpdates() when on insert row.");
0272:                } catch (SQLException expected) {
0273:                    // Expected
0274:                }
0275:            }
0276:
0277:            public void testAbsolute() throws Exception {
0278:                createUpdateTable();
0279:
0280:                _rset.absolute(2);
0281:                assertInMiddleInMultirowRS();
0282:                assertEquals(2, _rset.getInt("id"));
0283:
0284:                _rset.absolute(-2);
0285:                assertInMiddleInMultirowRS();
0286:                assertEquals(3, _rset.getInt("id"));
0287:
0288:                _rset.absolute(0);
0289:                assertBeforeFirst();
0290:
0291:                _rset.absolute(1);
0292:                assertFirstInMultirowRS();
0293:                assertEquals(1, _rset.getInt("id"));
0294:
0295:                _rset.absolute(4);
0296:                assertLastInMultirowRS();
0297:                assertEquals(4, _rset.getInt("id"));
0298:
0299:                _rset.absolute(3);
0300:                assertInMiddleInMultirowRS();
0301:                assertEquals(3, _rset.getInt("id"));
0302:
0303:                _rset.absolute(-1);
0304:                assertLastInMultirowRS();
0305:                assertEquals(4, _rset.getInt("id"));
0306:
0307:                _rset.absolute(-3);
0308:                assertInMiddleInMultirowRS();
0309:                assertEquals(2, _rset.getInt("id"));
0310:
0311:                _rset.absolute(-4);
0312:                assertFirstInMultirowRS();
0313:                assertEquals(1, _rset.getInt("id"));
0314:            }
0315:
0316:            public void testEmptyResultSet() throws Exception {
0317:                createEmptyTable();
0318:                assertEmptyResultSet();
0319:
0320:                assertFalse(_rset.next());
0321:                assertEmptyResultSet();
0322:
0323:                assertFalse(_rset.previous());
0324:                assertEmptyResultSet();
0325:
0326:                assertFalse(_rset.next());
0327:                assertEmptyResultSet();
0328:            }
0329:
0330:            public void testOneRowResultSet() throws Exception {
0331:                createOneRowTable();
0332:
0333:                // At start, just prior to row 1.
0334:                assertTrue(_rset.isBeforeFirst());
0335:
0336:                // Now at row 1.
0337:                assertTrue(_rset.next());
0338:                assertFalse(_rset.isAfterLast());
0339:                assertTrue(_rset.isFirst());
0340:                assertTrue(_rset.isLast());
0341:                assertEquals(1, _rset.getInt(1));
0342:
0343:                // Now after row 1.
0344:                assertFalse(_rset.next());
0345:                assertTrue(_rset.isAfterLast());
0346:
0347:                // Back to row 1.
0348:                assertTrue(_rset.previous());
0349:                assertTrue(_rset.isFirst());
0350:                assertTrue(_rset.isLast());
0351:                assertFalse(_rset.isAfterLast());
0352:                assertEquals(1, _rset.getInt(1));
0353:
0354:                // Now before row 1.
0355:                assertFalse(_rset.previous());
0356:                assertTrue(_rset.isBeforeFirst());
0357:
0358:                // Now forward to row 1.
0359:                assertTrue(_rset.next());
0360:                assertTrue(_rset.isFirst());
0361:                assertTrue(_rset.isLast());
0362:                assertFalse(_rset.isAfterLast());
0363:                assertEquals(1, _rset.getInt(1));
0364:            }
0365:
0366:            public void testPositionIndicators() throws Exception {
0367:                createUpdateTable();
0368:
0369:                assertBeforeFirst();
0370:
0371:                assertTrue(_rset.next());
0372:                assertEquals(1, _rset.getInt("id"));
0373:                assertFirstInMultirowRS();
0374:
0375:                assertTrue(_rset.next());
0376:                assertEquals(2, _rset.getInt("id"));
0377:                assertInMiddleInMultirowRS();
0378:
0379:                assertTrue(_rset.next());
0380:                assertEquals(3, _rset.getInt("id"));
0381:                assertInMiddleInMultirowRS();
0382:
0383:                assertTrue(_rset.next());
0384:                assertEquals(4, _rset.getInt("id"));
0385:                assertLastInMultirowRS();
0386:
0387:                assertFalse(_rset.next());
0388:                assertAfterLast();
0389:
0390:                assertTrue(_rset.previous());
0391:                assertEquals(4, _rset.getInt("id"));
0392:                assertLastInMultirowRS();
0393:
0394:                assertTrue(_rset.previous());
0395:                assertEquals(3, _rset.getInt("id"));
0396:                assertInMiddleInMultirowRS();
0397:
0398:                assertTrue(_rset.previous());
0399:                assertEquals(2, _rset.getInt("id"));
0400:                assertInMiddleInMultirowRS();
0401:
0402:                assertTrue(_rset.previous());
0403:                assertEquals(1, _rset.getInt("id"));
0404:                assertFirstInMultirowRS();
0405:
0406:                assertFalse(_rset.previous());
0407:                assertBeforeFirst();
0408:
0409:                _rset.afterLast();
0410:                assertAfterLast();
0411:
0412:                _rset.beforeFirst();
0413:                assertBeforeFirst();
0414:
0415:                _rset.relative(3);
0416:                assertEquals(3, _rset.getInt("id"));
0417:                assertInMiddleInMultirowRS();
0418:
0419:                _rset.relative(-2);
0420:                assertEquals(1, _rset.getInt("id"));
0421:                assertFirstInMultirowRS();
0422:
0423:                _rset.relative(3);
0424:                assertEquals(4, _rset.getInt("id"));
0425:                assertLastInMultirowRS();
0426:
0427:                _rset.relative(-1);
0428:                assertEquals(3, _rset.getInt("id"));
0429:                assertInMiddleInMultirowRS();
0430:
0431:                _rset.relative(2);
0432:                assertAfterLast();
0433:            }
0434:
0435:            public void testPreviousFollowingAfterLast() throws Exception {
0436:                createUpdateTable();
0437:                assertBeforeFirst();
0438:
0439:                _rset.afterLast();
0440:                assertTrue(_rset.previous());
0441:                assertTrue(_rset.previous());
0442:                assertTrue(_rset.next());
0443:                assertFalse(_rset.next());
0444:                assertTrue(_rset.isAfterLast());
0445:            }
0446:
0447:            public void testDeleteFirstThenOtherRows() throws Exception {
0448:                createUpdateTable();
0449:
0450:                // Delete first row using first.
0451:                _rset.first();
0452:                _rset.deleteRow();
0453:
0454:                // Per JDBC spec, cursor should now point to just before the next valid row, i.e., row 2.
0455:                // Advance the cursor and test that row 2 is the current row.
0456:                assertTrue(_rset.next());
0457:                assertEquals(2, _rset.getInt("id"));
0458:
0459:                // Now move forward to row 4, go back once to row 3, and delete it.
0460:                assertTrue(_rset.next());
0461:                assertTrue(_rset.next());
0462:                assertEquals(4, _rset.getInt("id"));
0463:                assertTrue(_rset.previous());
0464:                assertEquals(3, _rset.getInt("id"));
0465:                _rset.deleteRow();
0466:
0467:                // Per JDBC spec, cursor should now point to just before the next valid row, i.e., row 4.
0468:                // Advance the cursor and test that row 4 is the current row.
0469:                assertTrue(_rset.next());
0470:                assertEquals(4, _rset.getInt("id"));
0471:                assertTrue(_rset.isLast());
0472:
0473:                // Delete row 4.
0474:                _rset.deleteRow();
0475:                assertFalse(_rset.next());
0476:                assertAfterLast();
0477:
0478:                assertTrue(_rset.previous());
0479:                assertEquals(2, _rset.getInt("id"));
0480:                assertTrue(_rset.isFirst());
0481:            }
0482:
0483:            public void testDeleteRow2ThenOtherRows() throws Exception {
0484:                createUpdateTable();
0485:
0486:                // Delete row 2.
0487:                assertTrue(_rset.absolute(2));
0488:                _rset.deleteRow();
0489:
0490:                // Per JDBC spec, cursor should now point to just before the next valid row, i.e., row 3.
0491:                // Advance the cursor and test that row 3 is indeed the current row.
0492:                assertTrue(_rset.next());
0493:                assertEquals(3, _rset.getInt("id"));
0494:                assertInMiddleInMultirowRS();
0495:
0496:                // Move backward 1 row, then assert that this is the first row, then delete it.
0497:                assertTrue(_rset.previous());
0498:                assertEquals(1, _rset.getInt("id"));
0499:                assertFirstInMultirowRS();
0500:                _rset.deleteRow();
0501:
0502:                // Per JDBC spec, cursor should now point to just before the next valid row, i.e., row 3.
0503:                // Advance the cursor and test that row 3 is indeed the current row.
0504:                assertTrue(_rset.next());
0505:                assertEquals(3, _rset.getInt("id"));
0506:                assertTrue(_rset.isFirst());
0507:                _rset.deleteRow();
0508:
0509:                // Per JDBC spec, cursor should now point to just before the next valid row, i.e., row 4.
0510:                // Advance the cursor and test that row 4 is indeed the current row.
0511:                assertTrue(_rset.next());
0512:                assertEquals(4, _rset.getInt("id"));
0513:                _rset.deleteRow();
0514:
0515:                // There should be no more rows.
0516:                assertFalse(_rset.next());
0517:            }
0518:
0519:            public void testDeleteEndThenOtherRows() throws Exception {
0520:                createUpdateTable();
0521:
0522:                // Delete last item (row 4).
0523:                assertTrue(_rset.last());
0524:                _rset.deleteRow();
0525:
0526:                assertFalse(_rset.isLast());
0527:                assertTrue(_rset.isAfterLast());
0528:
0529:                // Move back 2 rows, then move ahead and assert that row 3 is the last row.
0530:                assertTrue(_rset.previous());
0531:                assertTrue(_rset.previous());
0532:                assertTrue(_rset.next());
0533:                assertTrue(_rset.isLast());
0534:
0535:                // Move back to original row 2 and delete it.
0536:                assertTrue(_rset.previous());
0537:                assertEquals(2, _rset.getInt("id"));
0538:                _rset.deleteRow();
0539:
0540:                // Now verify that we are on the last row (#2 of 2 remaining rows)
0541:                assertTrue(_rset.next());
0542:                assertTrue(_rset.isLast());
0543:                assertEquals(3, _rset.getInt("id"));
0544:                assertFalse(_rset.next());
0545:
0546:                // Now go back and delete row 1.
0547:                assertTrue(_rset.first());
0548:                assertTrue(_rset.isFirst());
0549:                assertFalse(_rset.isBeforeFirst());
0550:                _rset.deleteRow();
0551:
0552:                assertTrue(_rset.next());
0553:                assertTrue(_rset.isFirst());
0554:            }
0555:
0556:            public void testNegativeDeleteRow() throws Exception {
0557:                createBasicTable();
0558:                try {
0559:                    _rset.deleteRow();
0560:                    fail("Expected SQLException - not an updateable ResultSet.");
0561:                } catch (SQLException expected) {
0562:                    // expected.
0563:                }
0564:
0565:                createUpdateTable();
0566:                _rset.moveToInsertRow();
0567:                try {
0568:                    _rset.deleteRow();
0569:                    fail("Expected SQLException - cannot call deleteRow() when on insert row.");
0570:                } catch (SQLException expected) {
0571:                    // expected.
0572:                }
0573:            }
0574:
0575:            public void testMoveToCurrentRow() throws Exception {
0576:                createBasicTable();
0577:                try {
0578:                    _rset.moveToCurrentRow();
0579:                    fail("Expected SQLException - not an updateable ResultSet.");
0580:                } catch (SQLException expected) {
0581:                    // expected.
0582:                }
0583:                _rset.close();
0584:
0585:                createUpdateTable();
0586:                _rset.moveToCurrentRow();
0587:            }
0588:
0589:            public void testMoveToInsertRow() throws Exception {
0590:                createBasicTable();
0591:                try {
0592:                    _rset.moveToInsertRow();
0593:                    fail("Expected SQLException - not an updateable ResultSet");
0594:                } catch (SQLException ignore) {
0595:                    // expected.
0596:                }
0597:                _rset.close();
0598:
0599:                createUpdateTable();
0600:                _rset.moveToInsertRow();
0601:            }
0602:
0603:            public void testInsertRowOnce() throws Exception {
0604:                createUpdateTableWithNotNullColumn();
0605:                _rset.next();
0606:
0607:                // Remember values of current row for comparison later after invoking moveToCurrentRow().
0608:                final Object currentValue1 = _rset.getObject(1);
0609:                final Object currentValue2 = _rset.getObject(2);
0610:                final Object currentValue3 = _rset.getObject(3);
0611:                final Object currentValue4 = _rset.getObject(4);
0612:                final Object currentValue5 = _rset.getObject(5);
0613:                final Object currentValue6 = _rset.getObject(6);
0614:
0615:                try {
0616:                    _rset.insertRow();
0617:                    fail("Expected SQLException");
0618:                } catch (SQLException expected) {
0619:                    // expected - _rset is not yet on insert row.
0620:                }
0621:
0622:                final Object newValue1 = new Integer(Integer.MAX_VALUE);
0623:                final Object newValue2 = "MAX_VALUE";
0624:                final Object newValue6 = Boolean.TRUE;
0625:
0626:                _rset.moveToInsertRow();
0627:
0628:                _rset.updateObject(1, newValue1);
0629:                assertEquals(newValue1, _rset.getObject(1));
0630:                _rset.updateObject(2, newValue2);
0631:                assertEquals(newValue2, _rset.getObject(2));
0632:                _rset.updateObject(6, newValue6);
0633:                assertEquals(newValue6, _rset.getObject(6));
0634:                _rset.insertRow();
0635:
0636:                _rset.moveToCurrentRow();
0637:
0638:                // Check that current row values reflect those we saved earlier.
0639:                assertEquals(currentValue1, _rset.getObject(1));
0640:                assertEquals(currentValue2, _rset.getObject(2));
0641:                assertEquals(currentValue3, _rset.getObject(3));
0642:                assertEquals(currentValue4, _rset.getObject(4));
0643:                assertEquals(currentValue5, _rset.getObject(5));
0644:                assertEquals(currentValue6, _rset.getObject(6));
0645:
0646:                // Check that inserted row does indeed exist.
0647:                ResultSet inserted = null;
0648:                try {
0649:                    inserted = _stmt
0650:                            .executeQuery("select * from foo where id = "
0651:                                    + Integer.MAX_VALUE);
0652:                    inserted.next();
0653:
0654:                    assertEquals(newValue1, inserted.getObject(1));
0655:                    assertEquals(newValue2, inserted.getObject(2));
0656:                    assertNull(inserted.getObject(3));
0657:                    assertNull(inserted.getObject(4));
0658:                    assertNull(inserted.getObject(5));
0659:                    assertEquals(newValue6, inserted.getObject(6));
0660:                } finally {
0661:                    if (inserted != null) {
0662:                        inserted.close();
0663:                    }
0664:                }
0665:            }
0666:
0667:            public void testInsertRowMultipleTimes() throws Exception {
0668:                createUpdateTable();
0669:
0670:                assertTrue(_rset.next());
0671:
0672:                final Object newRow1Value1 = new Integer(Integer.MAX_VALUE - 1);
0673:                final Object newRow1Value2 = "MAX - 1";
0674:                final Object newRow1Value6 = Boolean.TRUE;
0675:
0676:                _rset.moveToInsertRow();
0677:
0678:                _rset.updateObject(1, newRow1Value1);
0679:                _rset.updateObject(2, newRow1Value2);
0680:                _rset.updateObject(6, newRow1Value6);
0681:
0682:                _rset.insertRow();
0683:
0684:                final Object newRow2Value1 = new Integer(Integer.MAX_VALUE);
0685:                final Object newRow2Value2 = "MAX_VALUE";
0686:
0687:                // Field 6 should still be the same as newRow1Value6. 
0688:                _rset.updateObject(1, newRow2Value1);
0689:                _rset.updateObject(2, newRow2Value2);
0690:
0691:                _rset.insertRow();
0692:                _rset.close();
0693:
0694:                // Check that inserted row does indeed exist.
0695:                ResultSet inserted = null;
0696:                try {
0697:                    inserted = _stmt
0698:                            .executeQuery("select * from foo where id > 4 order by id");
0699:
0700:                    inserted.next();
0701:                    assertEquals(newRow1Value1, inserted.getObject(1));
0702:                    assertEquals(newRow1Value2, inserted.getObject(2));
0703:                    assertNull(inserted.getObject(3));
0704:                    assertNull(inserted.getObject(4));
0705:                    assertNull(inserted.getObject(5));
0706:                    assertEquals(newRow1Value6, inserted.getObject(6));
0707:
0708:                    inserted.next();
0709:                    assertEquals(newRow2Value1, inserted.getObject(1));
0710:                    assertEquals(newRow2Value2, inserted.getObject(2));
0711:                    assertNull(inserted.getObject(3));
0712:                    assertNull(inserted.getObject(4));
0713:                    assertNull(inserted.getObject(5));
0714:
0715:                    // Since we didn't modify the value of field 6 in the first insert, it should be
0716:                    // the same for the second insert.
0717:                    assertEquals(newRow1Value6, inserted.getObject(6));
0718:                } finally {
0719:                    if (inserted != null) {
0720:                        inserted.close();
0721:                    }
0722:                }
0723:            }
0724:
0725:            public void testNegativeInsertRow() throws Exception {
0726:                createBasicTable();
0727:                try {
0728:                    _rset.insertRow();
0729:                    fail("Expected SQLException - not an updateable ResultSet.");
0730:                } catch (SQLException expected) {
0731:                    // Expected.
0732:                }
0733:
0734:                createUpdateTableWithNotNullColumn();
0735:                _rset.next();
0736:                _rset.moveToInsertRow();
0737:
0738:                final Object newValue1 = new Integer(Integer.MAX_VALUE);
0739:                final Object newValue2 = "MAX_VALUE";
0740:
0741:                _rset.updateObject(1, newValue1);
0742:                _rset.updateObject(2, newValue2);
0743:                try {
0744:                    _rset.insertRow();
0745:                    fail("Expected SQLException - non-null column not populated");
0746:                } catch (SQLException expected) {
0747:                    if (!"22004".equals(expected.getSQLState())) {
0748:                        fail("Expected SQLState 22004:  null value not allowed");
0749:                    }
0750:                }
0751:
0752:                _rset.moveToCurrentRow();
0753:                _rset.updateInt(1, 1000);
0754:                try {
0755:                    _rset.insertRow();
0756:                    fail("Expected SQLException - not on insert row");
0757:                } catch (SQLException expected) {
0758:                    // Expected.
0759:                }
0760:            }
0761:
0762:            public void testUpdateRow() throws Exception {
0763:                createUpdateTable();
0764:
0765:                final Object newValue1 = new Integer(Integer.MAX_VALUE);
0766:                final Object newValue2 = "MAX_VALUE";
0767:
0768:                while (_rset.next()) {
0769:                    Object oldValue3 = _rset.getObject(3);
0770:
0771:                    // TODO Test Date, Time and Timestamp when TimeZone complications are handled correctly.
0772:                    _rset.updateObject(1, newValue1);
0773:                    _rset.updateObject(2, newValue2);
0774:                    _rset.updateRow();
0775:
0776:                    // Check that updated values appear in the current row.
0777:                    assertEquals(newValue1, _rset.getObject(1));
0778:                    assertEquals(newValue2, _rset.getObject(2));
0779:                    assertEquals(oldValue3, _rset.getObject(3));
0780:                }
0781:
0782:                // Now open a new ResultSet and ensure that the changed columns are reflected
0783:                // there as well.
0784:                _rset.close();
0785:                _rset = _stmt.executeQuery("select * from foo");
0786:                while (_rset.next()) {
0787:                    assertEquals(newValue1, _rset.getObject(1));
0788:                    assertEquals(newValue2, _rset.getObject(2));
0789:                }
0790:
0791:                // Now close the ResultSet and Statement, create a read-only, forward-only
0792:                // statement and ensure that the changed columns are reflected in its 
0793:                // ResultSet as well.
0794:                _rset.close();
0795:                _stmt.close();
0796:                _stmt = (AxionStatement) _conn.createStatement();
0797:                _rset = _stmt.executeQuery("select * from foo");
0798:                while (_rset.next()) {
0799:                    assertEquals(newValue1, _rset.getObject(1));
0800:                    assertEquals(newValue2, _rset.getObject(2));
0801:                }
0802:            }
0803:
0804:            public void testUpdateNonNullColumn() throws Exception {
0805:                createUpdateTableWithNotNullColumn();
0806:
0807:                assertTrue(_rset.next());
0808:                _rset.updateNull(6);
0809:
0810:                try {
0811:                    _rset.updateRow();
0812:                    fail("Expected SQLException");
0813:                } catch (SQLException expected) {
0814:                    if (!"22004".equals(expected.getSQLState())) {
0815:                        fail("Expected SQLState 22004:  null value not allowed");
0816:                    }
0817:                }
0818:
0819:                _rset.updateBoolean(6, true);
0820:                _rset.updateRow();
0821:                assertTrue(_rset.getBoolean(6));
0822:            }
0823:
0824:            public void testNegativeUpdateRow() throws Exception {
0825:                createBasicTable();
0826:                try {
0827:                    _rset.deleteRow();
0828:                    fail("Expected SQLException - not an updateable ResultSet.");
0829:                } catch (SQLException expected) {
0830:                    // expected.
0831:                }
0832:
0833:                createUpdateTable();
0834:                _rset.moveToInsertRow();
0835:
0836:                try {
0837:                    _rset.updateRow();
0838:                } catch (SQLException expected) {
0839:                    // expected.
0840:                }
0841:            }
0842:
0843:            /*
0844:             * Class under test for void updateNull(int)
0845:             */
0846:            public void testUpdateNullint() throws Exception {
0847:                createUpdateTable();
0848:
0849:                // Test assertion that ResultSet has a current row
0850:                try {
0851:                    _rset.updateNull(1);
0852:                    fail("Expected SQLException");
0853:                } catch (SQLException ignore) {
0854:                    // expected.
0855:                }
0856:
0857:                // Set int column to null and verify.
0858:                _rset.next();
0859:                _rset.updateNull(1);
0860:                _rset.updateRow();
0861:                assertNull(_rset.getObject(1));
0862:
0863:                // Set varchar column to null and verify.
0864:                _rset.updateNull(2);
0865:                _rset.updateRow();
0866:                assertNull(_rset.getObject(2));
0867:
0868:                // Set date column to null and verify.
0869:                _rset.updateNull(3);
0870:                _rset.updateRow();
0871:                assertNull(_rset.getObject(3));
0872:
0873:                // Set time column to null and verify.
0874:                _rset.updateNull(4);
0875:                _rset.updateRow();
0876:                assertNull(_rset.getObject(4));
0877:
0878:                // Set time column to null and verify.
0879:                _rset.updateNull(5);
0880:                _rset.updateRow();
0881:                assertNull(_rset.getObject(5));
0882:            }
0883:
0884:            /*
0885:             * Class under test for void updateByte(int, byte)
0886:             */
0887:            public void testUpdateByteintbyte() throws Exception {
0888:                createUpdateTable();
0889:
0890:                // Test assertion that ResultSet has a current row
0891:                try {
0892:                    _rset.updateByte(1, (byte) 0);
0893:                    fail("Expected SQLException");
0894:                } catch (SQLException ignore) {
0895:                    // expected.
0896:                }
0897:
0898:                _rset.next();
0899:                _rset.updateByte(1, (byte) 127);
0900:                _rset.updateRow();
0901:                assertEquals((byte) 127, _rset.getByte(1));
0902:            }
0903:
0904:            /*
0905:             * Class under test for void updateDouble(int, double)
0906:             */
0907:            public void testUpdateDoubleintdouble() throws Exception {
0908:                createUpdateTable();
0909:
0910:                // Test assertion that ResultSet has a current row
0911:                try {
0912:                    _rset.updateDouble(1, 0.0);
0913:                    fail("Expected SQLException");
0914:                } catch (SQLException ignore) {
0915:                    // expected.
0916:                }
0917:
0918:                _rset.next();
0919:                _rset.updateDouble(1, 1234567890.0);
0920:                _rset.updateRow();
0921:                assertEquals(1234567890.0, _rset.getDouble(1), 0.00001);
0922:            }
0923:
0924:            /*
0925:             * Class under test for void updateFloat(int, float)
0926:             */
0927:            public void testUpdateFloatintfloat() throws Exception {
0928:                createUpdateTable();
0929:
0930:                // Test assertion that ResultSet has a current row
0931:                try {
0932:                    _rset.updateFloat(1, 0.0f);
0933:                    fail("Expected SQLException");
0934:                } catch (SQLException ignore) {
0935:                    // expected.
0936:                }
0937:
0938:                _rset.next();
0939:                _rset.updateFloat(1, 1234567.0f);
0940:                _rset.updateRow();
0941:                assertEquals(1234567.0f, _rset.getDouble(1), 0.00001);
0942:            }
0943:
0944:            /*
0945:             * Class under test for void updateInt(int, int)
0946:             */
0947:            public void testUpdateIntintint() throws Exception {
0948:                createUpdateTable();
0949:
0950:                // Test assertion that ResultSet has a current row
0951:                try {
0952:                    _rset.updateInt(1, 1);
0953:                    fail("Expected SQLException");
0954:                } catch (SQLException ignore) {
0955:                    // expected.
0956:                }
0957:
0958:                _rset.next();
0959:                _rset.updateInt(1, 1234567);
0960:                _rset.updateRow();
0961:                assertEquals(1234567, _rset.getInt(1));
0962:            }
0963:
0964:            /*
0965:             * Class under test for void updateLong(int, long)
0966:             */
0967:            public void testUpdateLongintlong() throws Exception {
0968:                createUpdateTable();
0969:
0970:                // Test assertion that ResultSet has a current row
0971:                try {
0972:                    _rset.updateLong(1, 0L);
0973:                    fail("Expected SQLException");
0974:                } catch (SQLException ignore) {
0975:                    // expected.
0976:                }
0977:
0978:                // Now test normal usage.
0979:                _rset.next();
0980:
0981:                final long newVal = 123457890L;
0982:                _rset.updateLong(1, newVal);
0983:                _rset.updateRow();
0984:                assertEquals(newVal, _rset.getInt(1));
0985:            }
0986:
0987:            /*
0988:             * Class under test for void updateShort(int, short)
0989:             */
0990:            public void testUpdateShortintshort() throws Exception {
0991:                createUpdateTable();
0992:
0993:                // Test assertion that ResultSet has a current row
0994:                try {
0995:                    _rset.updateShort(1, (short) 0);
0996:                    fail("Expected SQLException");
0997:                } catch (SQLException ignore) {
0998:                    // expected.
0999:                }
1000:
1001:                // Now test normal usage.
1002:                _rset.next();
1003:
1004:                _rset.updateShort(1, Short.MAX_VALUE);
1005:                _rset.updateRow();
1006:                assertEquals(Short.MAX_VALUE, _rset.getShort(1));
1007:            }
1008:
1009:            /*
1010:             * Class under test for void updateBoolean(int, boolean)
1011:             */
1012:            public void testUpdateBooleanintboolean() throws Exception {
1013:                createUpdateTable();
1014:
1015:                // Test assertion that ResultSet has a current row
1016:                try {
1017:                    _rset.updateBoolean(1, false);
1018:                    fail("Expected SQLException");
1019:                } catch (SQLException ignore) {
1020:                    // expected.
1021:                }
1022:
1023:                _rset.next();
1024:
1025:                // Expect a SQLException since boolean cannot be converted to a numeric in Axion.
1026:                try {
1027:                    _rset.updateBoolean(1, true);
1028:                } catch (SQLException ignore) {
1029:                    // expected.
1030:                }
1031:
1032:                // Now test normal usage.
1033:                final boolean newVal = true;
1034:                _rset.updateBoolean(6, newVal);
1035:                _rset.updateRow();
1036:                assertEquals(newVal, _rset.getBoolean(6));
1037:            }
1038:
1039:            /*
1040:             * Class under test for void updateBytes(int, byte[])
1041:             */
1042:            public void testUpdateBytesintbyteArray() throws Exception {
1043:                createUpdateTable();
1044:
1045:                // Test assertion that ResultSet has a current row
1046:                try {
1047:                    _rset.updateBytes(1, new byte[0]);
1048:                    fail("Expected SQLException");
1049:                } catch (SQLException ignore) {
1050:                    // expected.
1051:                }
1052:
1053:                // Now test normal usage.
1054:                _rset.next();
1055:            }
1056:
1057:            /*
1058:             * Class under test for void updateAsciiStream(int, InputStream, int)
1059:             */
1060:            public void testUpdateAsciiStreamintInputStreamint()
1061:                    throws Exception {
1062:                createUpdateTable();
1063:
1064:                // Test assertion that ResultSet has a current row
1065:                try {
1066:                    _rset.updateAsciiStream(1, System.in, 0);
1067:                    fail("Expected SQLException");
1068:                } catch (SQLException ignore) {
1069:                    // expected.
1070:                }
1071:
1072:                // Now test normal usage.
1073:                _rset.next();
1074:            }
1075:
1076:            /*
1077:             * Class under test for void updateBinaryStream(int, InputStream, int)
1078:             */
1079:            public void testUpdateBinaryStreamintInputStreamint()
1080:                    throws Exception {
1081:                createUpdateTable();
1082:
1083:                // Test assertion that ResultSet has a current row
1084:                try {
1085:                    _rset.updateBinaryStream(1, System.in, 0);
1086:                    fail("Expected SQLException");
1087:                } catch (SQLException ignore) {
1088:                    // expected.
1089:                }
1090:
1091:                // Now test normal usage.
1092:                _rset.next();
1093:            }
1094:
1095:            /*
1096:             * Class under test for void updateCharacterStream(int, Reader, int)
1097:             */
1098:            public void testUpdateCharacterStreamintReaderint()
1099:                    throws Exception {
1100:                createUpdateTable();
1101:
1102:                // Test assertion that ResultSet has a current row
1103:                try {
1104:                    _rset.updateCharacterStream(1, new InputStreamReader(
1105:                            System.in), 0);
1106:                    fail("Expected SQLException");
1107:                } catch (SQLException ignore) {
1108:                    // expected.
1109:                }
1110:
1111:                // Now test normal usage.
1112:                _rset.next();
1113:            }
1114:
1115:            /*
1116:             * Class under test for void updateObject(int, Object)
1117:             */
1118:            public void testUpdateObjectintObject_NoCurrentRow()
1119:                    throws Exception {
1120:                createUpdateTable();
1121:
1122:                // Test assertion that ResultSet has a current row
1123:                try {
1124:                    _rset.updateObject(1, new Object());
1125:                    fail("Expected SQLException");
1126:                } catch (SQLException ignore) {
1127:                    // expected.
1128:                }
1129:            }
1130:
1131:            public void testUpdateObjectintObject_Integer() throws Exception {
1132:                createUpdateTable();
1133:                _rset.next();
1134:
1135:                final Integer newInt = new Integer(123);
1136:
1137:                _rset.updateObject(1, newInt);
1138:                _rset.updateRow();
1139:                assertEquals(newInt, _rset.getObject(1));
1140:
1141:                _rset.updateObject(1, newInt.toString());
1142:                _rset.updateRow();
1143:                assertEquals(newInt, _rset.getObject(1));
1144:            }
1145:
1146:            public void testUpdateObjectintObject_Float() throws Exception {
1147:                createUpdateTable();
1148:                _rset.next();
1149:
1150:                final Float newFloat = new Float(456.0f);
1151:
1152:                _rset.updateObject(1, newFloat);
1153:                _rset.updateRow();
1154:                assertEquals(new Integer(newFloat.intValue()), _rset
1155:                        .getObject(1));
1156:
1157:                _rset.updateObject(1, newFloat.toString());
1158:                _rset.updateRow();
1159:                assertEquals(new Integer(newFloat.intValue()), _rset
1160:                        .getObject(1));
1161:            }
1162:
1163:            public void testUpdateObjectintObject_Double() throws Exception {
1164:                createUpdateTable();
1165:                _rset.next();
1166:
1167:                final Double newDouble = new Double(789.0);
1168:
1169:                _rset.updateObject(1, newDouble);
1170:                _rset.updateRow();
1171:                assertEquals(new Integer(newDouble.intValue()), _rset
1172:                        .getObject(1));
1173:
1174:                _rset.updateObject(1, newDouble.toString());
1175:                _rset.updateRow();
1176:                assertEquals(new Integer(newDouble.intValue()), _rset
1177:                        .getObject(1));
1178:            }
1179:
1180:            public void testUpdateObjectintObject_String() throws Exception {
1181:                createUpdateTable();
1182:                _rset.next();
1183:
1184:                final String newStr = "new string";
1185:
1186:                _rset.updateObject(2, newStr);
1187:                _rset.updateRow();
1188:                assertEquals(newStr, _rset.getObject(2));
1189:            }
1190:
1191:            public void testUpdateObjectintObject_DateTimeTimestamp()
1192:                    throws Exception {
1193:                createUpdateTable();
1194:                _rset.next();
1195:
1196:                final long now = System.currentTimeMillis();
1197:                final Date newDate = new Date(now);
1198:                final Time newTime = new Time(now);
1199:                final Timestamp newTimestamp = new Timestamp(now);
1200:
1201:                _rset.updateObject(3, newDate);
1202:                _rset.updateRow();
1203:                assertEquals(newDate, _rset.getObject(3));
1204:
1205:                _rset.updateObject(4, newTime);
1206:                _rset.updateRow();
1207:                assertEquals(newTime, _rset.getObject(4));
1208:
1209:                _rset.updateObject(5, newTimestamp);
1210:                _rset.updateRow();
1211:                assertEquals(newTimestamp, _rset.getObject(5));
1212:            }
1213:
1214:            public void testUpdateObjectintObject_Boolean() throws Exception {
1215:                createUpdateTable();
1216:                _rset.next();
1217:
1218:                final Boolean newVal = Boolean.TRUE;
1219:                _rset.updateObject(6, newVal);
1220:                _rset.updateRow();
1221:                assertEquals(newVal, _rset.getObject(6));
1222:            }
1223:
1224:            /*
1225:             * Class under test for void updateObject(int, Object, int)
1226:             */
1227:            public void testUpdateObjectintObjectint() throws Exception {
1228:                createUpdateTable();
1229:
1230:                // Test assertion that ResultSet has a current row
1231:                try {
1232:                    _rset.updateObject(1, new Object(), 0);
1233:                    fail("Expected SQLException");
1234:                } catch (SQLException ignore) {
1235:                    // expected.
1236:                }
1237:
1238:                // Now test normal usage.
1239:                _rset.next();
1240:            }
1241:
1242:            /*
1243:             * Class under test for void updateString(int, String)
1244:             */
1245:            public void testUpdateStringintString() throws Exception {
1246:                createUpdateTable();
1247:
1248:                // Test assertion that ResultSet has a current row
1249:                try {
1250:                    _rset.updateString(1, "");
1251:                    fail("Expected SQLException");
1252:                } catch (SQLException ignore) {
1253:                    // expected.
1254:                }
1255:
1256:                // Now test normal usage.
1257:                _rset.next();
1258:
1259:                final String newStr = "new string";
1260:                _rset.updateString(2, newStr);
1261:                _rset.updateRow();
1262:                assertEquals(newStr, _rset.getString(2));
1263:            }
1264:
1265:            /*
1266:             * Class under test for void updateNull(String)
1267:             */
1268:            public void testUpdateNullString() throws Exception {
1269:                createUpdateTable();
1270:
1271:                // Test assertion that ResultSet has a current row
1272:                try {
1273:                    _rset.updateNull("id");
1274:                    fail("Expected SQLException");
1275:                } catch (SQLException ignore) {
1276:                    // expected.
1277:                }
1278:
1279:                // Now test normal usage.
1280:                _rset.next();
1281:
1282:                _rset.updateNull("id");
1283:                _rset.updateRow();
1284:                _rset.getInt("id");
1285:                assertEquals(0, _rset.getInt("id"));
1286:                assertTrue(_rset.wasNull());
1287:            }
1288:
1289:            /*
1290:             * Class under test for void updateByte(String, byte)
1291:             */
1292:            public void testUpdateByteStringbyte() throws Exception {
1293:                createUpdateTable();
1294:
1295:                // Test assertion that ResultSet has a current row
1296:                try {
1297:                    _rset.updateByte("id", (byte) 0);
1298:                    fail("Expected SQLException");
1299:                } catch (SQLException ignore) {
1300:                    // expected.
1301:                }
1302:
1303:                // Now test normal usage.
1304:                _rset.next();
1305:
1306:                final byte newVal = (byte) 127;
1307:                _rset.updateByte("id", newVal);
1308:                _rset.updateRow();
1309:                assertEquals(newVal, _rset.getByte("id"));
1310:            }
1311:
1312:            /*
1313:             * Class under test for void updateDouble(String, double)
1314:             */
1315:            public void testUpdateDoubleStringdouble() throws Exception {
1316:                createUpdateTable();
1317:
1318:                // Test assertion that ResultSet has a current row
1319:                try {
1320:                    _rset.updateDouble("id", 0.0);
1321:                    fail("Expected SQLException");
1322:                } catch (SQLException ignore) {
1323:                    // expected.
1324:                }
1325:
1326:                // Now test normal usage.
1327:                _rset.next();
1328:
1329:                final double newVal = 42.0;
1330:                _rset.updateDouble("id", newVal);
1331:                _rset.updateRow();
1332:                assertEquals(newVal, _rset.getDouble("id"), 0.1);
1333:            }
1334:
1335:            /*
1336:             * Class under test for void updateFloat(String, float)
1337:             */
1338:            public void testUpdateFloatStringfloat() throws Exception {
1339:                createUpdateTable();
1340:
1341:                // Test assertion that ResultSet has a current row
1342:                try {
1343:                    _rset.updateFloat("id", 0.0f);
1344:                    fail("Expected SQLException");
1345:                } catch (SQLException ignore) {
1346:                    // expected.
1347:                }
1348:
1349:                // Now test normal usage.
1350:                _rset.next();
1351:
1352:                final float newVal = 42.0f;
1353:                _rset.updateFloat("id", newVal);
1354:                _rset.updateRow();
1355:                assertEquals(newVal, _rset.getFloat("id"), 0.1f);
1356:            }
1357:
1358:            /*
1359:             * Class under test for void updateInt(String, int)
1360:             */
1361:            public void testUpdateIntStringint() throws Exception {
1362:                createUpdateTable();
1363:
1364:                // Test assertion that ResultSet has a current row
1365:                try {
1366:                    _rset.updateInt("id", 0);
1367:                    fail("Expected SQLException");
1368:                } catch (SQLException ignore) {
1369:                    // expected.
1370:                }
1371:
1372:                // Now test normal usage.
1373:                _rset.next();
1374:
1375:                final int newVal = 150000;
1376:                _rset.updateInt("id", newVal);
1377:                _rset.updateRow();
1378:                assertEquals(newVal, _rset.getInt("id"));
1379:            }
1380:
1381:            /*
1382:             * Class under test for void updateLong(String, long)
1383:             */
1384:            public void testUpdateLongStringlong() throws Exception {
1385:                createUpdateTable();
1386:
1387:                // Test assertion that ResultSet has a current row
1388:                try {
1389:                    _rset.updateLong("id", 0L);
1390:                    fail("Expected SQLException");
1391:                } catch (SQLException ignore) {
1392:                    // expected.
1393:                }
1394:
1395:                // Now test normal usage.
1396:                _rset.next();
1397:
1398:                final long newVal = 150000L;
1399:                _rset.updateLong("id", newVal);
1400:                _rset.updateRow();
1401:                assertEquals(newVal, _rset.getLong("id"));
1402:            }
1403:
1404:            /*
1405:             * Class under test for void updateShort(String, short)
1406:             */
1407:            public void testUpdateShortStringshort() throws Exception {
1408:                createUpdateTable();
1409:
1410:                // Test assertion that ResultSet has a current row
1411:                try {
1412:                    _rset.updateShort("id", (short) 0);
1413:                    fail("Expected SQLException");
1414:                } catch (SQLException ignore) {
1415:                    // expected.
1416:                }
1417:
1418:                // Now test normal usage.
1419:                _rset.next();
1420:
1421:                final short newVal = (short) 32767;
1422:                _rset.updateShort("id", newVal);
1423:                _rset.updateRow();
1424:                assertEquals(newVal, _rset.getShort("id"));
1425:            }
1426:
1427:            /*
1428:             * Class under test for void updateBoolean(String, boolean)
1429:             */
1430:            public void testUpdateBooleanStringboolean() throws Exception {
1431:                createUpdateTable();
1432:
1433:                // Test assertion that ResultSet has a current row
1434:                try {
1435:                    _rset.updateBoolean("id", false);
1436:                    fail("Expected SQLException");
1437:                } catch (SQLException ignore) {
1438:                    // expected.
1439:                }
1440:
1441:                // Now test normal usage.
1442:                _rset.next();
1443:
1444:                final boolean newVal = true;
1445:                _rset.updateBoolean("bool", newVal);
1446:                _rset.updateRow();
1447:                assertTrue(_rset.getBoolean("bool"));
1448:            }
1449:
1450:            /*
1451:             * Class under test for void updateBytes(String, byte[])
1452:             */
1453:            public void testUpdateBytesStringbyteArray() throws Exception {
1454:                createUpdateTable();
1455:
1456:                // Test assertion that ResultSet has a current row
1457:                try {
1458:                    _rset.updateBytes("id", new byte[0]);
1459:                    fail("Expected SQLException");
1460:                } catch (SQLException ignore) {
1461:                    // expected.
1462:                }
1463:
1464:                // Now test normal usage.
1465:                _rset.next();
1466:            }
1467:
1468:            /*
1469:             * Class under test for void updateBigDecimal(int, BigDecimal)
1470:             */
1471:            public void testUpdateBigDecimalintBigDecimal() throws Exception {
1472:                createUpdateTable();
1473:
1474:                // Test assertion that ResultSet has a current row
1475:                try {
1476:                    _rset.updateBigDecimal("id", BigDecimal.valueOf(0L));
1477:                    fail("Expected SQLException");
1478:                } catch (SQLException ignore) {
1479:                    // expected.
1480:                }
1481:
1482:                // Now test normal usage.
1483:                _rset.next();
1484:
1485:            }
1486:
1487:            /*
1488:             * Class under test for void updateArray(int, Array)
1489:             */
1490:            public void testUpdateArrayintArray() throws Exception {
1491:                createUpdateTable();
1492:
1493:                // Test assertion that ResultSet has a current row
1494:                try {
1495:                    _rset.updateArray(1, null);
1496:                    fail("Expected SQLException");
1497:                } catch (SQLException ignore) {
1498:                    // expected.
1499:                }
1500:
1501:                // Now test normal usage.
1502:                _rset.next();
1503:            }
1504:
1505:            /*
1506:             * Class under test for void updateBlob(int, Blob)
1507:             */
1508:            public void testUpdateBlobintBlob() throws Exception {
1509:                createUpdateTable();
1510:
1511:                // Test assertion that ResultSet has a current row
1512:                try {
1513:                    _rset.updateBlob(1, (Blob) null);
1514:                    fail("Expected SQLException");
1515:                } catch (SQLException ignore) {
1516:                    // expected.
1517:                }
1518:
1519:                // Now test normal usage.
1520:                _rset.next();
1521:            }
1522:
1523:            /*
1524:             * Class under test for void updateClob(int, Clob)
1525:             */
1526:            public void testUpdateClobintClob() throws Exception {
1527:                createUpdateTable();
1528:
1529:                // Test assertion that ResultSet has a current row
1530:                try {
1531:                    _rset.updateClob("id", (Clob) null);
1532:                    fail("Expected SQLException");
1533:                } catch (SQLException ignore) {
1534:                    // expected.
1535:                }
1536:
1537:                // Now test normal usage.
1538:                _rset.next();
1539:            }
1540:
1541:            /*
1542:             * Class under test for void updateDate(int, Date)
1543:             */
1544:            public void testUpdateDateintDate() throws Exception {
1545:                createUpdateTable();
1546:
1547:                // Test assertion that ResultSet has a current row
1548:                try {
1549:                    _rset.updateDate(1, new Date(0L));
1550:                    fail("Expected SQLException");
1551:                } catch (SQLException ignore) {
1552:                    // expected.
1553:                }
1554:
1555:                // Now test normal usage.
1556:                _rset.next();
1557:
1558:                Calendar cal = Calendar
1559:                        .getInstance(TimeZone.getTimeZone("UTC"));
1560:                cal.set(2005, 3, 1, 0, 0, 0);
1561:                cal.set(Calendar.MILLISECOND, 0);
1562:
1563:                final Date newVal = new Date(cal.getTime().getTime());
1564:                _rset.updateDate("dt", newVal);
1565:                _rset.updateRow();
1566:
1567:                assertEquals(newVal, _rset.getDate("dt"));
1568:            }
1569:
1570:            /*
1571:             * Class under test for void updateRef(int, Ref)
1572:             */
1573:            public void testUpdateRefintRef() throws Exception {
1574:                createUpdateTable();
1575:
1576:                // Test assertion that ResultSet has a current row
1577:                try {
1578:                    _rset.updateRef(1, null);
1579:                    fail("Expected SQLException");
1580:                } catch (SQLException ignore) {
1581:                    // expected.
1582:                }
1583:
1584:                // Now test normal usage.
1585:                _rset.next();
1586:            }
1587:
1588:            /*
1589:             * Class under test for void updateTime(int, Time)
1590:             */
1591:            public void testUpdateTimeintTime() throws Exception {
1592:                createUpdateTable();
1593:
1594:                // Test assertion that ResultSet has a current row
1595:                try {
1596:                    _rset.updateTime(1, new Time(0L));
1597:                    fail("Expected SQLException");
1598:                } catch (SQLException ignore) {
1599:                    // expected.
1600:                }
1601:
1602:                // Now test normal usage.
1603:                _rset.next();
1604:
1605:                final Time newVal = new Time(System.currentTimeMillis());
1606:                _rset.updateTime(4, newVal);
1607:                _rset.updateRow();
1608:                assertEquals(newVal, _rset.getTime(4));
1609:            }
1610:
1611:            /*
1612:             * Class under test for void updateTimestamp(int, Timestamp)
1613:             */
1614:            public void testUpdateTimestampintTimestamp() throws Exception {
1615:                createUpdateTable();
1616:
1617:                // Test assertion that ResultSet has a current row
1618:                try {
1619:                    _rset.updateTimestamp(1, new Timestamp(0L));
1620:                    fail("Expected SQLException");
1621:                } catch (SQLException ignore) {
1622:                    // expected.
1623:                }
1624:
1625:                // Now test normal usage.
1626:                _rset.next();
1627:
1628:                final Timestamp newVal = new Timestamp(System
1629:                        .currentTimeMillis());
1630:                _rset.updateTimestamp(5, newVal);
1631:                _rset.updateRow();
1632:                assertEquals(newVal, _rset.getTimestamp(5));
1633:            }
1634:
1635:            /*
1636:             * Class under test for void updateAsciiStream(String, InputStream, int)
1637:             */
1638:            public void testUpdateAsciiStreamStringInputStreamint()
1639:                    throws Exception {
1640:                createUpdateTable();
1641:
1642:                // Test assertion that ResultSet has a current row
1643:                try {
1644:                    _rset.updateAsciiStream("foo", System.in, 0);
1645:                    fail("Expected SQLException");
1646:                } catch (SQLException ignore) {
1647:                    // expected.
1648:                }
1649:
1650:                // Now test normal usage.
1651:                _rset.next();
1652:
1653:            }
1654:
1655:            /*
1656:             * Class under test for void updateBinaryStream(String, InputStream, int)
1657:             */
1658:            public void testUpdateBinaryStreamStringInputStreamint()
1659:                    throws Exception {
1660:                createUpdateTable();
1661:
1662:                // Test assertion that ResultSet has a current row
1663:                try {
1664:                    _rset.updateBinaryStream("foo", System.in, 0);
1665:                    fail("Expected SQLException");
1666:                } catch (SQLException ignore) {
1667:                    // expected.
1668:                }
1669:
1670:                // Now test normal usage.
1671:                _rset.next();
1672:            }
1673:
1674:            /*
1675:             * Class under test for void updateCharacterStream(String, Reader, int)
1676:             */
1677:            public void testUpdateCharacterStreamStringReaderint()
1678:                    throws Exception {
1679:                createUpdateTable();
1680:
1681:                // Test assertion that ResultSet has a current row
1682:                try {
1683:                    _rset.updateCharacterStream("foo", new InputStreamReader(
1684:                            System.in), 0);
1685:                    fail("Expected SQLException");
1686:                } catch (SQLException ignore) {
1687:                    // expected.
1688:                }
1689:
1690:                // Now test normal usage.
1691:                _rset.next();
1692:            }
1693:
1694:            /*
1695:             * Class under test for void updateObject(String, Object)
1696:             */
1697:            public void testUpdateObjectStringObject_NoCurrentRow()
1698:                    throws Exception {
1699:                createUpdateTable();
1700:
1701:                // Test assertion that ResultSet has a current row
1702:                try {
1703:                    _rset.updateObject("id", new Object());
1704:                    fail("Expected SQLException");
1705:                } catch (SQLException ignore) {
1706:                    // expected.
1707:                }
1708:            }
1709:
1710:            public void testUpdateObjectStringObject_Integer() throws Exception {
1711:                createUpdateTable();
1712:                _rset.next();
1713:
1714:                final Integer newInt = new Integer(123);
1715:
1716:                _rset.updateObject("id", newInt);
1717:                _rset.updateRow();
1718:                assertEquals(newInt, _rset.getObject("id"));
1719:
1720:                _rset.updateObject("id", newInt.toString());
1721:                _rset.updateRow();
1722:                assertEquals(newInt, _rset.getObject("id"));
1723:            }
1724:
1725:            public void testUpdateObjectStringObject_Float() throws Exception {
1726:                createUpdateTable();
1727:                _rset.next();
1728:
1729:                final Float newFloat = new Float(456.0f);
1730:
1731:                _rset.updateObject("id", newFloat);
1732:                _rset.updateRow();
1733:                assertEquals(new Integer(newFloat.intValue()), _rset
1734:                        .getObject("id"));
1735:
1736:                _rset.updateObject("id", newFloat.toString());
1737:                _rset.updateRow();
1738:                assertEquals(new Integer(newFloat.intValue()), _rset
1739:                        .getObject("id"));
1740:            }
1741:
1742:            public void testUpdateObjectStringObject_Double() throws Exception {
1743:                createUpdateTable();
1744:                _rset.next();
1745:
1746:                final Double newDouble = new Double(789.0);
1747:
1748:                _rset.updateObject("id", newDouble);
1749:                _rset.updateRow();
1750:                assertEquals(new Integer(newDouble.intValue()), _rset
1751:                        .getObject("id"));
1752:
1753:                _rset.updateObject("id", newDouble.toString());
1754:                _rset.updateRow();
1755:                assertEquals(new Integer(newDouble.intValue()), _rset
1756:                        .getObject("id"));
1757:            }
1758:
1759:            public void testUpdateObjectStringObject_String() throws Exception {
1760:                createUpdateTable();
1761:                _rset.next();
1762:
1763:                final String newStr = "new string";
1764:
1765:                _rset.updateObject("str_10", newStr);
1766:                _rset.updateRow();
1767:                assertEquals(newStr, _rset.getObject("str_10"));
1768:            }
1769:
1770:            public void testUpdateObjectStringObject_DateTimeTimestamp()
1771:                    throws Exception {
1772:                createUpdateTable();
1773:                _rset.next();
1774:
1775:                final long now = System.currentTimeMillis();
1776:                final Date newDate = new Date(now);
1777:                final Time newTime = new Time(now);
1778:                final Timestamp newTimestamp = new Timestamp(now);
1779:
1780:                _rset.updateObject("dt", newDate);
1781:                _rset.updateRow();
1782:                assertEquals(newDate, _rset.getObject("dt"));
1783:
1784:                _rset.updateObject("tm", newTime);
1785:                _rset.updateRow();
1786:                assertEquals(newTime, _rset.getObject("tm"));
1787:
1788:                _rset.updateObject("ts", newTimestamp);
1789:                _rset.updateRow();
1790:                assertEquals(newTimestamp, _rset.getObject("ts"));
1791:            }
1792:
1793:            public void testUpdateObjectStringObject_DateTimeTimestamp_CaseInsensitivity()
1794:                    throws Exception {
1795:                createUpdateTable();
1796:                _rset.next();
1797:
1798:                final long now = System.currentTimeMillis();
1799:                final Date newDate = new Date(now);
1800:                final Time newTime = new Time(now);
1801:                final Timestamp newTimestamp = new Timestamp(now);
1802:
1803:                // Ensure case-insensitivity is functional.
1804:                _rset.updateObject("Dt", newDate);
1805:                _rset.updateRow();
1806:                assertEquals(newDate, _rset.getObject("Dt"));
1807:
1808:                _rset.updateObject("tM", newTime);
1809:                _rset.updateRow();
1810:                assertEquals(newTime, _rset.getObject("Tm"));
1811:
1812:                _rset.updateObject("Ts", newTimestamp);
1813:                _rset.updateRow();
1814:                assertEquals(newTimestamp, _rset.getObject("tS"));
1815:            }
1816:
1817:            public void testUpdateObjectStringObject_Boolean() throws Exception {
1818:                createUpdateTable();
1819:                _rset.next();
1820:
1821:                final Boolean newVal = Boolean.TRUE;
1822:                _rset.updateObject("bool", newVal);
1823:                _rset.updateRow();
1824:                assertEquals(newVal, _rset.getObject("bool"));
1825:            }
1826:
1827:            /*
1828:             * Class under test for void updateObject(String, Object, int)
1829:             */
1830:            public void testUpdateObjectStringObjectint() throws Exception {
1831:                createUpdateTable();
1832:
1833:                // Test assertion that ResultSet has a current row
1834:                try {
1835:                    _rset.updateObject("foo", new Object(), 0);
1836:                    fail("Expected SQLException");
1837:                } catch (SQLException ignore) {
1838:                    // expected.
1839:                }
1840:
1841:                // Now test normal usage.
1842:                _rset.next();
1843:            }
1844:
1845:            /*
1846:             * Class under test for void updateString(String, String)
1847:             */
1848:            public void testUpdateStringStringString() throws Exception {
1849:                createUpdateTable();
1850:
1851:                // Test assertion that ResultSet has a current row
1852:                try {
1853:                    _rset.updateString("foo", "");
1854:                    fail("Expected SQLException");
1855:                } catch (SQLException ignore) {
1856:                    // expected.
1857:                }
1858:
1859:                // Now test normal usage.
1860:                _rset.next();
1861:
1862:                final String newStr = "new string";
1863:                _rset.updateString("str_10", newStr);
1864:                _rset.updateRow();
1865:                assertEquals(newStr, _rset.getString("str_10"));
1866:            }
1867:
1868:            /*
1869:             * Class under test for void updateBigDecimal(String, BigDecimal)
1870:             */
1871:            public void testUpdateBigDecimalStringBigDecimal() throws Exception {
1872:                createUpdateTable();
1873:
1874:                // Test assertion that ResultSet has a current row
1875:                try {
1876:                    _rset.updateBigDecimal("foo", BigDecimal.valueOf(0L));
1877:                    fail("Expected SQLException");
1878:                } catch (SQLException ignore) {
1879:                    // expected.
1880:                }
1881:
1882:                // Now test normal usage.
1883:                _rset.next();
1884:            }
1885:
1886:            /*
1887:             * Class under test for void updateArray(String, Array)
1888:             */
1889:            public void testUpdateArrayStringArray() throws Exception {
1890:                createUpdateTable();
1891:
1892:                // Test assertion that ResultSet has a current row
1893:                try {
1894:                    _rset.updateArray("foo", null);
1895:                    fail("Expected SQLException");
1896:                } catch (SQLException ignore) {
1897:                    // expected.
1898:                }
1899:
1900:                // Now test normal usage.
1901:                _rset.next();
1902:            }
1903:
1904:            /*
1905:             * Class under test for void updateBlob(String, Blob)
1906:             */
1907:            public void testUpdateBlobStringBlob() throws Exception {
1908:                createUpdateTable();
1909:
1910:                // Test assertion that ResultSet has a current row
1911:                try {
1912:                    _rset.updateBlob("foo", (Blob) null);
1913:                    fail("Expected SQLException");
1914:                } catch (SQLException ignore) {
1915:                    // expected.
1916:                }
1917:
1918:                // Now test normal usage.
1919:                _rset.next();
1920:            }
1921:
1922:            /*
1923:             * Class under test for void updateClob(String, Clob)
1924:             */
1925:            public void testUpdateClobStringClob() throws Exception {
1926:                createUpdateTable();
1927:
1928:                // Test assertion that ResultSet has a current row
1929:                try {
1930:                    _rset.updateClob("foo", (Clob) null);
1931:                    fail("Expected SQLException");
1932:                } catch (SQLException ignore) {
1933:                    // expected.
1934:                }
1935:
1936:                // Now test normal usage.
1937:                _rset.next();
1938:            }
1939:
1940:            /*
1941:             * Class under test for void updateDate(String, Date)
1942:             */
1943:            public void testUpdateDateStringDate() throws Exception {
1944:                createUpdateTable();
1945:
1946:                // Test assertion that ResultSet has a current row
1947:                try {
1948:                    _rset.updateDate("foo", new Date(0L));
1949:                    fail("Expected SQLException");
1950:                } catch (SQLException ignore) {
1951:                    // expected.
1952:                }
1953:
1954:                // Now test normal usage.
1955:                _rset.next();
1956:
1957:                Calendar cal = Calendar
1958:                        .getInstance(TimeZone.getTimeZone("UTC"));
1959:                cal.set(2005, 3, 1, 0, 0, 0);
1960:                cal.set(Calendar.MILLISECOND, 0);
1961:
1962:                final Date newVal = new Date(cal.getTime().getTime());
1963:                _rset.updateDate("dt", newVal);
1964:                _rset.updateRow();
1965:
1966:                assertEquals(newVal, _rset.getDate("dt"));
1967:            }
1968:
1969:            /*
1970:             * Class under test for void updateRef(String, Ref)
1971:             */
1972:            public void testUpdateRefStringRef() throws Exception {
1973:                createUpdateTable();
1974:
1975:                // Test assertion that ResultSet has a current row
1976:                try {
1977:                    _rset.updateRef("foo", null);
1978:                    fail("Expected SQLException");
1979:                } catch (SQLException ignore) {
1980:                    // expected.
1981:                }
1982:
1983:                // Now test normal usage.
1984:                _rset.next();
1985:            }
1986:
1987:            /*
1988:             * Class under test for void updateTime(String, Time)
1989:             */
1990:            public void testUpdateTimeStringTime() throws Exception {
1991:                createUpdateTable();
1992:
1993:                // Test assertion that ResultSet has a current row
1994:                try {
1995:                    _rset.updateTime("foo", new Time(0L));
1996:                    fail("Expected SQLException");
1997:                } catch (SQLException ignore) {
1998:                    // expected.
1999:                }
2000:
2001:                // Now test normal usage.
2002:                _rset.next();
2003:
2004:                final Time newVal = new Time(System.currentTimeMillis());
2005:                _rset.updateTime("tm", newVal);
2006:                _rset.updateRow();
2007:                assertEquals(newVal, _rset.getTime("tm"));
2008:            }
2009:
2010:            /*
2011:             * Class under test for void updateTimestamp(String, Timestamp)
2012:             */
2013:            public void testUpdateTimestampStringTimestamp() throws Exception {
2014:                createUpdateTable();
2015:
2016:                // Test assertion that ResultSet has a current row
2017:                try {
2018:                    _rset.updateTimestamp("foo", new Timestamp(0L));
2019:                    fail("Expected SQLException");
2020:                } catch (SQLException ignore) {
2021:                    // expected.
2022:                }
2023:
2024:                // Now test normal usage.
2025:                _rset.next();
2026:
2027:                final Timestamp newVal = new Timestamp(System
2028:                        .currentTimeMillis());
2029:                _rset.updateTimestamp("ts", newVal);
2030:                _rset.updateRow();
2031:                assertEquals(newVal, _rset.getTimestamp("ts"));
2032:            }
2033:
2034:            public void testWasNullWithInsertRow() throws Exception {
2035:                createUpdateTable();
2036:
2037:                _rset.moveToInsertRow();
2038:                _rset.updateNull(1);
2039:                assertEquals(0, _rset.getInt(1));
2040:                assertTrue(_rset.wasNull());
2041:            }
2042:
2043:            public void testNegativeForwardOnly() throws Exception {
2044:                // Section 14.2.2, JDBC 3.0 specification:
2045:                // 
2046:                // "For a ResultSet object that is of TYPE_FORWARD_ONLY, the only valid cursor movement is
2047:                // next.  All other cursor movement methods throw an SQLException."
2048:                createForwardOnlyTable();
2049:
2050:                assertTrue(_rset.next());
2051:
2052:                try {
2053:                    _rset.previous();
2054:                    fail("Expected SQLException - forward-only result set.");
2055:                } catch (SQLException expected) {
2056:                    // Expected
2057:                }
2058:
2059:                try {
2060:                    _rset.relative(-2);
2061:                    fail("Expected SQLException - forward-only result set.");
2062:                } catch (SQLException expected) {
2063:                    // Expected
2064:                }
2065:
2066:                try {
2067:                    _rset.last();
2068:                    fail("Expected SQLException - forward-only result set.");
2069:                } catch (SQLException expected) {
2070:                    // Expected
2071:                }
2072:
2073:                try {
2074:                    _rset.first();
2075:                    fail("Expected SQLException - forward-only result set.");
2076:                } catch (SQLException expected) {
2077:                    // Expected
2078:                }
2079:
2080:                try {
2081:                    _rset.afterLast();
2082:                    fail("Expected SQLException - forward-only result set.");
2083:                } catch (SQLException expected) {
2084:                    // Expected
2085:                }
2086:
2087:                try {
2088:                    _rset.beforeFirst();
2089:                    fail("Expected SQLException - forward-only result set.");
2090:                } catch (SQLException expected) {
2091:                    // Expected
2092:                }
2093:
2094:                try {
2095:                    _rset.absolute(2);
2096:                    fail("Expected SQLException - forward-only result set.");
2097:                } catch (SQLException expected) {
2098:                    // Expected
2099:                }
2100:            }
2101:
2102:            /**
2103:             * Creates Axion database for this test suite.
2104:             * 
2105:             * @return Database instance.
2106:             * @throws Exception
2107:             */
2108:            protected Database createDatabase() throws Exception {
2109:                return Databases.getOrCreateDatabase(getDatabaseName(),
2110:                        getDatabaseDirectory());
2111:            }
2112:
2113:            /**
2114:             * Executes cleanup methods that are local to this test suite.  A subclass should override
2115:             * this method as necessary, but be sure to invoke it via super.doCleanup() if it does not
2116:             * already close resources which are bound to this class instance. 
2117:             */
2118:            protected void doCleanup() throws Exception {
2119:                if (_rset != null) {
2120:                    _rset.close();
2121:                }
2122:
2123:                try {
2124:                    if (_stmt != null) {
2125:                        _stmt.execute("drop table foo");
2126:                    }
2127:                } catch (SQLException ignore) {
2128:                    // ignore
2129:                }
2130:
2131:                if (_stmt != null) {
2132:                    _stmt.close();
2133:                }
2134:
2135:                if (_conn != null) {
2136:                    _conn.close();
2137:                }
2138:            }
2139:
2140:            /**
2141:             * Gets name of Axion database to use in this test suite.  Should be overridden by subclasses that
2142:             * wish to use a distinct database.
2143:             * 
2144:             * @return
2145:             */
2146:            protected String getDatabaseName() {
2147:                return "JDBC_MemoryDB";
2148:            }
2149:
2150:            /**
2151:             * Gets File representing local filesystem directory in which Axion metadata files will be
2152:             * stored - null for this instance since we're testing via memory database.  Should be 
2153:             * overridden by subclasses that use the local file system for persistence.  
2154:             * 
2155:             * @return null for this instance
2156:             */
2157:            protected File getDatabaseDirectory() {
2158:                return null;
2159:            }
2160:
2161:            /**
2162:             * @return
2163:             */
2164:            protected Table createTableInstance() throws Exception {
2165:                return new MemoryTable("foo");
2166:            }
2167:
2168:            /**
2169:             * Creates basic table for use in general ResultSet testing.
2170:             * 
2171:             * @throws Exception if error occurs during table or ResultSet construction
2172:             */
2173:            protected void createBasicTable() throws Exception {
2174:                if (_stmt != null) {
2175:                    _stmt.close();
2176:                }
2177:
2178:                _stmt = (AxionStatement) _conn.createStatement(
2179:                        ResultSet.TYPE_SCROLL_SENSITIVE,
2180:                        ResultSet.CONCUR_UPDATABLE);
2181:                try {
2182:                    _stmt.executeUpdate("drop table foo");
2183:                } catch (SQLException ignore) {
2184:                    // ignore - table doesn't exist.
2185:                }
2186:
2187:                _stmt
2188:                        .executeUpdate("create table foo (test varchar(10), num int)");
2189:                _conn.setAutoCommit(false);
2190:                for (int i = 0; i < IMAX; i++) {
2191:                    for (int j = 0; j < JMAX; j++) {
2192:                        _stmt.executeUpdate("insert into foo values ('"
2193:                                + String.valueOf((char) (65 + i)) + "', " + j
2194:                                + ")");
2195:                    }
2196:                }
2197:                _conn.commit();
2198:                _conn.setAutoCommit(true);
2199:
2200:                _stmt = (AxionStatement) _conn.createStatement(
2201:                        ResultSet.TYPE_SCROLL_SENSITIVE,
2202:                        ResultSet.CONCUR_READ_ONLY);
2203:                _stmt.executeQuery("select * from foo");
2204:                _rset = _stmt.getCurrentResultSet();
2205:            }
2206:
2207:            /**
2208:             * Creates empty table for use in testing position logic against a degenerate AxionResultSet.
2209:             * 
2210:             * @throws Exception if error occurs during table or ResultSet construction 
2211:             */
2212:            protected void createEmptyTable() throws Exception {
2213:                if (_stmt != null) {
2214:                    _stmt.close();
2215:                }
2216:
2217:                _stmt = (AxionStatement) _conn.createStatement(
2218:                        ResultSet.TYPE_SCROLL_SENSITIVE,
2219:                        ResultSet.CONCUR_UPDATABLE);
2220:
2221:                try {
2222:                    _stmt.execute("drop table foo");
2223:                } catch (SQLException ignore) {
2224:                    // ignore and continue            
2225:                }
2226:                _stmt.execute("create table foo (id int)");
2227:
2228:                _rset = _stmt.executeQuery("select * from foo");
2229:            }
2230:
2231:            protected void createForwardOnlyTable() throws Exception {
2232:                if (_stmt != null) {
2233:                    _stmt.close();
2234:                }
2235:
2236:                _stmt = (AxionStatement) _conn
2237:                        .createStatement(ResultSet.TYPE_FORWARD_ONLY,
2238:                                ResultSet.CONCUR_UPDATABLE);
2239:
2240:                try {
2241:                    _stmt.execute("drop table foo");
2242:                } catch (SQLException ignore) {
2243:                    // ignore and continue            
2244:                }
2245:                _stmt.execute("create table foo (id int)");
2246:                _stmt.execute("insert into foo values (1)");
2247:                _stmt.execute("insert into foo values (2)");
2248:                _stmt.execute("insert into foo values (3)");
2249:                _stmt.execute("insert into foo values (4)");
2250:
2251:                _rset = _stmt.executeQuery("select * from foo");
2252:            }
2253:
2254:            /**
2255:             * Creates empty table for use in testing position logic against a degenerate AxionResultSet.
2256:             * 
2257:             * @throws Exception if error occurs during table or ResultSet construction 
2258:             */
2259:            protected void createOneRowTable() throws Exception {
2260:                if (_stmt != null) {
2261:                    _stmt.close();
2262:                }
2263:
2264:                _stmt = (AxionStatement) _conn.createStatement(
2265:                        ResultSet.TYPE_SCROLL_SENSITIVE,
2266:                        ResultSet.CONCUR_UPDATABLE);
2267:                try {
2268:                    _stmt.execute("drop table foo");
2269:                } catch (SQLException ignore) {
2270:                    // ignore and continue            
2271:                }
2272:                _stmt.execute("create table foo (id int)");
2273:                _stmt.execute("insert into foo values (1)");
2274:
2275:                _rset = _stmt.executeQuery("select * from foo");
2276:            }
2277:
2278:            /**
2279:             * Constructs a table for use in testing updating methods in AxionResultSet.
2280:             * 
2281:             * @throws Exception if error occurs during table or ResultSet construction
2282:             */
2283:            protected void createUpdateTable() throws Exception {
2284:                if (_stmt != null) {
2285:                    _stmt.close();
2286:                }
2287:
2288:                _stmt = (AxionStatement) _conn.createStatement(
2289:                        ResultSet.TYPE_SCROLL_SENSITIVE,
2290:                        ResultSet.CONCUR_UPDATABLE);
2291:
2292:                try {
2293:                    _stmt.execute("drop table foo");
2294:                } catch (SQLException ignore) {
2295:                    // ignore and continue            
2296:                }
2297:                _stmt
2298:                        .execute("create table foo (id int, str_10 varchar(10), dt date, tm time, ts timestamp, bool boolean)");
2299:
2300:                _conn.setAutoCommit(false);
2301:                _stmt
2302:                        .execute("insert into foo values (1, 'This is 1', '2005-01-01', '12:34:56', '2005-03-31 23:56:00.0', false)");
2303:                _stmt
2304:                        .execute("insert into foo values (2, 'This is 2', '2005-02-02', '23:45:00', '2005-04-01 00:00:00.0', false)");
2305:                _stmt
2306:                        .execute("insert into foo values (3, 'This is 3', '2005-03-03', '06:30:30', '2005-04-02 01:23:45.6', false)");
2307:                _stmt
2308:                        .execute("insert into foo values (4, 'This is 4', '2005-04-04', '07:45:45', '2005-04-03 02:34:32.1', false)");
2309:                _conn.commit();
2310:                _conn.setAutoCommit(true);
2311:
2312:                _rset = _stmt.executeQuery("select * from foo");
2313:            }
2314:
2315:            protected void createUpdateTableWithNotNullColumn()
2316:                    throws Exception {
2317:                if (_stmt != null) {
2318:                    _stmt.close();
2319:                }
2320:
2321:                _stmt = (AxionStatement) _conn.createStatement(
2322:                        ResultSet.TYPE_SCROLL_SENSITIVE,
2323:                        ResultSet.CONCUR_UPDATABLE);
2324:
2325:                try {
2326:                    _stmt.execute("drop table foo");
2327:                } catch (SQLException ignore) {
2328:                    // ignore and continue            
2329:                }
2330:                _stmt
2331:                        .execute("create table foo (id int, str_10 varchar(10), dt date, tm time, ts timestamp, bool boolean not null)");
2332:
2333:                _conn.setAutoCommit(false);
2334:                _stmt
2335:                        .execute("insert into foo values (1, 'This is 1', '2005-01-01', '12:34:56', '2005-03-31 23:56:00.0', false)");
2336:                _stmt
2337:                        .execute("insert into foo values (2, 'This is 2', '2005-02-02', '23:45:00', '2005-04-01 00:00:00.0', false)");
2338:                _stmt
2339:                        .execute("insert into foo values (3, 'This is 3', '2005-03-03', '06:30:30', '2005-04-02 01:23:45.6', false)");
2340:                _stmt
2341:                        .execute("insert into foo values (4, 'This is 4', '2005-04-04', '07:45:45', '2005-04-03 02:34:32.1', false)");
2342:                _conn.commit();
2343:                _conn.setAutoCommit(true);
2344:
2345:                _rset = _stmt
2346:                        .executeQuery("select id, str_10, dt, tm, ts, bool from foo");
2347:            }
2348:
2349:            /**
2350:             * Tests indicators that must be false when the result set is empty.
2351:             *  
2352:             * @throws Exception if error occurs while executing methods under test.
2353:             */
2354:            protected void assertEmptyResultSet() throws Exception {
2355:                assertFalse(_rset.isBeforeFirst());
2356:                assertFalse(_rset.isFirst());
2357:                assertFalse(_rset.isLast());
2358:                assertFalse(_rset.isAfterLast());
2359:            }
2360:
2361:            /**
2362:             * Tests indicators that show that the result set cursor is positioned before the first row in the 
2363:             * ResultSet. 
2364:             * 
2365:             * @throws Exception if error occurs while executing methods under test.
2366:             */
2367:            protected void assertBeforeFirst() throws Exception {
2368:                assertTrue(_rset.isBeforeFirst());
2369:                assertFalse(_rset.isFirst());
2370:                assertFalse(_rset.isLast());
2371:                assertFalse(_rset.isAfterLast());
2372:            }
2373:
2374:            /**
2375:             * Tests indicators that show that the result set is in the middle of a ResultSet and not in either of
2376:             * the extremes - use only for multi-row ResultSets. 
2377:             * 
2378:             * @throws Exception if error occurs while executing methods under test.
2379:             */
2380:            protected void assertInMiddleInMultirowRS() throws Exception {
2381:                assertFalse(_rset.isBeforeFirst());
2382:                assertFalse(_rset.isFirst());
2383:                assertFalse(_rset.isLast());
2384:                assertFalse(_rset.isAfterLast());
2385:            }
2386:
2387:            /**
2388:             * Tests indicators that show that the result set cursor is on the first row in the 
2389:             * ResultSet - use only for multi-row ResultSets. 
2390:             * 
2391:             * @throws Exception if error occurs while executing methods under test.
2392:             */
2393:            protected void assertFirstInMultirowRS() throws Exception {
2394:                assertFalse(_rset.isBeforeFirst());
2395:                assertTrue(_rset.isFirst());
2396:                assertFalse(_rset.isLast());
2397:                assertFalse(_rset.isAfterLast());
2398:            }
2399:
2400:            /**
2401:             * Tests indicators that show that the result set cursor is on the last row in the 
2402:             * ResultSet - use only for multi-row ResultSets.   
2403:             * 
2404:             * @throws Exception if error occurs while executing methods under test.
2405:             */
2406:            protected void assertLastInMultirowRS() throws Exception {
2407:                assertFalse(_rset.isBeforeFirst());
2408:                assertFalse(_rset.isFirst());
2409:                assertTrue(_rset.isLast());
2410:                assertFalse(_rset.isAfterLast());
2411:            }
2412:
2413:            /**
2414:             * Tests indicators that show that result set cursor is positioned after the last row in the 
2415:             * ResultSet. 
2416:             * 
2417:             * @throws Exception if error occurs while executing methods under test.
2418:             */
2419:            protected void assertAfterLast() throws Exception {
2420:                assertFalse(_rset.isBeforeFirst());
2421:                assertFalse(_rset.isFirst());
2422:                assertFalse(_rset.isLast());
2423:                assertTrue(_rset.isAfterLast());
2424:            }
2425:
2426:            /**
2427:             * Drops Axion database used for this test suite.
2428:             */
2429:            private void dropDatabase() {
2430:                Databases.forgetDatabase(getDatabaseName());
2431:            }
2432:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.