1 package com.quadcap.jdbc; 2 3 7 8 import java.io.File ; 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 import java.util.Properties ; 13 14 import java.sql.Connection ; 15 import java.sql.Driver ; 16 import java.sql.DriverManager ; 17 import java.sql.DriverPropertyInfo ; 18 import java.sql.SQLException ; 19 20 import com.quadcap.sql.Version; 21 22 import com.quadcap.io.dir.ClassLoader; 23 import com.quadcap.io.dir.Directory; 24 25 import com.quadcap.util.Util; 26 27 45 public class MultiDriver implements Driver { 46 static Map versions = new HashMap (); 47 48 static { 49 try { 50 DriverManager.registerDriver(new MultiDriver()); 51 } catch (Throwable t) {} 52 } 53 54 57 public MultiDriver() {} 58 59 63 public Connection connect(String url, Properties info) 64 throws SQLException 65 { 66 try { 67 Properties p = new Properties (); 68 p.putAll(info); 69 int idx = url.indexOf(';'); 70 if (idx >= 0) { 71 p.putAll(Util.parsePropsString(url.substring(idx+1))); 72 } 73 String qed = p.getProperty("qed"); 74 if (qed == null) { 75 throw new SQLException ("MultiDriver requires 'qed' property"); 76 } 77 Driver qdriver = (Driver )versions.get(qed); 78 if (qdriver == null) { 79 ClassLoader cl; 80 cl = new ClassLoader (Directory.getDirectory(new File (qed))); 81 Class qdclass = cl.loadClass("com.quadcap.jdbc.JdbcDriver"); 82 qdriver = (Driver )(qdclass.newInstance()); 83 versions.put(qed, qdriver); 84 } 85 String xurl = "jdbc:qed:" + url.substring("jdbc:mqed:".length()); 86 return qdriver.connect(xurl, info); 87 } catch (SQLException ex) { 88 throw ex; 89 } catch (Throwable t) { 90 throw new SQLException (t.toString()); 91 } 92 } 93 94 public boolean acceptsURL(String url) throws SQLException { 95 return url.startsWith("jdbc:mqed:"); 96 } 97 98 public DriverPropertyInfo [] getPropertyInfo(String url, Properties info) 99 throws SQLException 100 { 101 return null; 102 } 103 104 public int getMajorVersion() { 105 return Version.majorVersion; 106 } 107 108 public int getMinorVersion() { 109 return Version.minorVersion; 110 } 111 112 public boolean jdbcCompliant() { 113 return true; 114 } 115 } 116 117 | Popular Tags |