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


001:        /*
002:         *    GeoLBS - OpenSource Location Based Servces toolkit
003:         *    (C) 2004, Julian J. Ray, All Rights Reserved
004:         *
005:         *    This library is free software; you can redistribute it and/or
006:         *    modify it under the terms of the GNU Lesser General Public
007:         *    License as published by the Free Software Foundation;
008:         *    version 2.1 of the License.
009:         *
010:         *    This library is distributed in the hope that it will be useful,
011:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         *    Lesser General Public License for more details.
014:         *
015:         */
016:
017:        package org.geotools.data.geomedia;
018:
019:        import java.lang.reflect.Constructor;
020:        import java.lang.reflect.InvocationTargetException;
021:        import java.lang.reflect.Method;
022:        import java.sql.SQLException;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:        import java.util.logging.Logger;
026:
027:        import javax.sql.ConnectionPoolDataSource;
028:
029:        import org.geotools.data.jdbc.ConnectionPool;
030:        import org.geotools.data.jdbc.ConnectionPoolManager;
031:
032:        /**
033:         * <p>
034:         * Title: GeoTools2 Development
035:         * </p>
036:         * 
037:         * <p>
038:         * Description:
039:         * </p>
040:         * 
041:         * <p>
042:         * Copyright: Copyright (c) 2003
043:         * </p>
044:         * 
045:         * <p>
046:         * Company:
047:         * </p>
048:         * Provides javax.sql.DataSource wrapper around a JDBC object. User passes a JDBC driver string as part of the
049:         * properties. Driver is loaded using Class.forname() from the class path. User also passes a connection string URL as
050:         * part of the properties.
051:         *
052:         * @author Julian J. Ray
053:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/geomedia/src/main/java/org/geotools/data/geomedia/GeoMediaConnectionFactory.java $
054:         * @version 1.0
055:         */
056:        public class GeoMediaConnectionFactory {
057:            /** DOCUMENT ME! */
058:            private static final Logger LOGGER = org.geotools.util.logging.Logging
059:                    .getLogger("org.geotools.data.geomedia");
060:
061:            /** Map that contains Connection Pool Data Sources */
062:            private static Map mDataSources = new HashMap();
063:
064:            // The class name for the JDBC driver
065:
066:            /** DOCUMENT ME! */
067:            private String mDriverClassName;
068:
069:            // The url to the DB
070:
071:            /** DOCUMENT ME! */
072:            private String mPoolKey;
073:
074:            // Connection Parameters
075:
076:            /** DOCUMENT ME! */
077:            private GeoMediaConnectionParam[] mParams;
078:
079:            // The username to login with
080:
081:            /** DOCUMENT ME! */
082:            private String mUsername = "";
083:
084:            /// The password to login with
085:
086:            /** DOCUMENT ME! */
087:            private String mPasswd = "";
088:
089:            /**
090:             * Creates a new Connection object.
091:             *
092:             * @param classname The host name of IP address to connect to.
093:             * @param poolKey The port number on the host. Usually 1433
094:             * @param params The database name on the host
095:             */
096:            public GeoMediaConnectionFactory(String classname, String poolKey,
097:                    GeoMediaConnectionParam[] params) {
098:                mDriverClassName = classname;
099:                mPoolKey = poolKey;
100:                mParams = params;
101:            }
102:
103:            /**
104:             * Creates the real Server Connection. Logs in to the Database and creates the Connection object. If the connection
105:             * pool is not established, a new one is created.
106:             *
107:             * @param user The user name.
108:             * @param pass The password
109:             *
110:             * @return The ConnectionPool object.
111:             *
112:             * @throws SQLException If an error occurs connecting to the DB.
113:             */
114:            public ConnectionPool getConnectionPool(String user, String pass)
115:                    throws SQLException {
116:                String poolKey = mPoolKey + ":" + user + ":" + pass;
117:                ConnectionPoolDataSource poolDataSource = (ConnectionPoolDataSource) mDataSources
118:                        .get(poolKey);
119:
120:                if (poolDataSource == null) {
121:                    try {
122:                        // Attempt to load the driver
123:                        Class driver = Class.forName(mDriverClassName);
124:
125:                        // Get the constructor
126:                        Constructor constr = driver
127:                                .getConstructor(new Class[] {});
128:                        poolDataSource = (ConnectionPoolDataSource) constr
129:                                .newInstance(new Object[] {});
130:
131:                        // Process the connection parameters
132:                        for (int i = 0; i < mParams.length; i++) {
133:                            Method method = driver.getMethod(mParams[i]
134:                                    .getMethodName(), new Class[] { mParams[i]
135:                                    .getClassType() });
136:                            Object ret = method.invoke(poolDataSource,
137:                                    new Object[] { mParams[i].getParam() });
138:                        }
139:
140:                        // Cache the data source
141:                        mDataSources.put(poolKey, poolDataSource);
142:                    } catch (ClassNotFoundException e) {
143:                        throw new SQLException("Driver " + mDriverClassName
144:                                + " not found!");
145:                    } catch (NoSuchMethodException e) {
146:                        throw new SQLException("Driver does not support method"
147:                                + e.getMessage());
148:                    } catch (InstantiationException e) {
149:                        throw new SQLException("Cannot create instance of "
150:                                + mDriverClassName);
151:                    } catch (IllegalAccessException e) {
152:                        throw new SQLException(
153:                                "IllegalAccessException while instantiating connection pool for driver "
154:                                        + mDriverClassName);
155:                    } catch (InvocationTargetException e) {
156:                        throw new SQLException(
157:                                "IllegalAccessException while instantiating connection pool for driver "
158:                                        + mDriverClassName);
159:                    }
160:                }
161:
162:                ConnectionPoolManager manager = ConnectionPoolManager
163:                        .getInstance();
164:                ConnectionPool connectionPool = manager
165:                        .getConnectionPool(poolDataSource);
166:
167:                return connectionPool;
168:            }
169:
170:            /**
171:             * Returns a connection from the connection pool.
172:             *
173:             * @return The connection to the data base.
174:             *
175:             * @throws SQLException If an error occurs.
176:             */
177:            public ConnectionPool getConnectionPool() throws SQLException {
178:                return getConnectionPool(mUsername, mPasswd);
179:            }
180:
181:            /**
182:             * Sets the login credentials.
183:             *
184:             * @param user The username
185:             * @param pass The password
186:             */
187:            public void setLogin(String user, String pass) {
188:                this.mUsername = user;
189:                this.mPasswd = pass;
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.