Source Code Cross Referenced for ScrollResultSetTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbcapi » 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 » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.jdbcapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Derby - Class ScrollResultSetTest
004:         *
005:         * Licensed to the Apache Software Foundation (ASF) under one or more
006:         * contributor license agreements.  See the NOTICE file distributed with
007:         * this work for additional information regarding copyright ownership.
008:         * The ASF licenses this file to You under the Apache License, Version 2.0
009:         * (the "License"); you may not use this file except in compliance with
010:         * the License.  You may obtain a copy of the License at
011:         *
012:         *    http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing, 
015:         * software distributed under the License is distributed on an 
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
017:         * either express or implied. See the License for the specific 
018:         * language governing permissions and limitations under the License.
019:         */
020:        package org.apache.derbyTesting.functionTests.tests.jdbcapi;
021:
022:        import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
023:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
024:        import org.apache.derbyTesting.junit.JDBC;
025:
026:        import junit.framework.*;
027:
028:        import java.sql.*;
029:
030:        /**
031:         * Tests scrollable result sets
032:         *
033:         * @author Fernanda Pizzorno
034:         *
035:         * Tests:
036:         * - testNextOnLastRowForwardOnly: tests that the result set is closed when all
037:         * rows have been retreived and next has been called from the last row, 
038:         * autocommit = true, the result set is not holdable and type forward 
039:         * only. (DERBY-1295)
040:         * - testNextOnLastRowScrollable: tests that the result set is not closed when 
041:         * next is called while the result set is positioned in the last row, 
042:         * autocommit = true, the result set is not holdable type scrollable 
043:         * insensitive. (DERBY-1295)
044:         *
045:         */
046:        public class ScrollResultSetTest extends BaseJDBCTestCase {
047:
048:            /** Creates a new instance of ScrollResultSetTest */
049:            public ScrollResultSetTest(String name) {
050:                super (name);
051:            }
052:
053:            public static Test suite() {
054:                TestSuite suite = new TestSuite();
055:
056:                // Requires holdability
057:                if (JDBC.vmSupportsJDBC3() || JDBC.vmSupportsJSR169()) {
058:                    suite.addTestSuite(ScrollResultSetTest.class);
059:                }
060:
061:                return suite;
062:            }
063:
064:            /**
065:             * Set up the connection to the database.
066:             */
067:            public void setUp() throws Exception {
068:                Connection con = getConnection();
069:                con.setAutoCommit(true);
070:
071:                String createTableWithPK = "CREATE TABLE tableWithPK ("
072:                        + "c1 int primary key," + "c2 int)";
073:                String insertData = "INSERT INTO tableWithPK values "
074:                        + "(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)";
075:                Statement stmt = con.createStatement();
076:                stmt.execute(createTableWithPK);
077:
078:                stmt.execute(insertData);
079:                stmt.close();
080:            }
081:
082:            /**
083:             * Drop the table
084:             */
085:            public void tearDown() throws Exception {
086:                println("TearDown");
087:                Statement s = getConnection().createStatement();
088:                try {
089:
090:                    s.executeUpdate("DROP TABLE tableWithPK");
091:                } catch (SQLException e) {
092:                    printStackTrace(e);
093:                }
094:                s.close();
095:                super .tearDown();
096:
097:            }
098:
099:            /**
100:             * Test that moving to next row after positioned at the last row on a 
101:             * forward only result set will close the result set
102:             */
103:            public void testNextOnLastRowForwardOnly() throws SQLException {
104:
105:                Connection con = getConnection();
106:                con.setAutoCommit(true);
107:                con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
108:                Statement roStmt = con
109:                        .createStatement(ResultSet.TYPE_FORWARD_ONLY,
110:                                ResultSet.CONCUR_READ_ONLY);
111:
112:                ResultSet rs = roStmt
113:                        .executeQuery("SELECT c1 FROM tableWithPK");
114:
115:                // call next until positioned after last
116:                while (rs.next())
117:                    ;
118:
119:                try {
120:                    // forward only result set should be closed now, an exception will
121:                    // be thrown
122:                    rs.next();
123:                    assertTrue(
124:                            "Excepted exception to be thrown - result set is closed",
125:                            false);
126:                } catch (SQLException se) {
127:                    if (!usingDerbyNet()) {
128:                        assertSQLState("Unexpected SQL State",
129:                                SQLStateConstants.RESULT_SET_IS_CLOSED, se);
130:                    }
131:                }
132:
133:            }
134:
135:            /**
136:             * Test that moving to next row after positioned at the last row on a 
137:             * scrollable result set will not close the result set
138:             */
139:            public void testNextOnLastRowScrollable() throws SQLException {
140:
141:                Connection con = getConnection();
142:                con.setAutoCommit(true);
143:                con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
144:                Statement roStmt = con.createStatement(
145:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
146:                        ResultSet.CONCUR_READ_ONLY);
147:
148:                ResultSet rs = roStmt
149:                        .executeQuery("SELECT c1 FROM tableWithPK");
150:                // move to last position and then call next
151:                rs.last();
152:                rs.next();
153:
154:                // scrollable result set should still be open and not throw no 
155:                // exception will be thrown
156:                assertFalse("Calling next while positioned after last returns "
157:                        + "false", rs.next());
158:                assertTrue("Moving to absolute(2) returns true", rs.absolute(2));
159:                rs.close();
160:
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.