Source Code Cross Referenced for CachedRowSetDataProviderTest.java in  » IDE-Netbeans » visualweb.api.designer » com » sun » data » provider » impl » 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 » IDE Netbeans » visualweb.api.designer » com.sun.data.provider.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * To change this template, choose Tools | Templates
003:         * and open the template in the editor.
004:         */
005:
006:        package com.sun.data.provider.impl;
007:
008:        import com.sun.data.provider.FieldKey;
009:        import com.sun.sql.rowset.CachedRowSetXImpl;
010:        import java.io.File;
011:        import junit.framework.TestCase;
012:
013:        import java.sql.Connection;
014:        import java.sql.DriverManager;
015:        import java.sql.PreparedStatement;
016:        import java.sql.SQLException;
017:        import java.util.logging.Level;
018:        import java.util.logging.Logger;
019:        import junit.framework.TestCase;
020:
021:        /**
022:         * This class makes sure that the rowset behaves correctly around what should
023:         * happen if the rowset is executed, not executed, modified, etc.
024:         * 
025:         * @author David
026:         */
027:        public class CachedRowSetDataProviderTest extends TestCase {
028:
029:            private static final Logger LOGGER = Logger
030:                    .getLogger(CachedRowSetDataProviderTest.class.getName());
031:
032:            private static final String DBURL = "jdbc:derby:mydb;create=true";
033:            private static final String TABLENAME = "mytable";
034:            private static final String IDNAME = "id";
035:            private static final String COL1NAME = "col1";
036:            private static final String COL2NAME = "col2";
037:
038:            private static final int NUMROWS = 10;
039:
040:            public CachedRowSetDataProviderTest(String testName) {
041:                super (testName);
042:            }
043:
044:            protected void setUp() throws Exception {
045:                try {
046:                    super .setUp();
047:
048:                    // Comment this out to turn off debugging
049:                    LOGGER.setLevel(Level.FINE);
050:
051:                    initDatabase();
052:                } catch (SQLException sqle) {
053:                    reportSQLException(sqle);
054:                } catch (Throwable t) {
055:                    LOGGER.log(Level.SEVERE, "Failed to set up test", t);
056:                    throw new Exception(t);
057:                }
058:            }
059:
060:            private void reportSQLException(SQLException sqle) {
061:                LOGGER.log(Level.SEVERE, null, sqle);
062:
063:                if (sqle.getNextException() != null) {
064:                    reportSQLException(sqle.getNextException());
065:                }
066:            }
067:
068:            protected void tearDown() throws Exception {
069:                super .tearDown();
070:
071:                // Remove the test database so it's not left lying around
072:                String userdir = System.getProperty("user.dir");
073:                File dbdir = new File(userdir + "/" + "mydb");
074:
075:                LOGGER.log(Level.INFO, "userdir is " + userdir);
076:
077:                deleteRecursively(dbdir);
078:
079:                File logfile = new File(userdir + "/derby.log");
080:                if (logfile.exists()) {
081:                    logfile.delete();
082:                }
083:            }
084:
085:            private void deleteRecursively(File file) throws Exception {
086:                if (!file.exists()) {
087:                    return;
088:                }
089:
090:                if (!file.isDirectory()) {
091:                    file.delete();
092:                    return;
093:                }
094:
095:                File[] children = file.listFiles();
096:
097:                for (int i = 0; i < children.length; i++) {
098:                    deleteRecursively(children[i]);
099:                }
100:
101:                file.delete();
102:            }
103:
104:            private void initDatabase() throws Exception {
105:                Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
106:                Connection conn = DriverManager.getConnection(DBURL);
107:
108:                try {
109:                    conn.prepareStatement("DROP TABLE " + TABLENAME).execute();
110:                } catch (SQLException sqle) {
111:                    LOGGER.log(Level.FINE, null, sqle);
112:                }
113:
114:                String create = "CREATE TABLE " + TABLENAME + "(" + IDNAME
115:                        + " int primary key, " + COL1NAME + " varchar(255),  "
116:                        + COL2NAME + " varchar(255))";
117:
118:                conn.prepareStatement(create).execute();
119:
120:                PreparedStatement insert = conn.prepareStatement("INSERT INTO "
121:                        + TABLENAME + " VALUES(?, ?, ?)");
122:
123:                for (int i = 1; i <= NUMROWS; i++) {
124:                    insert.setInt(1, i);
125:                    insert.setString(2, "col1_" + i);
126:                    insert.setString(3, "col2_" + i);
127:
128:                    insert.execute();
129:                }
130:            }
131:
132:            /**
133:             * Make sure the data provider detects a change to the rowset command 
134:             * 
135:             * @throws java.lang.Exception
136:             */
137:            public void testCommandChange() throws Exception {
138:                CachedRowSetXImpl rowset = new CachedRowSetXImpl();
139:
140:                CachedRowSetDataProvider provider = new CachedRowSetDataProvider();
141:                provider.setCachedRowSet(rowset);
142:
143:                rowset.setUrl("jdbc:derby:mydb;create=true");
144:
145:                /** 
146:                 * Select only one row and one extra column
147:                 */
148:                rowset.setCommand("SELECT " + IDNAME + ", " + COL1NAME
149:                        + " FROM " + TABLENAME + " WHERE " + IDNAME + " = 2");
150:
151:                rowset.setTableName(TABLENAME);
152:
153:                checkRows(provider, 1, 2);
154:
155:                rowset.setCommand("SELECT " + IDNAME + " FROM " + TABLENAME);
156:
157:                checkRows(provider, NUMROWS, 1);
158:
159:                provider.close();
160:            }
161:
162:            private void checkRows(CachedRowSetDataProvider provider,
163:                    int expectedRows, int expectedFields) {
164:                int numrows = provider.getRowCount();
165:                assert (numrows == expectedRows);
166:
167:                FieldKey[] keys = provider.getFieldKeys();
168:                int numkeys = keys.length;
169:
170:                assert (numkeys == expectedFields);
171:
172:                provider.cursorFirst();
173:
174:                for (int i = 0; i < numrows; i++) {
175:                    for (int j = 0; j < numkeys; j++) {
176:                        Object value = provider.getValue(keys[j]);
177:                        assert (value != null);
178:                    }
179:                }
180:            }
181:
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.