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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) Copyright IBM Corporation, 2005. All rights reserved.
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:         */
017:        package org.geotools.data.db2;
018:
019:        import com.ibm.db2.jcc.DB2ConnectionPoolDataSource;
020:        import org.geotools.data.jdbc.ConnectionPool;
021:        import org.geotools.data.jdbc.ConnectionPoolManager;
022:        import org.geotools.data.jdbc.datasource.DataSourceFinder;
023:        import org.geotools.data.jdbc.datasource.DataSourceUtil;
024:
025:        import java.sql.SQLException;
026:        import java.util.HashMap;
027:        import java.util.Map;
028:        import java.util.logging.Logger;
029:        import javax.sql.ConnectionPoolDataSource;
030:        import javax.sql.DataSource;
031:
032:        /**
033:         * A factory to create a DB2 Connection based on the needed parameters.
034:         *
035:         * @author David Adler - IBM Corporation
036:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/db2/src/main/java/org/geotools/data/db2/DB2ConnectionFactory.java $
037:         * @deprecated Use {@link DataSource}, {@link DataSourceUtil} and {@link DataSourceFinder} instead
038:         */
039:        public class DB2ConnectionFactory {
040:            private static final Logger LOGGER = org.geotools.util.logging.Logging
041:                    .getLogger("org.geotools.data.db2");
042:            private static final String DB2_URL_PREFIX = "jdbc:db2://";
043:            private static Map DATA_SOURCES = new HashMap();
044:            private String dbURL = null;
045:            private String dbname = null;
046:            private String user = null;
047:            private String pw = null;
048:            private String host = null;
049:            private String portnum = null;
050:
051:            /**
052:             * Creates a new DB2ConnectionFactory from a host name, port number, and
053:             * database name.
054:
055:             * If the port number is zero we will try to use the JDBC type 2 driver
056:             * and if the port number is non-zer, we will try to use the JDBC type 4
057:             * driver
058:             *
059:             * @param host the DB2 host name
060:             * @param portnum the TCP/IP port number for the DB2 client connection
061:             * @param dbname the DB2 database name
062:             */
063:            public DB2ConnectionFactory(String host, String portnum,
064:                    String dbname) {
065:                super ();
066:                this .dbURL = DB2_URL_PREFIX + host + ":" + portnum + "/"
067:                        + dbname;
068:                this .dbname = dbname;
069:                this .portnum = portnum;
070:                this .host = host;
071:            }
072:
073:            /**
074:             * Sets database login information.
075:             *
076:             * @param user the database user name
077:             * @param pw the user's database password
078:             */
079:            public void setLogin(String user, String pw) {
080:                this .user = user;
081:                this .pw = pw;
082:            }
083:
084:            /**
085:             * Returns the database URL string for this connection.
086:             *
087:             * @return dbURL
088:             */
089:            public String getDbURL() {
090:                return this .dbURL;
091:            }
092:
093:            /**
094:             * Returns a ConnectionPool.  Assumes that the required connection
095:             * information: database name, user name and password have already been
096:             * set.
097:             *
098:             * @return a ConnectionPool object
099:             *
100:             * @throws SQLException if we fail to get a database connection
101:             */
102:            public ConnectionPool getConnectionPool() throws SQLException {
103:                String key = this .dbURL + this .user + this .pw;
104:                DB2ConnectionPoolDataSource poolDataSource = (DB2ConnectionPoolDataSource) DATA_SOURCES
105:                        .get(key);
106:
107:                // Create a new pool data source if one doesn't already exist.
108:                if (poolDataSource == null) {
109:                    poolDataSource = new DB2ConnectionPoolDataSource();
110:                    int portValue = Integer.valueOf(portnum).intValue();
111:                    int driverType = 4;
112:                    poolDataSource = new DB2ConnectionPoolDataSource();
113:                    if (portValue == 0) { // If there is no port number, use type 2 driver
114:                        driverType = 2;
115:                    }
116:                    poolDataSource.setDriverType(driverType);
117:                    poolDataSource.setPortNumber(portValue);
118:                    poolDataSource.setServerName(host);
119:                    poolDataSource.setDatabaseName(this .dbname);
120:                    poolDataSource.setUser(this .user);
121:                    poolDataSource.setPassword(this .pw);
122:                    DATA_SOURCES.put(key, poolDataSource);
123:                    LOGGER
124:                            .info("Created new DB2ConnectionPoolDataSource for dbUrl "
125:                                    + this .dbURL);
126:                }
127:
128:                ConnectionPoolManager manager = ConnectionPoolManager
129:                        .getInstance();
130:                ConnectionPool connectionPool = manager
131:                        .getConnectionPool((ConnectionPoolDataSource) poolDataSource);
132:
133:                LOGGER.info("Successfully obtained DB2 ConnectionPool");
134:
135:                return connectionPool;
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.