Source Code Cross Referenced for PoolTestFixture.java in  » Database-JDBC-Connection-Pool » SmartPool » org » smartlib » pool » core » 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 » SmartPool » org.smartlib.pool.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.smartlib.pool.core;
002:
003:        import junit.framework.TestCase;
004:        import org.apache.log4j.LogManager;
005:        import org.apache.log4j.PropertyConfigurator;
006:        import org.apache.log4j.Logger;
007:        import org.smartlib.pool.core.PoolConstants;
008:        import org.smartlib.pool.core.PoolConfig;
009:
010:        import java.util.Properties;
011:        import java.sql.Connection;
012:        import java.sql.Statement;
013:        import java.sql.ResultSet;
014:        import java.sql.PreparedStatement;
015:
016:        /**
017:         * Created by IntelliJ IDEA.
018:         * User: kerneldebugger
019:         * Date: Sep 28, 2005
020:         * Time: 8:54:09 PM
021:         * To change this template use File | Settings | File Templates.
022:         */
023:        public class PoolTestFixture extends TestCase {
024:
025:            Logger logger = Logger.getLogger(PoolTestFixture.class);
026:
027:            protected PoolConfig getBasicPoolConfig() {
028:                PoolConfig config = new PoolConfig();
029:                config.setMultiPoolName("MultiPool-1");
030:                config.setAllowAnonymousConnections(true);
031:                config.setAutoClose(true);
032:                PoolConfig.ConnectionString connectionString = new PoolConfig.ConnectionString();
033:                connectionString.setName("MultiPool.Pool-1");
034:                connectionString
035:                        .setConnectString("jdbc:oracle:thin:@db01.dev:1521:dev1");
036:                config
037:                        .setConnectionString(new PoolConfig.ConnectionString[] { connectionString });
038:                config.setDefaultPool(true);
039:                config.setDetectLeaks(false);
040:                config.setDriver("oracle.jdbc.driver.OracleDriver");
041:                config.setMaxConnections(3);
042:                config.setMinConnections(1);
043:                config.setPassword("passw0rd");
044:                config.setUserName("sachin");
045:                return config;
046:            }
047:
048:            protected PoolConfig getPoolConfigWithMultiplePools() {
049:                PoolConfig config = getBasicPoolConfig();
050:
051:                PoolConfig.ConnectionString connectionString = new PoolConfig.ConnectionString();
052:                connectionString.setName("MultiPool.Pool-1");
053:                connectionString
054:                        .setConnectString("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=10.102.15.212)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=DEV)(INSTANCE_NAME=DEV1)))");
055:                PoolConfig.ConnectionString connectionString1 = new PoolConfig.ConnectionString();
056:                connectionString1
057:                        .setConnectString("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=10.102.15.213)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=DEV)(INSTANCE_NAME=DEV1)))");
058:                connectionString1.setName("MultiPool.Pool-2");
059:                config.setConnectionString(new PoolConfig.ConnectionString[] {
060:                        connectionString, connectionString1 });
061:                return config;
062:
063:            }
064:
065:            protected PoolConfig getPoolConfigWithMultipleExternalPools() {
066:                PoolConfig config = getBasicPoolConfig();
067:
068:                PoolConfig.ConnectionLoaderClass connectionLoaderClass = new PoolConfig.ConnectionLoaderClass();
069:
070:                connectionLoaderClass
071:                        .setName("MultiPool.ConnectionProviderImpl-1");
072:                connectionLoaderClass
073:                        .setConnectionLoaderClass("org.smartlib.pool.core.ConnectionProviderImpl1");
074:
075:                PoolConfig.ConnectionLoaderClass connectionLoaderClass1 = new PoolConfig.ConnectionLoaderClass();
076:                connectionLoaderClass1
077:                        .setConnectionLoaderClass("org.smartlib.pool.core.ConnectionProviderImpl2");
078:                connectionLoaderClass1
079:                        .setName("MultiPool.ConnectionProviderImpl-2");
080:                config
081:                        .setConnectionLoaderClass(new PoolConfig.ConnectionLoaderClass[] {
082:                                connectionLoaderClass, connectionLoaderClass1 });
083:                return config;
084:
085:            }
086:
087:            protected void testConnection(Connection conn) throws Exception {
088:
089:                logger.debug("Testing Connection: " + conn);
090:                Statement stmt = null;
091:                try {
092:                    stmt = conn.createStatement();
093:                    stmt.execute("Select count(*) from version");
094:                    logger.debug("Test Passed: " + conn);
095:                } finally {
096:                    if (stmt != null) {
097:                        try {
098:                            stmt.close();
099:                        } catch (Exception e) {
100:                            //Ignore
101:                        }
102:                    }
103:                }
104:
105:            }
106:
107:            protected void setUp() throws Exception {
108:                super .setUp();
109:                LogManager.resetConfiguration();
110:                Properties log4j = new Properties();
111:
112:                // ----------Basic dont change
113:                log4j.put("log4j.appender.A1",
114:                        "org.apache.log4j.DailyRollingFileAppender");
115:                log4j.put("log4j.appender.A1.File", "c:\\smartpool.log");
116:                log4j.put("log4j.appender.A1.layout",
117:                        "org.apache.log4j.PatternLayout");
118:                log4j.put("log4j.appender.A1.layout.ConversionPattern",
119:                        "[%d{ISO8601}] <%t> %-5p %c: %m%n");
120:                log4j.put("log4j.appender.A1.DatePattern", "'.'yyyy-MM-dd");
121:                log4j.put("log4j.appender.SYSTEMOUT",
122:                        "org.apache.log4j.ConsoleAppender");
123:                log4j.put("log4j.appender.SYSTEMOUT.layout",
124:                        "org.apache.log4j.PatternLayout");
125:                log4j.put("log4j.appender.SYSTEMOUT.layout.ConversionPattern",
126:                        "[%d{ISO8601}] <%t> %-5p %c: %m%n");
127:                log4j.put("log4j.appender.KILL",
128:                        "org.apache.log4j.FileAppender");
129:                log4j.put("log4j.appender.KILL.File", "/dev/null");
130:                log4j.put("log4j.appender.KILL.layout",
131:                        "org.apache.log4j.PatternLayout");
132:                log4j.put("log4j.appender.KILL.layout.ConversionPattern",
133:                        "[%d] %m%n");
134:                //--------------------------
135:
136:                log4j.put("log4j.rootLogger", "WARN, SYSTEMOUT");
137:                log4j.put("log4j.logger.org.smartlib", "DEBUG");
138:
139:                PropertyConfigurator.configure(log4j);
140:                if (logger.isDebugEnabled()) {
141:                    logger.debug("Log4J Configured");
142:                }
143:
144:                //Set the test config file name to main config file name
145:                System
146:                        .setProperty(
147:                                PoolConstants.CONFIG_FILE_SYSTEM_PROPERTY,
148:                                System
149:                                        .getProperty(PoolConstants.TEST_CONFIG_FILE_SYSTEM_PROPERTY));
150:
151:            }
152:
153:            /**
154:             * Gets the instance name from the V$instance view, the connected user should have the required prevelige
155:             * @param conn
156:             * @return
157:             * @throws Exception
158:             */
159:            protected String getInstanceName(Connection conn) throws Exception {
160:                PreparedStatement stmt = null;
161:                ResultSet rs = null;
162:                try {
163:                    stmt = conn
164:                            .prepareStatement("select instance_name from v$instance");
165:                    rs = stmt.executeQuery();
166:                    if (rs.next()) {
167:                        return rs.getString(1);
168:                    } else {
169:                        throw new Exception(
170:                                "No Rows found, should never happen");
171:                    }
172:                } finally {
173:                    stmt.close();
174:                    rs.close();
175:                }
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.