Source Code Cross Referenced for DBConnectionPooler.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.*;
022:        import java.util.*;
023:
024:        /**
025:         * A singleton class which provides access to database connection pools. A single
026:         * static method provides access to each instance, each instance then provides access to an 
027:         * individual pool for connections to any one database.
028:         * 
029:         * @author Michael Bell
030:         * @version $Revision: 1.1 $
031:         *
032:         */
033:        public class DBConnectionPooler {
034:
035:            /**
036:             * Map of database connectin pools.
037:             */
038:            private static Map m_DBCPinstance_map = Collections
039:                    .synchronizedMap(new HashMap(50));
040:
041:            /**
042:             * Connection pool for this instance.
043:             */
044:            private DBConnectionPool m_broker = null;
045:
046:            /**
047:             * Constructs a pooler instance with the given database parameters.
048:             * 
049:             * @param driver the JDBC driver class name
050:             * @param dsn the database URI
051:             * @param usr the database user name
052:             * @param pwd the database user password
053:             * @throws DataStoreException if an error occurs creating the pool
054:             */
055:            private DBConnectionPooler(String driver, String dsn, String usr,
056:                    String pwd) throws DataStoreException {
057:                try {
058:                    m_broker = new DBConnectionPool(driver, dsn, usr, pwd);
059:                } catch (Exception e) {
060:                    throw new DataStoreException(
061:                            "Fatal Error in Connection Pool,", e);
062:                }
063:            }
064:
065:            /**
066:             * Returns the number of connection in the pool.
067:             * 
068:             * @return the number of connection in the pool
069:             */
070:            public int getNumConnections() {
071:                return m_broker.countObjects();
072:            }
073:
074:            /**
075:             * Returns a connection from the pool.
076:             * 
077:             * @return a connection from the pool
078:             * @throws SQLException if an error occurs
079:             */
080:            public Connection getConnection() throws SQLException {
081:                return m_broker.borrowConnection();
082:            }
083:
084:            /**
085:             * Returns the connection to the pool.
086:             * 
087:             * @param conn the connection to be returned to the pool
088:             */
089:            public void freeConnection(Connection conn) {
090:                m_broker.returnConnection(conn);
091:            }
092:
093:            /**
094:             * Returns the instance of the pooler that corresponds to the given
095:             * database parameters.
096:             * 
097:             * @param driver the JDBC driver class name
098:             * @param dsn the database URI
099:             * @param usr the database user name
100:             * @param pwd the database user password
101:             * @return the instance of the pooler that corresponds to the given
102:             * database parameters
103:             * @throws DataStoreException if an error occurs creating the connection pool
104:             */
105:            synchronized public static DBConnectionPooler getInstance(
106:                    String driver, String dsn, String usr, String pwd)
107:                    throws DataStoreException {
108:
109:                StringBuffer sbuf = new StringBuffer();
110:
111:                sbuf.append(driver).append(":").append(dsn).append(":").append(
112:                        usr).append(":").append(pwd);
113:
114:                String sMapKey = sbuf.toString();
115:
116:                DBConnectionPooler DBCPinstance = (DBConnectionPooler) m_DBCPinstance_map
117:                        .get(sMapKey);
118:
119:                if (DBCPinstance == null) {
120:                    DBCPinstance = new DBConnectionPooler(driver, dsn, usr, pwd);
121:
122:                    m_DBCPinstance_map.put(sMapKey, DBCPinstance);
123:                }
124:
125:                return DBCPinstance;
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.