00001
package com.quadcap.jdbc;
00002
00003
00004
00005
00006
00007
00008
import java.io.File;
00009
00010
import java.util.HashMap;
00011
import java.util.Map;
00012
import java.util.Properties;
00013
00014
import java.sql.Connection;
00015
import java.sql.Driver;
00016
import java.sql.DriverManager;
00017
import java.sql.DriverPropertyInfo;
00018
import java.sql.SQLException;
00019
00020
import com.quadcap.sql.Version;
00021
00022
import com.quadcap.io.dir.ClassLoader;
00023
import com.quadcap.io.dir.Directory;
00024
00025
import com.quadcap.util.Util;
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 public class MultiDriver implements Driver {
00046 static Map
versions =
new HashMap();
00047
00048
static {
00049
try {
00050 DriverManager.registerDriver(
new MultiDriver());
00051 }
catch (Throwable t) {}
00052 }
00053
00054
00055
00056
00057 public MultiDriver() {}
00058
00059
00060
00061
00062
00063 public Connection connect(String url, Properties info)
00064
throws SQLException
00065 {
00066
try {
00067 Properties p =
new Properties();
00068 p.putAll(info);
00069
int idx = url.indexOf(
';');
00070
if (idx >= 0) {
00071 p.putAll(
Util.parsePropsString(url.substring(idx+1)));
00072 }
00073 String qed = p.getProperty(
"qed");
00074
if (qed == null) {
00075
throw new SQLException(
"MultiDriver requires 'qed' property");
00076 }
00077
Driver qdriver = (
Driver)
versions.get(qed);
00078
if (qdriver == null) {
00079
ClassLoader cl;
00080 cl =
new ClassLoader(
Directory.getDirectory(
new File(qed)));
00081 Class qdclass = cl.
loadClass(
"com.quadcap.jdbc.JdbcDriver");
00082 qdriver = (
Driver)(qdclass.newInstance());
00083
versions.put(qed, qdriver);
00084 }
00085 String xurl =
"jdbc:qed:" + url.substring(
"jdbc:mqed:".length());
00086
return qdriver.connect(xurl, info);
00087 }
catch (SQLException ex) {
00088
throw ex;
00089 }
catch (Throwable t) {
00090
throw new SQLException(t.toString());
00091 }
00092 }
00093
00094 public boolean acceptsURL(String url)
throws SQLException {
00095
return url.startsWith(
"jdbc:mqed:");
00096 }
00097
00098 public DriverPropertyInfo[]
getPropertyInfo(String url, Properties info)
00099
throws SQLException
00100 {
00101
return null;
00102 }
00103
00104 public int getMajorVersion() {
00105
return Version.majorVersion;
00106 }
00107
00108 public int getMinorVersion() {
00109
return Version.minorVersion;
00110 }
00111
00112 public boolean jdbcCompliant() {
00113
return true;
00114 }
00115 }
00116