Source Code Cross Referenced for ExternalJdbcConnectionSource.java in  » Testing » PolePosition-0.20 » com » versant » core » jdbc » conn » 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 » Testing » PolePosition 0.20 » com.versant.core.jdbc.conn 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998 - 2005 Versant Corporation
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         * Versant Corporation - initial API and implementation
010:         */
011:        package com.versant.core.jdbc.conn;
012:
013:        import com.versant.core.jdbc.JdbcConnectionSource;
014:        import com.versant.core.logging.LogEventStore;
015:
016:        import javax.sql.DataSource;
017:        import java.sql.Connection;
018:        import java.sql.SQLException;
019:
020:        /**
021:         * Gets connections from one or more java.sql.DataSource's and/or a
022:         * JDBCConnectionPool. If there are 2 DataSource's then the second is used
023:         * for highPriority (keygen) connections. If there is only one DataSource
024:         * and a pool then the pool is used for highPriority connections. Otherwise
025:         * the first DataSource is used.
026:         * <p/>
027:         * Connections obtained from the DataSource(s) may optionally have
028:         * PreparedStatement pooling enabled for them. Operations on these connections
029:         * will also be logged depending on the logging level.
030:         */
031:        public class ExternalJdbcConnectionSource implements 
032:                JdbcConnectionSource {
033:
034:            private DataSource ds1;
035:            private DataSource ds2;
036:            private JDBCConnectionPool pool;
037:            private LogEventStore pes;
038:            private String url;
039:            private String driverName;
040:
041:            private boolean usePsPool;
042:            private int psCacheMax;
043:            private boolean clearBatch;
044:
045:            public ExternalJdbcConnectionSource(DataSource ds1, DataSource ds2,
046:                    JDBCConnectionPool pool, LogEventStore pes) {
047:                this .ds1 = ds1;
048:                this .ds2 = ds2;
049:                this .pool = pool;
050:                this .pes = pes;
051:            }
052:
053:            public void setUrl(String url) {
054:                this .url = url;
055:            }
056:
057:            public void setDriverName(String driverName) {
058:                this .driverName = driverName;
059:            }
060:
061:            public boolean isUsePsPool() {
062:                return usePsPool;
063:            }
064:
065:            /**
066:             * Use PreparedStatement pooling on connections obtained from DataSource's
067:             * or not.
068:             */
069:            public void setUsePsPool(boolean usePsPool) {
070:                this .usePsPool = usePsPool;
071:            }
072:
073:            public int getPsCacheMax() {
074:                return psCacheMax;
075:            }
076:
077:            /**
078:             * Limit the number of cached PreparedStatement's per connection to this
079:             * if PreparedStatement pooling is enabled.
080:             */
081:            public void setPsCacheMax(int psCacheMax) {
082:                this .psCacheMax = psCacheMax;
083:            }
084:
085:            public boolean isClearBatch() {
086:                return clearBatch;
087:            }
088:
089:            /**
090:             * Invoke clearBatch on PreparedStatements returned to the pool
091:             * if PreparedStatement pooling is enabled.
092:             */
093:            public void setClearBatch(boolean clearBatch) {
094:                this .clearBatch = clearBatch;
095:            }
096:
097:            public Connection getConnection(boolean highPriority,
098:                    boolean autoCommit) throws SQLException {
099:                if (highPriority) {
100:                    if (pool != null) {
101:                        return pool.getConnection(false, autoCommit);
102:                    } else if (ds2 != null) {
103:                        return getConnection(ds2);
104:                    }
105:                }
106:                return getConnection(ds1);
107:            }
108:
109:            /**
110:             * Get a Connection from ds and wrap it.
111:             */
112:            protected Connection getConnection(DataSource ds)
113:                    throws SQLException {
114:                return new LoggingConnection(ds.getConnection(), pes,
115:                        usePsPool, psCacheMax, clearBatch);
116:            }
117:
118:            public void returnConnection(Connection con) throws SQLException {
119:                if (con instanceof  PooledConnection) {
120:                    pool.returnConnection(con);
121:                } else {
122:                    con.close();
123:                }
124:            }
125:
126:            public String getURL() {
127:                return url;
128:            }
129:
130:            public String getDriverName() {
131:                return driverName;
132:            }
133:
134:            public void init() {
135:                if (pool != null) {
136:                    pool.init();
137:                }
138:            }
139:
140:            public void destroy() {
141:                ds1 = ds2 = null;
142:                if (pool != null) {
143:                    pool.destroy();
144:                    pool = null;
145:                }
146:            }
147:
148:            public void closeIdleConnections() {
149:                if (pool != null) {
150:                    pool.closeIdleConnections();
151:                }
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.