Source Code Cross Referenced for ConnectionPoolAdapterSingleton.java in  » Portal » mypersonalizer » es » udc » mypersonalizer » kernel » model » repository » sql » plain » 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 » Portal » mypersonalizer » es.udc.mypersonalizer.kernel.model.repository.sql.plain 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/sql/plain/ConnectionPoolAdapterSingleton.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
003:         * $Revision: 1.1.1.1 $
004:         * $Date: 2004/03/25 12:08:36 $
005:         *
006:         * =============================================================================
007:         *
008:         * Copyright (c) 2003, The MyPersonalizer Development Group
009:         * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at 
010:         * University Of A Coruna
011:         * All rights reserved.
012:         *
013:         * Redistribution and use in source and binary forms, with or without
014:         * modification, are permitted provided that the following conditions are met:
015:         *
016:         *  - Redistributions of source code must retain the above copyright notice, 
017:         *    this list of conditions and the following disclaimer.
018:         *
019:         *  - Redistributions in binary form must reproduce the above copyright notice,
020:         *    this list of conditions and the following disclaimer in the documentation
021:         *    and/or other materials provided with the distribution.
022:         *
023:         *  - Neither the name of the University Of A Coruna nor the names of its 
024:         *    contributors may be used to endorse or promote products derived from 
025:         *    this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
028:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
036:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037:         * POSSIBILITY OF SUCH DAMAGE.
038:         *
039:         */
040:
041:        package es.udc.mypersonalizer.kernel.model.repository.sql.plain;
042:
043:        import java.sql.Connection;
044:
045:        import es.udc.mypersonalizer.kernel.config.ConnectionPoolAdapterSingletonConfig;
046:        import es.udc.mypersonalizer.kernel.log.Log;
047:        import es.udc.mypersonalizer.kernel.log.LogManager;
048:        import es.udc.mypersonalizer.kernel.log.LogNamingConventions;
049:        import es.udc.mypersonalizer.kernel.model.repository.sql.config.DatabaseSpecificsConfig;
050:        import es.udc.mypersonalizer.kernel.model.repository.sql.config.DatabaseSpecificsConfigManager;
051:        import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
052:
053:        /**
054:         * This singleton abstract class provides an implementation of the
055:         * Adapter design pattern which provides a way to use any database
056:         * connection pool you want. A default implementation is provided.
057:         * <p>
058:         * This singleton class creates the concrete singleton on run-time the first
059:         * time is needed. The name of such a concrete class is obtained by using the 
060:         * standard "MyPersonalizer" configuration mechanism 
061:         * {@link es.udc.mypersonalizer.kernel.config.ConnectionPoolAdapterSingletonConfig}).
062:         * There is a configuration parameter that specifies the name of the concrete
063:         * singleton class.
064:         *
065:         * @author  Fernando Bellas
066:         * @author  Daniel Fernandez
067:         * @author  Abel Muinho
068:         * @since   1.0
069:         */
070:        public abstract class ConnectionPoolAdapterSingleton {
071:
072:            /**
073:             * The driver for the database, where to connect.
074:             */
075:            private static String connectionDriver = null;
076:
077:            /**
078:             * The URL for the database, where to connect.
079:             */
080:            private static String connectionUrl = null;
081:
082:            /**
083:             * The user name for the database, where to connect.
084:             */
085:            private static String connectionUser = "";
086:
087:            /**
088:             * The password of the user for the database, where to connect.
089:             */
090:            private static String connectionPassword = "";
091:
092:            /**
093:             * The timeout for the process of getting a Connection from the pool.
094:             */
095:            private static long connectionWaitTimeOutSeconds;
096:
097:            /**
098:             * The maximum number of Connections for the pool.
099:             */
100:            private static int connectionMaximumNumber;
101:
102:            /**
103:             * A SQL query that will be used to validate connections from this pool
104:             * before returning them to the caller. If specified, this query 
105:             * <b>MUST</b> be an SQL SELECT statement that returns at least one row.
106:             */
107:            private static String connectionPingQuery = null;
108:
109:            /**
110:             * The singleton instance.
111:             */
112:            private static ConnectionPoolAdapterSingleton singleton = null;
113:
114:            /*
115:             * It uses the standard "MyPersonalizer" configuration mechanism for
116:             * getting the name of the concrete singleton class, and creates the
117:             * instance.
118:             */
119:            static {
120:
121:                try {
122:                    DatabaseSpecificsConfig databaseConfig = DatabaseSpecificsConfigManager
123:                            .getConfig();
124:
125:                    ConnectionPoolAdapterSingletonConfig connectionPoolAdapterSingletonConfig = databaseConfig
126:                            .getConnectionPoolAdapterSingletonConfig();
127:
128:                    String className = connectionPoolAdapterSingletonConfig
129:                            .getClassName();
130:                    connectionDriver = connectionPoolAdapterSingletonConfig
131:                            .getConnectionDriver();
132:                    connectionUrl = connectionPoolAdapterSingletonConfig
133:                            .getConnectionURL();
134:                    connectionUser = connectionPoolAdapterSingletonConfig
135:                            .getConnectionUser();
136:                    connectionPassword = connectionPoolAdapterSingletonConfig
137:                            .getConnectionPassword();
138:                    String connectionWaitTimeOutSecondsStr = connectionPoolAdapterSingletonConfig
139:                            .getConnectionWaitTimeOutSeconds();
140:                    String connectionMaximumNumberStr = connectionPoolAdapterSingletonConfig
141:                            .getConnectionMaximumNumber();
142:                    connectionWaitTimeOutSeconds = (new Long(
143:                            connectionWaitTimeOutSecondsStr)).longValue();
144:                    connectionMaximumNumber = (new Integer(
145:                            connectionMaximumNumberStr)).intValue();
146:                    connectionPingQuery = connectionPoolAdapterSingletonConfig
147:                            .getConnectionPingQuery();
148:
149:                    Class singletonClassName = Class.forName(className);
150:                    singleton = (ConnectionPoolAdapterSingleton) singletonClassName
151:                            .newInstance();
152:
153:                    Log mypersonalizerLog = LogManager
154:                            .getLog(LogNamingConventions.MYPERSONALIZER);
155:
156:                    mypersonalizerLog.write("ConnectionPool started (Driver: "
157:                            + connectionDriver + ", URL: " + connectionUrl
158:                            + ", Timeout: " + connectionWaitTimeOutSeconds
159:                            + ", Maximum pooled connections: "
160:                            + connectionMaximumNumber + ").", null, // no exception
161:                            ConnectionPoolAdapterSingleton.class);
162:
163:                } catch (Exception e) {
164:
165:                    Log mypersonalizerLog = LogManager
166:                            .getLog(LogNamingConventions.MYPERSONALIZER);
167:                    mypersonalizerLog.write(
168:                            "Could not initialize configuration for "
169:                                    + "ConnectionPoolAdapterSingleton", e,
170:                            ConnectionPoolAdapterSingleton.class);
171:
172:                }
173:
174:            }
175:
176:            /**
177:             * Creates an instance of this class
178:             */
179:            protected ConnectionPoolAdapterSingleton() {
180:            }
181:
182:            /**
183:             * Retuns the singleton.
184:             *
185:             * @return the singleton
186:             */
187:            public static ConnectionPoolAdapterSingleton getInstance() {
188:                return singleton;
189:            }
190:
191:            /**
192:             * Gets a <code>Connection</code> from the pool.
193:             *
194:             * @return the connection from the pool
195:             */
196:            public abstract Connection getConnection()
197:                    throws InternalErrorException;
198:
199:            /**
200:             * Gets the connection driver.
201:             *
202:             * @return the connection driver
203:             */
204:            final String getConnectionDriver() {
205:                return connectionDriver;
206:            }
207:
208:            /**
209:             * Gets the connection URL.
210:             *
211:             * @return the connection URL
212:             */
213:            final String getConnectionUrl() {
214:                return connectionUrl;
215:            }
216:
217:            /**
218:             * Gets the connection user.
219:             *
220:             * @return the connection user
221:             */
222:            final String getConnectionUser() {
223:                return connectionUser;
224:            }
225:
226:            /**
227:             * Gets the connection password.
228:             *
229:             * @return the connection password
230:             */
231:            final String getConnectionPassword() {
232:                return connectionPassword;
233:            }
234:
235:            /**
236:             * Gets the time out time for getting a connection, in seconds.
237:             *
238:             * @return the time out time for getting a connection
239:             */
240:            final long getConnectionWaitTimeOutSeconds() {
241:                return connectionWaitTimeOutSeconds;
242:            }
243:
244:            /**
245:             * Gets the maximum number of connections for the pool.
246:             *
247:             * @return the maximum number of connections for the pool
248:             */
249:            final int getConnectionMaximumNumber() {
250:                return connectionMaximumNumber;
251:            }
252:
253:            /**
254:             * Gets the ping query to be executed before returning a connection. A 
255:             * ping query is a SQL command (i.e. a <code>SELECT</code>) that will be 
256:             * executed before a connection is returned. Such a query should
257:             * execute very quickly. It returns <code>null</code> if no ping query will
258:             * be used.
259:             *
260:             * @return the ping query or <code>null</code>
261:             */
262:            final String getConnectionPingQuery() {
263:                return connectionPingQuery;
264:            }
265:
266:        }
w_w___w__.___j___a_v__a2__s.c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.