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


001:        /*
002:         *
003:         * Derby - Class XA40Test
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:
021:        package org.apache.derbyTesting.functionTests.tests.jdbc4;
022:
023:        import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
024:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
025:
026:        import junit.framework.*;
027:
028:        import java.sql.*;
029:
030:        import javax.sql.XAConnection;
031:        import javax.sql.XADataSource;
032:        import javax.transaction.xa.XAResource;
033:
034:        import org.apache.derby.iapi.jdbc.BrokeredStatement40;
035:        import org.apache.derby.iapi.jdbc.BrokeredPreparedStatement40;
036:        import org.apache.derby.iapi.jdbc.BrokeredCallableStatement40;
037:
038:        /**
039:         * Test new methods added for XA in JDBC4.
040:         */
041:        public class XA40Test extends BaseJDBCTestCase {
042:
043:            /** Default XADataSource used by the tests. */
044:            private XADataSource xads = null;
045:
046:            /** Default XAConnection used by the tests. */
047:            private XAConnection xac = null;
048:
049:            /** Default XAResource used by the tests. */
050:            private XAResource xar = null;
051:
052:            /** Default Connection used by the tests. */
053:            private Connection con = null;
054:
055:            /**
056:             * Create a new test with the given name.
057:             *
058:             * @param name name of the test.
059:             */
060:            public XA40Test(String name) {
061:                super (name);
062:            }
063:
064:            /**
065:             * Create default XADataSource, XAResource, XAConnection, and
066:             * Connection for the tests.
067:             *
068:             * @throws SQLException if a database access exception occurs.
069:             */
070:            public void setUp() throws SQLException {
071:                xads = TestDataSourceFactory.getXADataSource();
072:                xac = xads.getXAConnection();
073:                xar = xac.getXAResource();
074:                con = xac.getConnection();
075:                assertFalse("Connection must be open initially", con.isClosed());
076:                con.setAutoCommit(false);
077:            }
078:
079:            /**
080:             * Close default connection and XAConnection if necessary.
081:             *
082:             * @throws SQLException if a database access exception occurs.
083:             */
084:            public void tearDown() throws SQLException {
085:                // Close default connection
086:                // Check if connection is open to avoid exception on rollback.
087:                if (con != null && !con.isClosed()) {
088:                    // Abort changes that may have been done in the test.
089:                    // The test-method may however commit these itself.
090:                    con.rollback();
091:                    con.close();
092:                }
093:                if (xac != null) {
094:                    xac.close();
095:                }
096:            }
097:
098:            /**
099:             * Tests isPoolable(), setPoolable(boolean) and default
100:             * poolability for Statement, (which for XA is actually a
101:             * BrokeredStatement40 in embedded).
102:             *
103:             * @throws SQLException if a database access exception occurs.
104:             */
105:            public void testStatementPoolable() throws SQLException {
106:                Statement s = con.createStatement();
107:                if (usingEmbedded()) {
108:                    assertTrue("s must be an instance of BrokeredStatement40, "
109:                            + "but is " + s.getClass(),
110:                            (s instanceof  BrokeredStatement40));
111:                }
112:                assertFalse("Statement must not be poolable by default", s
113:                        .isPoolable());
114:                s.setPoolable(true);
115:                assertTrue("Statement must be poolable", s.isPoolable());
116:
117:                s.setPoolable(false);
118:                assertFalse("Statement cannot be poolable", s.isPoolable());
119:            }
120:
121:            /**
122:             * Tests isPoolable() and setPoolable(boolean) for
123:             * PreparedStatement, (which for XA is actually a
124:             * BrokeredPreparedStatement40 in embedded).
125:             *
126:             * @throws SQLException if a database access exception occurs.
127:             */
128:            public void testPreparedStatementPoolable() throws SQLException {
129:                PreparedStatement ps = con
130:                        .prepareStatement("CREATE TABLE foo(i int)");
131:                if (usingEmbedded()) {
132:                    assertTrue("ps must be an instance of "
133:                            + "BrokeredPreparedStatement40, " + "but is "
134:                            + ps.getClass(),
135:                            (ps instanceof  BrokeredPreparedStatement40));
136:                }
137:                assertTrue("PreparedStatement must be poolable by default", ps
138:                        .isPoolable());
139:                ps.setPoolable(false);
140:                assertFalse("PreparedStatement cannot be poolable", ps
141:                        .isPoolable());
142:
143:                ps.setPoolable(true);
144:                assertTrue("PreparedStatement must be poolable", ps
145:                        .isPoolable());
146:            }
147:
148:            /**
149:             * Tests isPoolable() and setPoolable(boolean) and default
150:             * poolability for CallableStatement (which for XA is actually a
151:             * BrokeredCallableStatement40 in embedded).
152:             *
153:             * @throws SQLException if a database access exception occurs.
154:             */
155:            public void testCallableStatementPoolable() throws SQLException {
156:                CallableStatement cs = con
157:                        .prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
158:                if (usingEmbedded()) {
159:                    assertTrue("cs must be an instance of "
160:                            + "BrokeredCallableStatement40, " + "but is "
161:                            + cs.getClass(),
162:                            (cs instanceof  BrokeredCallableStatement40));
163:                }
164:                assertTrue("CallableStatement must be poolable by default", cs
165:                        .isPoolable());
166:                cs.setPoolable(false);
167:                assertFalse("CallableStatement cannot be poolable", cs
168:                        .isPoolable());
169:
170:                cs.setPoolable(true);
171:                assertTrue("CallableStatement must be poolable", cs
172:                        .isPoolable());
173:            }
174:
175:            /**
176:             * Create test suite for XA40Test.
177:             */
178:            public static Test suite() {
179:                TestSuite suite = new TestSuite("XA40Test suite");
180:                // Decorate test suite with a TestSetup class.
181:                suite.addTest(new TestSuite(XA40Test.class));
182:
183:                return suite;
184:            }
185:
186:        } // End class XA40Test
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.