Source Code Cross Referenced for DataSourceUtil.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » jdbc » datasource » 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 » GIS » GeoTools 2.4.1 » org.geotools.data.jdbc.datasource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005:         *    
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.data.jdbc.datasource;
017:
018:        import java.sql.Connection;
019:        import java.sql.SQLException;
020:
021:        import org.apache.commons.dbcp.BasicDataSource;
022:        import org.geotools.data.DataSourceException;
023:
024:        /**
025:         * Utility methods to build a default connection pool
026:         * 
027:         * @author Andrea Aime - TOPP
028:         * 
029:         */
030:        public class DataSourceUtil {
031:            private DataSourceUtil() {
032:                // singleton
033:            }
034:
035:            /**
036:             * Builds up a default DBCP DataSource that easy to use connection factories
037:             * can use to setup a connection pool.
038:             * 
039:             * @param url
040:             *            the jdbc url
041:             * @param driverName
042:             *            the jdbc driver full qualified class name
043:             * @param username
044:             * @param password
045:             * @param validationQuery
046:             *            the validation query to be used for connection liveliness on
047:             *            borrow, or null, if no check is to be performed
048:             * @return
049:             * @throws DataSourceException
050:             */
051:            public static ManageableDataSource buildDefaultDataSource(
052:                    String url, String driverName, String username,
053:                    String password, String validationQuery)
054:                    throws DataSourceException {
055:                return buildDefaultDataSource(url, driverName, username,
056:                        password, 10, 1, validationQuery, false, 0);
057:            }
058:
059:            /**
060:             * Builds up a default DBCP DataSource that easy to use connection factories
061:             * can use to setup a connection pool.
062:             * 
063:             * @param url
064:             *            the jdbc url
065:             * @param driverName
066:             *            the jdbc driver full qualified class name
067:             * @param username
068:             * @param password
069:             * @param maxActive maximum number of concurrent connections in the pool
070:             * @param minIdle minimum number of concurrent connections in the pool
071:             * @param validationQuery
072:             *            the validation query to be used for connection liveliness on
073:             *            borrow, or null, if no check is to be performed
074:             * @param cachePreparedStatements
075:             *            wheter to cache prepared statements or not
076:             * @return
077:             * @throws DataSourceException
078:             */
079:            public static ManageableDataSource buildDefaultDataSource(
080:                    String url, String driverName, String username,
081:                    String password, int maxActive, int minIdle,
082:                    String validationQuery, boolean cachePreparedStatements,
083:                    int removeAbandonedTimeout) throws DataSourceException {
084:                // basics
085:                BasicDataSource dataSource = new BasicDataSource();
086:                dataSource.setDriverClassName(driverName);
087:                dataSource.setUrl(url);
088:                dataSource.setUsername(username);
089:                dataSource.setPassword(password);
090:                dataSource.setAccessToUnderlyingConnectionAllowed(true);
091:
092:                // pool size
093:                dataSource.setMaxActive(maxActive);
094:                dataSource.setMinIdle(minIdle);
095:
096:                // pool eviction settings
097:                dataSource.setMinEvictableIdleTimeMillis(1000 * 20);
098:                dataSource.setTimeBetweenEvictionRunsMillis(1000 * 10);
099:
100:                // connection validation
101:                if (validationQuery != null) {
102:                    dataSource.setTestOnBorrow(true);
103:                    dataSource.setValidationQuery(validationQuery);
104:                }
105:
106:                // prepared statement cache
107:                if (cachePreparedStatements) {
108:                    dataSource.setPoolPreparedStatements(true);
109:                    dataSource.setMaxOpenPreparedStatements(10);
110:                }
111:
112:                // remove abandoned connections (I know it's deprecated, but we do want
113:                // something shaving off lost connections. Let's give them 5 minutes of 
114:                // continuous usage
115:                if (removeAbandonedTimeout > 0) {
116:                    dataSource.setRemoveAbandoned(true);
117:                    dataSource
118:                            .setRemoveAbandonedTimeout(removeAbandonedTimeout);
119:                    dataSource.setLogAbandoned(true);
120:                }
121:
122:                Connection conn = null;
123:                try {
124:                    conn = dataSource.getConnection();
125:                } catch (Exception e) {
126:                    throw new DataSourceException("Connection test failed ", e);
127:                } finally {
128:                    if (conn != null)
129:                        try {
130:                            conn.close();
131:                        } catch (SQLException e) {
132:                        }
133:                }
134:
135:                return new DBCPDataSource(dataSource);
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.