1 package edu.internet2.middleware.grouperInstaller.driverShim;
2
3 import java.io.File;
4 import java.net.URL;
5 import java.net.URLClassLoader;
6 import java.sql.Connection;
7 import java.sql.Driver;
8 import java.sql.DriverPropertyInfo;
9 import java.sql.SQLException;
10 import java.sql.SQLFeatureNotSupportedException;
11 import java.util.Properties;
12 import java.util.logging.Logger;
13
14
15
16
17
18
19 public abstract class DatabaseShimBase implements Driver {
20
21
22
23
24 private static File jarFile = null;
25
26
27
28
29
30 public static void init(File theJarFile) {
31 jarFile = theJarFile;
32 }
33
34
35
36
37
38 public abstract String getDriverClassName();
39
40
41
42
43 public DatabaseShimBase() {
44
45 try {
46
47 URL u = new URL("jar:file:" + jarFile.getAbsolutePath() + "!/");
48
49 String classname = this.getDriverClassName();
50 URLClassLoader ucl = new URLClassLoader(new URL[] { u });
51 this.driver = (Driver)Class.forName(classname, true, ucl).newInstance();
52 } catch (Exception e) {
53 throw new RuntimeException("Problem loading driver from: " + (jarFile == null ? null : jarFile.getAbsolutePath()), e);
54 }
55 }
56
57
58
59
60 private Driver driver;
61
62
63
64
65 @Override
66 public Connection connect(String url, Properties info) throws SQLException {
67 return this.driver.connect(url, info);
68 }
69
70
71
72
73 @Override
74 public boolean acceptsURL(String url) throws SQLException {
75 return this.driver.acceptsURL(url);
76 }
77
78
79
80
81 @Override
82 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
83 throws SQLException {
84 return this.driver.getPropertyInfo(url, info);
85 }
86
87
88
89
90 @Override
91 public int getMajorVersion() {
92 return this.driver.getMajorVersion();
93 }
94
95
96
97
98 @Override
99 public int getMinorVersion() {
100 return this.driver.getMinorVersion();
101 }
102
103
104
105
106 @Override
107 public boolean jdbcCompliant() {
108 return this.driver.jdbcCompliant();
109 }
110
111
112 public Logger getParentLogger() throws SQLFeatureNotSupportedException {
113 try {
114 return (Logger) Driver.class.getDeclaredMethod("getParentLogger").invoke(this.driver);
115 } catch (Throwable e) {
116 return null;
117 }
118 }
119
120 }