Source Code Cross Referenced for SimpleConnectionManager.java in  » Database-JDBC-Connection-Pool » sequoia-2.10.9 » org » continuent » sequoia » controller » connection » 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 » sequoia 2.10.9 » org.continuent.sequoia.controller.connection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Sequoia: Database clustering technology.
003:         * Copyright (C) 2002-2004 French National Institute For Research In Computer
004:         * Science And Control (INRIA).
005:         * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006:         * Contact: sequoia@continuent.org
007:         * 
008:         * Licensed under the Apache License, Version 2.0 (the "License");
009:         * you may not use this file except in compliance with the License.
010:         * 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, software
015:         * distributed under the License is distributed on an "AS IS" BASIS,
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:         * See the License for the specific language governing permissions and
018:         * limitations under the License. 
019:         *
020:         * Initial developer(s): Emmanuel Cecchet.
021:         * Contributor(s): ______________________.
022:         */package org.continuent.sequoia.controller.connection;
023:
024:        import java.sql.Connection;
025:        import java.sql.SQLException;
026:
027:        import org.continuent.sequoia.common.exceptions.UnreachableBackendException;
028:        import org.continuent.sequoia.common.xml.DatabasesXmlTags;
029:
030:        /**
031:         * This connection manager creates a new <code>Connection</code> every time
032:         * the {@link #getConnection}method is called.
033:         * 
034:         * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
035:         * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
036:         * @version 1.0
037:         */
038:        public class SimpleConnectionManager extends AbstractConnectionManager {
039:            private int nbOfConnections = 0;
040:
041:            /**
042:             * Creates a new <code>SimpleConnectionManager</code> instance.
043:             * 
044:             * @param backendUrl URL of the <code>DatabaseBackend</code> owning this
045:             *          connection manager.
046:             * @param backendName name of the <code>DatabaseBackend</code> owning this
047:             *          connection manager.
048:             * @param login backend connection login to be used by this connection
049:             *          manager.
050:             * @param password backend connection password to be used by this connection
051:             *          manager.
052:             * @param driverPath path for driver
053:             * @param driverClassName class name for driver
054:             */
055:            public SimpleConnectionManager(String backendUrl,
056:                    String backendName, String login, String password,
057:                    String driverPath, String driverClassName) {
058:                super (backendUrl, backendName, login, password, driverPath,
059:                        driverClassName);
060:            }
061:
062:            /**
063:             * @see java.lang.Object#clone()
064:             */
065:            protected Object clone() throws CloneNotSupportedException {
066:                return new SimpleConnectionManager(backendUrl, backendName,
067:                        rLogin, rPassword, driverPath, driverClassName);
068:            }
069:
070:            /**
071:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#clone(String,
072:             *      String)
073:             */
074:            public AbstractConnectionManager clone(String rLogin,
075:                    String rPassword) {
076:                return new SimpleConnectionManager(backendUrl, backendName,
077:                        rLogin, rPassword, driverPath, driverClassName);
078:            }
079:
080:            /**
081:             * Does nothing.
082:             * 
083:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#doConnectionInitialization()
084:             */
085:            protected void doConnectionInitialization() throws SQLException {
086:                initialized = true;
087:                if (idlePersistentConnectionPingInterval > 0) {
088:                    persistentConnectionPingerThread = new IdlePersistentConnectionsPingerThread(
089:                            backendName, this );
090:                    persistentConnectionPingerThread.start();
091:                    idlePersistentConnectionPingRunning = true;
092:                }
093:            }
094:
095:            /**
096:             * Does nothing.
097:             * 
098:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#doConnectionFinalization()
099:             */
100:            protected void doConnectionFinalization() throws SQLException {
101:                initialized = false;
102:            }
103:
104:            /**
105:             * Gets a new connection from the underlying driver.
106:             * 
107:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#getConnection()
108:             */
109:            public PooledConnection getConnection()
110:                    throws UnreachableBackendException {
111:                if (!initialized) {
112:                    logger
113:                            .error("Requesting a connection from a non-initialized connection manager");
114:                    return null;
115:                }
116:                if (isShutdown) {
117:                    return null;
118:                }
119:                addConnection();
120:                Connection c = getConnectionFromDriver();
121:                if (c == null) {
122:                    removeConnection();
123:                    logger.error("Unable to get connection from " + backendUrl);
124:                    if (nbOfConnections == 0) {
125:                        logger
126:                                .error("Backend '"
127:                                        + backendUrl
128:                                        + "' is considered unreachable. "
129:                                        + "(No active connection and none can be opened)");
130:                        throw new UnreachableBackendException();
131:                    }
132:                }
133:                return new PooledConnection(c);
134:            }
135:
136:            /**
137:             * Closes the connection.
138:             * 
139:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#releaseConnection(PooledConnection)
140:             */
141:            public void releaseConnection(PooledConnection connection) {
142:                removeConnection();
143:                try {
144:                    connection.close();
145:                } catch (SQLException e) {
146:                    logger.error("Failed to close connection for '"
147:                            + backendUrl + "'", e);
148:                }
149:            }
150:
151:            /**
152:             * Closes the persistent connection.
153:             * 
154:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#releasePersistentConnection(PooledConnection)
155:             */
156:            protected void releasePersistentConnection(PooledConnection c) {
157:                releaseConnection(c);
158:            }
159:
160:            /**
161:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#deleteConnection(PooledConnection)
162:             */
163:            public void deleteConnection(PooledConnection c) {
164:            }
165:
166:            /**
167:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#flagAllConnectionsForRenewal()
168:             */
169:            public void flagAllConnectionsForRenewal() {
170:                // Nothing to do here, all connections are always renewed
171:            }
172:
173:            /**
174:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#getCurrentNumberOfConnections()
175:             */
176:            public int getCurrentNumberOfConnections() {
177:                return nbOfConnections;
178:            }
179:
180:            private synchronized void addConnection() {
181:                nbOfConnections++;
182:            }
183:
184:            private synchronized void removeConnection() {
185:                nbOfConnections--;
186:            }
187:
188:            /**
189:             * @see org.continuent.sequoia.controller.connection.AbstractConnectionManager#getXmlImpl()
190:             */
191:            public String getXmlImpl() {
192:                return "<" + DatabasesXmlTags.ELT_SimpleConnectionManager
193:                        + "/>";
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.