Lines 11-16
Link Here
|
11 |
******************************************************************************/ |
11 |
******************************************************************************/ |
12 |
package org.eclipse.datatools.connectivity.drivers.jdbc; |
12 |
package org.eclipse.datatools.connectivity.drivers.jdbc; |
13 |
|
13 |
|
|
|
14 |
import java.io.File; |
15 |
import java.net.MalformedURLException; |
16 |
import java.net.URL; |
17 |
import java.net.URLClassLoader; |
14 |
import java.sql.Connection; |
18 |
import java.sql.Connection; |
15 |
import java.sql.DatabaseMetaData; |
19 |
import java.sql.DatabaseMetaData; |
16 |
import java.sql.Driver; |
20 |
import java.sql.Driver; |
Lines 21-26
Link Here
|
21 |
import org.eclipse.datatools.connectivity.DriverConnectionBase; |
25 |
import org.eclipse.datatools.connectivity.DriverConnectionBase; |
22 |
import org.eclipse.datatools.connectivity.IConnectionProfile; |
26 |
import org.eclipse.datatools.connectivity.IConnectionProfile; |
23 |
import org.eclipse.datatools.connectivity.Version; |
27 |
import org.eclipse.datatools.connectivity.Version; |
|
|
28 |
import org.eclipse.datatools.connectivity.drivers.DriverMgmtMessages; |
29 |
import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants; |
24 |
import org.eclipse.datatools.connectivity.internal.ConnectivityPlugin; |
30 |
import org.eclipse.datatools.connectivity.internal.ConnectivityPlugin; |
25 |
|
31 |
|
26 |
/** |
32 |
/** |
Lines 44-60
Link Here
|
44 |
private Version mTechVersion = Version.NULL_VERSION; |
50 |
private Version mTechVersion = Version.NULL_VERSION; |
45 |
private Version mServerVersion = Version.NULL_VERSION; |
51 |
private Version mServerVersion = Version.NULL_VERSION; |
46 |
private String mServerName; |
52 |
private String mServerName; |
|
|
53 |
|
54 |
private boolean mHasDriver = true; |
47 |
|
55 |
|
48 |
public JDBCConnection(IConnectionProfile profile, Class factoryClass) { |
56 |
public JDBCConnection(IConnectionProfile profile, Class factoryClass) { |
49 |
super(profile, factoryClass); |
57 |
super(profile, factoryClass); |
50 |
} |
58 |
} |
51 |
|
59 |
|
|
|
60 |
public void open() { |
61 |
if (mConnection != null) { |
62 |
close(); |
63 |
} |
64 |
|
65 |
mConnection = null; |
66 |
mConnectException = null; |
67 |
|
68 |
try { |
69 |
if (getDriverDefinition() != null) |
70 |
super.open(); |
71 |
} catch (Exception e) { |
72 |
if (e.getMessage().equalsIgnoreCase(ConnectivityPlugin.getDefault().getResourceString("DriverConnectionBase.error.driverDefinitionNotSpecified"))) //$NON-NLS-1$ |
73 |
{ |
74 |
if (profileHasDriverDetails()) { |
75 |
mHasDriver = false; |
76 |
} |
77 |
else { |
78 |
e.printStackTrace(); |
79 |
} |
80 |
} |
81 |
else |
82 |
e.printStackTrace(); |
83 |
} |
84 |
internalCreateConnection(); |
85 |
} |
86 |
|
87 |
public String[] getJarListAsArray(String jarList) { |
88 |
if (jarList != null) { |
89 |
if (jarList.length() == 0) |
90 |
return new String[0]; |
91 |
String[] paths = parseString(jarList, |
92 |
IDriverMgmtConstants.PATH_DELIMITER); |
93 |
return paths; |
94 |
} |
95 |
return null; |
96 |
} |
97 |
|
98 |
public ClassLoader createClassLoader(ClassLoader parentCL) throws Exception { |
99 |
Properties props = getConnectionProfile().getBaseProperties(); |
100 |
String jarList = |
101 |
props.getProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST); |
102 |
if ((jarList == null || jarList.trim().length() == 0)) { |
103 |
throw new Exception( |
104 |
DriverMgmtMessages.getString("DriverInstance.error.jarListNotDefined")); //$NON-NLS-1$ |
105 |
} |
106 |
|
107 |
String[] jarStrings = getJarListAsArray(jarList); |
108 |
URL[] jars = new URL[jarStrings.length]; |
109 |
for (int index = 0, count = jars.length; index < count; ++index) { |
110 |
try { |
111 |
jars[index] = new File(jarStrings[index]).toURL(); |
112 |
} |
113 |
catch (MalformedURLException e) { |
114 |
throw new Exception(DriverMgmtMessages.getString("DriverInstance.error.invalidClassPath"), e); //$NON-NLS-1$ |
115 |
} |
116 |
} |
117 |
if (parentCL == null) { |
118 |
return URLClassLoader.newInstance(jars); |
119 |
} |
120 |
return URLClassLoader.newInstance(jars, parentCL); |
121 |
} |
122 |
|
123 |
private void internalCreateConnection() { |
124 |
try { |
125 |
ClassLoader parentCL = getParentClassLoader(); |
126 |
ClassLoader driverCL = createClassLoader(parentCL); |
127 |
|
128 |
mConnection = createConnection(driverCL); |
129 |
|
130 |
if (mConnection == null) { |
131 |
// Connect attempt failed without throwing an exception. |
132 |
// We'll generate one for them. |
133 |
throw new Exception(ConnectivityPlugin.getDefault().getResourceString("DriverConnectionBase.error.unknown")); //$NON-NLS-1$ |
134 |
} |
135 |
|
136 |
initVersions(); |
137 |
updateVersionCache(); |
138 |
} |
139 |
catch (Throwable t) { |
140 |
mConnectException = t; |
141 |
clearVersionCache(); |
142 |
} |
143 |
} |
144 |
|
145 |
private boolean profileHasDriverDetails() { |
146 |
Properties props = getConnectionProfile().getBaseProperties(); |
147 |
String driverClass = |
148 |
props.getProperty(IJDBCConnectionProfileConstants.DRIVER_CLASS_PROP_ID); |
149 |
String jarList = |
150 |
props.getProperty(IDriverMgmtConstants.PROP_DEFN_JARLIST); |
151 |
if (driverClass != null && jarList != null) { |
152 |
return true; |
153 |
} |
154 |
return false; |
155 |
} |
156 |
|
52 |
protected Object createConnection(ClassLoader cl) throws Throwable { |
157 |
protected Object createConnection(ClassLoader cl) throws Throwable { |
53 |
Properties props = getConnectionProfile().getBaseProperties(); |
158 |
Properties props = getConnectionProfile().getBaseProperties(); |
54 |
Properties connectionProps = new Properties(); |
159 |
Properties connectionProps = new Properties(); |
55 |
|
160 |
|
56 |
String driverClass = getDriverDefinition().getProperty( |
161 |
// boolean hasDriver = (getDriverDefinition() != null); |
|
|
162 |
String driverClass = null; |
163 |
if (mHasDriver) |
164 |
driverClass = getDriverDefinition().getProperty( |
57 |
IJDBCConnectionProfileConstants.DRIVER_CLASS_PROP_ID); |
165 |
IJDBCConnectionProfileConstants.DRIVER_CLASS_PROP_ID); |
|
|
166 |
else |
167 |
driverClass = |
168 |
props.getProperty(IJDBCConnectionProfileConstants.DRIVER_CLASS_PROP_ID); |
169 |
|
58 |
String connectURL = props |
170 |
String connectURL = props |
59 |
.getProperty(IJDBCConnectionProfileConstants.URL_PROP_ID); |
171 |
.getProperty(IJDBCConnectionProfileConstants.URL_PROP_ID); |
60 |
String uid = props |
172 |
String uid = props |
Lines 84-90
Link Here
|
84 |
addPairs = addPairs + pairs[i]; |
196 |
addPairs = addPairs + pairs[i]; |
85 |
} |
197 |
} |
86 |
} |
198 |
} |
87 |
|
199 |
|
88 |
Driver jdbcDriver = (Driver) cl.loadClass(driverClass).newInstance(); |
200 |
Driver jdbcDriver = (Driver) cl.loadClass(driverClass).newInstance(); |
89 |
return jdbcDriver.connect(connectURL, connectionProps); |
201 |
return jdbcDriver.connect(connectURL, connectionProps); |
90 |
} |
202 |
} |