Source Code Cross Referenced for PooledConnection.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) 2006 Continuent, Inc.
004:         * Contact: sequoia@continuent.org
005:         * 
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License. 
017:         *
018:         * Initial developer(s): Emmanuel Cecchet.
019:         * Contributor(s): ______________________.
020:         */package org.continuent.sequoia.controller.connection;
021:
022:        import java.sql.Connection;
023:        import java.sql.SQLException;
024:        import java.util.LinkedList;
025:        import java.util.List;
026:
027:        /**
028:         * This class defines a PooledConnection that is a connection in a pool with
029:         * associated metadata.
030:         * 
031:         * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
032:         * @version 1.0
033:         */
034:        public class PooledConnection {
035:            private Connection connection;
036:            private boolean mustBeRenewed = false;
037:            private int currentTransactionIsolation = org.continuent.sequoia.driver.Connection.DEFAULT_TRANSACTION_ISOLATION_LEVEL;
038:            private int oldTransactionIsolation;
039:
040:            /*
041:             * List of temporary tables that were defined in this connection.
042:             */
043:            private List temporaryTables;
044:
045:            /**
046:             * Creates a new <code>PooledConnection</code> object
047:             * 
048:             * @param c the real connection to the database
049:             */
050:            public PooledConnection(Connection c) {
051:                this .connection = c;
052:                temporaryTables = new LinkedList();
053:            }
054:
055:            /**
056:             * Returns the real connection to the database
057:             * 
058:             * @return Returns the connection.
059:             */
060:            public Connection getConnection() {
061:                return connection;
062:            }
063:
064:            /**
065:             * Returns true if the connection must be renewed.
066:             * 
067:             * @return Returns true if the connection must be renewed.
068:             */
069:            boolean mustBeRenewed() {
070:                return mustBeRenewed;
071:            }
072:
073:            /**
074:             * Sets the mustBeRenewed value.
075:             * 
076:             * @param mustBeRenewed true if the connection to the database must be
077:             *          renewed.
078:             */
079:            public void setMustBeRenewed(boolean mustBeRenewed) {
080:                this .mustBeRenewed = mustBeRenewed;
081:            }
082:
083:            //
084:            // Transaction isolation related functions
085:            //
086:
087:            /**
088:             * Returns true if this connection is set to the default transaction
089:             * isolation.
090:             * 
091:             * @return true if default isolation is used
092:             */
093:            public boolean isDefaultTransactionIsolation() {
094:                return currentTransactionIsolation == org.continuent.sequoia.driver.Connection.DEFAULT_TRANSACTION_ISOLATION_LEVEL;
095:            }
096:
097:            /**
098:             * Restore the default transaction isolation that was recorded when
099:             * setTransactionIsolation was called. This is a no-op if the transaction
100:             * isolation of the connection is already set to the default.
101:             * 
102:             * @throws SQLException if we failed to restore the transaction isolation on
103:             *           the connection
104:             */
105:            public final void restoreDefaultTransactionIsolation()
106:                    throws SQLException {
107:                if (isDefaultTransactionIsolation())
108:                    return;
109:                connection.setTransactionIsolation(oldTransactionIsolation);
110:                currentTransactionIsolation = org.continuent.sequoia.driver.Connection.DEFAULT_TRANSACTION_ISOLATION_LEVEL;
111:            }
112:
113:            /**
114:             * Sets the transaction isolation on the connection and record its previous
115:             * isolation level.
116:             * 
117:             * @param transactionIsolationLevel The transactionIsolation to set.
118:             * @throws SQLException if we failed to get the current transaction isolation
119:             *           of the connection
120:             */
121:            public final void setTransactionIsolation(
122:                    int transactionIsolationLevel) throws SQLException {
123:                oldTransactionIsolation = connection.getTransactionIsolation();
124:                this .currentTransactionIsolation = transactionIsolationLevel;
125:                connection.setTransactionIsolation(transactionIsolationLevel);
126:            }
127:
128:            /**
129:             * Closes the underlying connection
130:             * 
131:             * @throws SQLException in case of error
132:             */
133:            public void close() throws SQLException {
134:                if (connection != null && !connection.isClosed()) {
135:                    connection.close();
136:                    connection = null;
137:                }
138:            }
139:
140:            /*
141:             * Temporary tables management
142:             */
143:            /**
144:             * Adds a temporary table inside this connection's context
145:             * 
146:             * @param temporaryTable the name of the table to add for this connection
147:             */
148:            public void addTemporaryTables(String temporaryTable) {
149:                if (!existsTemporaryTable(temporaryTable))
150:                    temporaryTables.add(temporaryTable);
151:            }
152:
153:            /**
154:             * Removes the list of temporary tables from this connection's context. This
155:             * is used when releasing the connection to the pool.
156:             */
157:            public void removeAllTemporaryTables() {
158:                temporaryTables.clear();
159:            }
160:
161:            /**
162:             * Check if a temporary table exists inside this connection's context
163:             * 
164:             * @param tableName name of the table that is looked for
165:             * @return true if the table can be find inside this connection
166:             */
167:            public boolean existsTemporaryTable(String tableName) {
168:                return temporaryTables.contains(tableName);
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.