synchronized from quantum plugin
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / sql / MultiSQLServer.java
index 843d57f..4946bf6 100644 (file)
@@ -1,13 +1,9 @@
 package com.quantum.sql;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.InputStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.Driver;
@@ -15,13 +11,13 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Hashtable;
 import java.util.Properties;
 import java.util.Vector;
 
 import com.quantum.model.Bookmark;
 import com.quantum.model.ConnectionException;
 import com.quantum.model.Entity;
+import com.quantum.model.JDBCDriver;
 import com.quantum.model.PasswordFinder;
 import com.quantum.sql.metadata.MetaDataJDBCInterface;
 import com.quantum.sql.metadata.ObjectMetaData;
@@ -39,11 +35,9 @@ public class MultiSQLServer implements ConnectionEstablisher {
     public static final String USERNAME = "user"; //$NON-NLS-1$
     public static final String PASSWORD = "password"; //$NON-NLS-1$
     private static MultiSQLServer instance = null;
-    private Hashtable classLoaderCache = new Hashtable();
     boolean running = true;
 
-    public MultiSQLServer() {
-        //start();
+    private MultiSQLServer() {
     }
     public synchronized static MultiSQLServer getInstance() {
         if (instance == null) {
@@ -145,42 +139,29 @@ public class MultiSQLServer implements ConnectionEstablisher {
         throws ConnectionException {
         LogProxy log = LogProxy.getInstance();
         log.addText(LogProxy.QUERY, "Connecting to: " + bookmark.getName()); //$NON-NLS-1$
-        URL urls[] = new URL[1];
         try {
-            String driverFile = bookmark.getDriverFile();
-            URLClassLoader loader =
-                (URLClassLoader) classLoaderCache.get(driverFile);
-            if (loader == null) {
-                urls[0] = new File(driverFile).toURL();
-                loader = new URLClassLoader(urls);
-                classLoaderCache.put(driverFile, loader);
-                System.out.println("Creating new classloader"); //$NON-NLS-1$
-            } else {
-                System.out.println("Using classloader in cache"); //$NON-NLS-1$
-            }
-            Class driverClass = loader.loadClass(bookmark.getDriver());
-            Driver driver = (Driver) driverClass.newInstance();
-            Properties props = new Properties();
-            props.put(USERNAME, bookmark.getUsername());
-            props.put(PASSWORD, password);
-            Connection connection =
-                driver.connect(bookmark.getConnect(), props);
-            if (connection == null) {
-                throw new ConnectionException("Error: Driver returned a null connection: " + bookmark.toString()); //$NON-NLS-1$
+               JDBCDriver jdbcDriver = bookmark.getJDBCDriver();
+            Driver driver = jdbcDriver.getDriver();
+            Connection connection = null;
+            if (driver != null) {
+                   Properties props = new Properties();
+                   props.put(USERNAME, bookmark.getUsername());
+                   props.put(PASSWORD, password);
+                   connection =
+                       driver.connect(bookmark.getConnect(), props);
+                   if (connection == null) {
+                       throw new ConnectionException("Error: Driver returned a null connection: " + bookmark.toString()); //$NON-NLS-1$
+                   }
+                   
+                   DatabaseMetaData metaData = connection.getMetaData();
+                   jdbcDriver.setName(metaData.getDriverName());
+                   jdbcDriver.setVersion(metaData.getDriverVersion());
+                   log.addText(LogProxy.RESULTS, "Connected to: " + bookmark.getName()); //$NON-NLS-1$
+                   System.out.println("Connected"); //$NON-NLS-1$
             }
-            log.addText(LogProxy.RESULTS, "Connected to: " + bookmark.getName()); //$NON-NLS-1$
-            System.out.println("Connected"); //$NON-NLS-1$
             return connection;
         } catch (SQLException e) {
             throw new ConnectionException(e);
-        } catch (MalformedURLException e) {
-            throw new ConnectionException(e);
-        } catch (ClassNotFoundException e) {
-            throw new ConnectionException(e);
-        } catch (InstantiationException e) {
-            throw new ConnectionException(e);
-        } catch (IllegalAccessException e) {
-            throw new ConnectionException(e);
         }
     }
        public SQLResults execute(Connection con, String s) throws SQLException {