Source Code Cross Referenced for ProxyStatementTest.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » 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 JDBC Connection Pool » proxool » org.logicalcobwebs.proxool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.proxool;
007:
008:        import java.sql.CallableStatement;
009:        import java.sql.Connection;
010:        import java.sql.DriverManager;
011:        import java.sql.PreparedStatement;
012:        import java.sql.Statement;
013:        import java.util.Properties;
014:
015:        import org.apache.commons.logging.Log;
016:        import org.apache.commons.logging.LogFactory;
017:
018:        /**
019:         * Test whether ProxyStatement works
020:         *
021:         * @version $Revision: 1.13 $, $Date: 2006/03/03 09:58:26 $
022:         * @author bill
023:         * @author $Author: billhorsman $ (current maintainer)
024:         * @since Proxool 0.8
025:         */
026:        public class ProxyStatementTest extends AbstractProxoolTest {
027:
028:            private static final Log LOG = LogFactory
029:                    .getLog(ProxyStatementTest.class);
030:
031:            public ProxyStatementTest(String alias) {
032:                super (alias);
033:            }
034:
035:            /**
036:             * That we can get the delegate driver's Statement from the one given by Proxool
037:             */
038:            public void testDelegateStatement() throws Exception {
039:                String testName = "delegateStatement";
040:
041:                // Register pool
042:                String url = registerPool(testName);
043:
044:                // get a connection from the pool and create a statement with it
045:                Connection c = DriverManager.getConnection(url);
046:                Statement s = c.createStatement();
047:                Statement delegateStatement = ProxoolFacade
048:                        .getDelegateStatement(s);
049:                Class delegateStatementClass = delegateStatement.getClass();
050:                s.close();
051:
052:                LOG.debug("Statement " + s.getClass() + " is delegating to "
053:                        + delegateStatementClass);
054:
055:                // get a *real* connection directly from the native driver (bypassing the pool)
056:                Connection realConnection = TestHelper.getDirectConnection();
057:                Statement realStatement = realConnection.createStatement();
058:                Class realStatementClass = realStatement.getClass();
059:
060:                realStatement.close();
061:                realConnection.close();
062:
063:                // are they of the same type ?
064:                assertEquals("Delegate statement isn't of the expected type.",
065:                        realStatementClass, delegateStatementClass);
066:            }
067:
068:            /**
069:             * Test what interfaces are supported when getting a PreparedStatement
070:             */
071:            public void testPreparedStatement() throws Exception {
072:
073:                String testName = "preparedStatement";
074:
075:                // Register pool
076:                String url = registerPool(testName);
077:
078:                // get a connection from the pool and create a prepare statement with it
079:                Connection c = DriverManager.getConnection(url);
080:                PreparedStatement s = c
081:                        .prepareStatement(TestConstants.HYPERSONIC_TEST_SQL);
082:                Statement delegateStatement = ProxoolFacade
083:                        .getDelegateStatement(s);
084:                Class delegateStatementClass = delegateStatement.getClass();
085:                s.close();
086:                c.close();
087:
088:                LOG.debug("Statement " + s.getClass() + " is delegating to "
089:                        + delegateStatementClass);
090:
091:                // get a *real* connection directly from the native driver (bypassing the pool)
092:                Connection realConnection = TestHelper.getDirectConnection();
093:                Statement realStatement = realConnection
094:                        .prepareStatement(TestConstants.HYPERSONIC_TEST_SQL);
095:                Class realStatementClass = realStatement.getClass();
096:
097:                realStatement.close();
098:                realConnection.close();
099:
100:                // are they of the same type ?
101:                assertEquals("Delegate statement isn't of the expected type.",
102:                        realStatementClass, delegateStatementClass);
103:            }
104:
105:            /**
106:             * Test what interfaces are supported when getting a CallableStatement
107:             */
108:            public void testCallableStatement() throws Exception {
109:
110:                String testName = "callableStatement";
111:
112:                // Register pool
113:                String url = registerPool(testName);
114:
115:                // get a connection from the pool and create a callable statement with it
116:                Connection c = DriverManager.getConnection(url);
117:                CallableStatement s = c
118:                        .prepareCall(TestConstants.HYPERSONIC_TEST_SQL);
119:                Statement delegateStatement = ProxoolFacade
120:                        .getDelegateStatement(s);
121:                Class delegateStatementClass = delegateStatement.getClass();
122:                s.close();
123:
124:                LOG.debug("Statement " + s.getClass() + " is delegating to "
125:                        + delegateStatementClass);
126:
127:                // get a *real* connection directly from the native driver (bypassing the pool)
128:                Connection realConnection = TestHelper.getDirectConnection();
129:                Statement realStatement = realConnection
130:                        .prepareCall(TestConstants.HYPERSONIC_TEST_SQL);
131:                Class realStatementClass = realStatement.getClass();
132:
133:                realStatement.close();
134:                realConnection.close();
135:
136:                // are they of the same type ?
137:                assertEquals("Delegate statement isn't of the expected type.",
138:                        realStatementClass, delegateStatementClass);
139:            }
140:
141:            /**
142:             * That we can get the delegate driver's Connection from the one given by Proxool
143:             */
144:            public void testDelegateConnection() throws Exception {
145:
146:                String testName = "delegateConnection";
147:
148:                // Register pool
149:                String url = registerPool(testName);
150:
151:                // get a connection from the pool
152:                Connection c = DriverManager.getConnection(url);
153:                Connection delegateConnection = ProxoolFacade
154:                        .getDelegateConnection(c);
155:                Class delegateConnectionClass = delegateConnection.getClass();
156:
157:                LOG.debug("Connection " + c + " is delegating to "
158:                        + delegateConnectionClass);
159:                c.close();
160:
161:                // get a *real* connection directly from the native driver (bypassing the pool)
162:                Connection realConnection = TestHelper.getDirectConnection();
163:                Class realConnectionClass = realConnection.getClass();
164:                realConnection.close();
165:
166:                assertEquals("Connection isn't of the expected.",
167:                        realConnectionClass, delegateConnectionClass);
168:            }
169:
170:            /**
171:             * 
172:             * @param alias
173:             * @throws Exception
174:             */
175:            private String registerPool(String alias) throws Exception {
176:                String url = TestHelper.buildProxoolUrl(alias,
177:                        TestConstants.HYPERSONIC_DRIVER,
178:                        TestConstants.HYPERSONIC_TEST_URL);
179:                Properties info = new Properties();
180:                info.setProperty(ProxoolConstants.USER_PROPERTY,
181:                        TestConstants.HYPERSONIC_USER);
182:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
183:                        TestConstants.HYPERSONIC_PASSWORD);
184:                ProxoolFacade.registerConnectionPool(url, info);
185:
186:                return url;
187:            }
188:
189:            public void testCloseByStatement() throws Exception {
190:
191:                String testName = "snapshot";
192:                final String alias = testName;
193:                String url = TestHelper.buildProxoolUrl(alias,
194:                        TestConstants.HYPERSONIC_DRIVER,
195:                        TestConstants.HYPERSONIC_TEST_URL);
196:                Properties info = new Properties();
197:                info.setProperty(ProxoolConstants.USER_PROPERTY,
198:                        TestConstants.HYPERSONIC_USER);
199:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
200:                        TestConstants.HYPERSONIC_PASSWORD);
201:                ProxoolFacade.registerConnectionPool(url, info);
202:
203:                // get a connection from the pool and create a statement with it
204:                Connection c = DriverManager.getConnection(url);
205:                Statement s = c.createStatement();
206:                // Even if we ask the statement to close it it should still work.
207:                s.getConnection().close();
208:                assertEquals("servedCount", 0, ProxoolFacade.getSnapshot(alias)
209:                        .getActiveConnectionCount());
210:
211:            }
212:        }
213:
214:        /*
215:         Revision history:
216:         $Log: ProxyStatementTest.java,v $
217:         Revision 1.13  2006/03/03 09:58:26  billhorsman
218:         Fix for statement.getConnection(). See bug 1149834.
219:
220:         Revision 1.12  2006/01/18 14:40:06  billhorsman
221:         Unbundled Jakarta's Commons Logging.
222:
223:         Revision 1.11  2004/07/13 21:32:41  billhorsman
224:         Close the first connection first before opening the real connection (directly) otherwise you get a "database already in use"error on Windows.
225:
226:         Revision 1.10  2004/05/26 17:19:09  brenuart
227:         Allow JUnit tests to be executed against another database.
228:         By default the test configuration will be taken from the 'testconfig-hsqldb.properties' file located in the org.logicalcobwebs.proxool package.
229:         This behavior can be overriden by setting the 'testConfig' environment property to another location.
230:
231:         Revision 1.9  2004/03/23 21:17:23  billhorsman
232:         added preparedStatement and callableStatement tests
233:
234:         Revision 1.8  2003/12/09 18:52:19  billhorsman
235:         checkstyle
236:
237:         Revision 1.7  2003/11/05 00:00:52  billhorsman
238:         Remove redundant test (already in FatalSqlExceptionTest)
239:
240:         Revision 1.6  2003/08/27 18:03:20  billhorsman
241:         added new getDelegateConnection() method
242:
243:         Revision 1.5  2003/03/04 10:24:40  billhorsman
244:         removed try blocks around each test
245:
246:         Revision 1.4  2003/03/03 17:09:05  billhorsman
247:         all tests now extend AbstractProxoolTest
248:
249:         Revision 1.3  2003/03/03 11:12:05  billhorsman
250:         fixed licence
251:
252:         Revision 1.2  2003/03/01 15:27:24  billhorsman
253:         checkstyle
254:
255:         Revision 1.1  2003/02/27 18:01:48  billhorsman
256:         completely rethought the test structure. it's now
257:         more obvious. no new tests yet though.
258:
259:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.