Source Code Cross Referenced for DBConnectionPool.java in  » Content-Management-System » harmonise » org » openharmonise » commons » dsi » 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 » Content Management System » harmonise » org.openharmonise.commons.dsi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.commons.dsi;
020:
021:        import java.sql.Connection;
022:        import java.sql.DriverManager;
023:        import java.sql.SQLException;
024:        import java.util.logging.*;
025:        import java.util.logging.Logger;
026:
027:        import org.openharmonise.commons.pool.*;
028:
029:        /**
030:         * A pool of database connections.
031:         * 
032:         * @author Michael Bell
033:         * @version $Revision: 1.2 $
034:         *
035:         */
036:        public class DBConnectionPool extends AbstractPool {
037:
038:            /**
039:             * The database URI
040:             */
041:            private String dsn;
042:
043:            /**
044:             * The database user name
045:             */
046:            private String usr;
047:
048:            /**
049:             * The database user password
050:             */
051:            private String pwd;
052:
053:            /**
054:             * Logger for this class
055:             */
056:            private static final Logger m_logger = Logger
057:                    .getLogger(DBConnectionPool.class.getName());
058:
059:            /**
060:             * Constructs a DB connection pool which will pool connections with
061:             * the given parameters.
062:             * 
063:             * @param driver the JDBC driver class name
064:             * @param dsn the database URI
065:             * @param usr the database user name
066:             * @param pwd the database user password
067:             */
068:            public DBConnectionPool(String driver, String dsn, String usr,
069:                    String pwd) {
070:                try {
071:                    Class.forName(driver).newInstance();
072:                } catch (Exception e) {
073:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
074:                }
075:
076:                this .dsn = dsn;
077:                this .usr = usr;
078:                this .pwd = pwd;
079:
080:                this .setMinPoolSize(5);
081:            }
082:
083:            /* (non-Javadoc)
084:             * @see org.openharmonise.commons.pool.AbstractPool#create()
085:             */
086:            public Object create() throws SQLException {
087:                return (DriverManager.getConnection(dsn, usr, pwd));
088:            }
089:
090:            /* (non-Javadoc)
091:             * @see org.openharmonise.commons.pool.AbstractPool#validate(java.lang.Object)
092:             */
093:            public boolean validate(Object o) {
094:                try {
095:                    return (!((Connection) o).isClosed());
096:                } catch (SQLException e) {
097:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
098:
099:                    return false;
100:                }
101:            }
102:
103:            /* (non-Javadoc)
104:             * @see org.openharmonise.commons.pool.AbstractPool#expire(java.lang.Object)
105:             */
106:            public void expire(Object o) {
107:                try {
108:                    ((Connection) o).close();
109:                } catch (SQLException e) {
110:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
111:                }
112:            }
113:
114:            /**
115:             * Returns a connection from the pool.
116:             * 
117:             * @return a connection from the pool
118:             * @throws SQLException if an error occurs
119:             */
120:            public Connection borrowConnection() throws SQLException {
121:                try {
122:                    return (Connection) super .checkOut();
123:                } catch (Exception e) {
124:                    throw (SQLException) e;
125:                }
126:            }
127:
128:            /**
129:             * Checks the connection back in to the pool.
130:             * 
131:             * @param c the connection to be checked back in
132:             */
133:            public void returnConnection(Connection c) {
134:                super.checkIn(c);
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.