Source Code Cross Referenced for DBBrowserDriverManager.java in  » Database-Client » DBBrowser » org » dbbrowser » drivermanager » 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 » Database Client » DBBrowser » org.dbbrowser.drivermanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.dbbrowser.drivermanager;
002:
003:        import infrastructure.logging.Log;
004:        import java.net.MalformedURLException;
005:        import java.net.URL;
006:        import java.net.URLClassLoader;
007:        import java.sql.Connection;
008:        import java.sql.Driver;
009:        import java.sql.SQLException;
010:        import java.util.Hashtable;
011:        import java.util.Properties;
012:
013:        import org.dbbrowser.security.AsymmetricEncryptionEngine;
014:        import org.dbbrowser.security.EncryptionEngineException;
015:        import org.dbbrowser.ui.UIControllerForQueries;
016:
017:        /**
018:         * Used to get the connection to the database
019:         */
020:        public class DBBrowserDriverManager {
021:            private static DBBrowserDriverManager driverManager = new DBBrowserDriverManager();
022:            private Hashtable pooledConnections = new Hashtable();
023:
024:            /**
025:             * Private constructer as it is a singleton
026:             *
027:             */
028:            private DBBrowserDriverManager() {
029:
030:            }
031:
032:            /**
033:             * Returns the singleton object
034:             * @return
035:             */
036:            public static DBBrowserDriverManager getInstance() {
037:                return driverManager;
038:            }
039:
040:            /**
041:             * Get the connection.  the 'name' attribute in the connectionInfo uniquely identifies a connection.  
042:             * This class pools the connection and returns the same connection for subsequent calls with the 'same' 
043:             * connectionInfo object.  Do not close the connection as it is cached. <br /> <br />
044:             * <ul>
045:             * <li>For MySQL, the url is of the form jdbc:mysql://localhost:3306/mysql</li>
046:             * <li>For Oracle, the url is of the form jdbc:oracle:thin:@localhost:1521:live</li>
047:             * </ul>
048:             * @param connectionInfo
049:             * @param masterPassword
050:             * @return
051:             * @throws DriverManagerException
052:             */
053:            public Connection getConnection(ConnectionInfo connectionInfo,
054:                    String masterPassword) throws DriverManagerException {
055:                Connection connection = null;
056:                Object connectionFromPool = this .pooledConnections
057:                        .get(connectionInfo);
058:                if (connectionFromPool == null) {
059:                    try {
060:                        URL jdbcDriverURL = connectionInfo
061:                                .getJdbcDriverJarFileLocation().toURL();
062:                        URL[] urls = new URL[1];
063:                        urls[0] = jdbcDriverURL;
064:                        URLClassLoader urlClassLoader = new URLClassLoader(urls);
065:                        Class driverClass = Class.forName(connectionInfo
066:                                .getDriverClassName(), true, urlClassLoader);
067:                        Driver driver = (Driver) driverClass.newInstance();
068:
069:                        //Decrypt the password
070:                        String passwordInClearText = AsymmetricEncryptionEngine
071:                                .decrypt(connectionInfo.getPassword(),
072:                                        masterPassword);
073:
074:                        //Get the connection
075:                        Properties props = new Properties();
076:                        props.put("user", connectionInfo.getUsername());
077:                        props.put("password", passwordInClearText);
078:
079:                        //If it is a oracle connection, then check if encryption and checksum is required
080:                        if (UIControllerForQueries.ORACLE_DBMS
081:                                .equals(connectionInfo.getDBMSType())) {
082:                            if (connectionInfo.getEncryptionAlgorithm() != null) {
083:                                props
084:                                        .put(
085:                                                "oracle.net.encryption_types_client",
086:                                                connectionInfo
087:                                                        .getEncryptionAlgorithm());
088:                            }
089:
090:                            if (connectionInfo.getCheckSumAlgorithm() != null) {
091:                                props
092:                                        .put(
093:                                                "oracle.net.crypto_checksum_types_client",
094:                                                connectionInfo
095:                                                        .getCheckSumAlgorithm());
096:                            }
097:                        }
098:
099:                        //Connect
100:                        connection = driver.connect(connectionInfo
101:                                .getDatabaseURL(), props);
102:
103:                        this .pooledConnections.put(connectionInfo, connection);
104:                        Log.getInstance().infoMessage(
105:                                "Connection setup for "
106:                                        + connectionInfo.toString(),
107:                                DBBrowserDriverManager.class.getName());
108:                    } catch (MalformedURLException exc) {
109:                        throw new DriverManagerException(exc);
110:                    } catch (ClassNotFoundException exc) {
111:                        throw new DriverManagerException(exc);
112:                    } catch (InstantiationException exc) {
113:                        throw new DriverManagerException(exc);
114:                    } catch (IllegalAccessException exc) {
115:                        throw new DriverManagerException(exc);
116:                    } catch (SQLException exc) {
117:                        throw new DriverManagerException(exc);
118:                    } catch (EncryptionEngineException exc) {
119:                        throw new DriverManagerException(exc);
120:                    }
121:                } else {
122:                    connection = (Connection) connectionFromPool;
123:                }
124:                return connection;
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.