Source Code Cross Referenced for StandardPooledConnection.java in  » Database-JDBC-Connection-Pool » xapool » org » enhydra » jdbc » standard » 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 » xapool » org.enhydra.jdbc.standard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * XAPool: Open Source XA JDBC Pool
003:         * Copyright (C) 2003 Objectweb.org
004:         * Initial Developer: Lutris Technologies Inc.
005:         * Contact: xapool-public@lists.debian-sf.objectweb.org
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
020:         * USA
021:         */
022:        package org.enhydra.jdbc.standard;
023:
024:        import org.enhydra.jdbc.util.Logger;
025:
026:        import java.sql.Connection;
027:        import java.sql.SQLException;
028:        import java.util.Vector;
029:        import javax.sql.ConnectionEvent;
030:        import javax.sql.ConnectionEventListener;
031:        import javax.sql.PooledConnection;
032:
033:        /**
034:         * Provides an implementation of javax.sql.PooledConnection which
035:         * is completely generic (i.e. it relies only on JDBC 1 functionality).
036:         *
037:         * This class maintains a physical database connection which is
038:         * passed to each StandardXAConnectionHandle when it is created. It is the
039:         * StandardXAConnectionHandle object which the application receives and which
040:         * it perceives as the java.sql.Connection object.
041:         *
042:         * StandardXAConnectionHandle objects pass PreparedStatements back to the
043:         * StandardPooledConnection so that they can be retained across
044:         * StandardXAConnectionHandle instantiations.
045:         */
046:        public class StandardPooledConnection implements  PooledConnection {
047:
048:            protected StandardConnectionPoolDataSource dataSource;
049:            public Connection con; // the physical database connection
050:            public StandardConnectionHandle connectionHandle;
051:            // the last StandardConnectionHandle created
052:            Vector listeners; // objects listening for events on this connection
053:            boolean isClosed; // true if this connection has been closed
054:            public Logger log;
055:
056:            /**
057:             * Creates the physical database connection.
058:             */
059:            public StandardPooledConnection(
060:                    StandardConnectionPoolDataSource dataSource, String user,
061:                    String password) throws SQLException {
062:                this .dataSource = dataSource;
063:                con = dataSource.getConnection(user, password);
064:                listeners = new Vector(5, 5);
065:            }
066:
067:            /**
068:             * Creates a new StandardConnectionHandle for use by an application.
069:             * If there is already a StandardConnectionHandle in use then it is
070:             * closed (i.e. the application has the connection withdrawn).
071:             */
072:            synchronized public Connection getConnection()
073:                    throws java.sql.SQLException {
074:                if (connectionHandle != null) {
075:                    // if there's already a connection handle
076:                    if (!connectionHandle.isClosed()) { // and it hasn't been closed
077:                        connectionHandle.close(); // close it now
078:                    }
079:                }
080:                newConnectionHandle();
081:                return connectionHandle;
082:            }
083:
084:            protected void newConnectionHandle() {
085:                log.debug("StandardPooledConnection:newConnectionHandle");
086:                connectionHandle = new StandardConnectionHandle(this ,
087:                        dataSource.getMasterPrepStmtCache(), dataSource
088:                                .getPreparedStmtCacheSize());
089:            }
090:
091:            public void close() throws java.sql.SQLException {
092:                con.close();
093:                dataSource.getMasterPrepStmtCache().remove(con.toString());
094:            }
095:
096:            public void addConnectionEventListener(
097:                    ConnectionEventListener listener) {
098:                listeners.addElement(listener);
099:            }
100:
101:            public void removeConnectionEventListener(
102:                    ConnectionEventListener listener) {
103:                listeners.removeElement(listener);
104:            }
105:
106:            /**
107:             * Notifies all listeners that the StandardConnectionHandle created by this
108:             * PooledConnection has been closed.
109:             */
110:            void closeEvent() {
111:                ConnectionEvent event = new ConnectionEvent(this );
112:                // create the event that we'll send
113:                for (int i = 0; i < listeners.size(); i++) { // for each listener
114:                    Object obj = listeners.elementAt(i); // get next listener
115:                    ConnectionEventListener cel = (ConnectionEventListener) obj;
116:                    //cast to something more useful
117:                    cel.connectionClosed(event); // notify this listener
118:                }
119:
120:            }
121:
122:            /**
123:             * Invoked when a fatal connection error occurs, 
124:             * just before an SQLException is thrown to the application
125:             *
126:             * This method is automatically called when a fatal error 
127:             * is detected on the base connection. The base connection 
128:             * is the actual connection that backs the connection
129:             * handle provided by the getConnection() method
130:             */
131:            public void connectionErrorOccurred(ConnectionEvent event) {
132:                for (int i = 0; i < listeners.size(); i++) { // for each listener
133:                    Object obj = listeners.elementAt(i); // get next listener
134:                    ConnectionEventListener cel = (ConnectionEventListener) obj;
135:                    //cast to something more useful
136:                    cel.connectionErrorOccurred(event); // notify this listener
137:                    //cel.connectionClosed (event);				// notify this listener
138:                }
139:            }
140:
141:            /**
142:             * Access method allowing access to the underlying physical connection.
143:             */
144:            public Connection getPhysicalConnection() {
145:                return con;
146:            }
147:
148:            public void setLogger(Logger alog) {
149:                log = alog;
150:            }
151:
152:            public String toString() {
153:                try {
154:                    StringBuffer sb = new StringBuffer();
155:                    sb.append("StandardPooledConnection:\n");
156:                    sb.append("     is closed local=<" + this .isClosed + ">\n");
157:                    sb.append("     is closed con=<" + con.isClosed() + ">\n");
158:                    sb.append("     connection =<" + this .con + ">\n");
159:
160:                    return sb.toString();
161:                } catch (Exception e) {
162:                    e.printStackTrace();
163:                    return null;
164:                }
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.