View | Details | Raw Unified | Return to bug 253606 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/datatools/connectivity/IConnectionProfile.java (+5 lines)
Lines 61-66 Link Here
61
	 */
61
	 */
62
	static final String INSTANCE_ID_PROPERTY_ID = "instanceID"; //$NON-NLS-1$
62
	static final String INSTANCE_ID_PROPERTY_ID = "instanceID"; //$NON-NLS-1$
63
	
63
	
64
	/**
65
	 * Transient marker for profile instance.
66
	 */
67
	static final String TRANSIENT_PROPERTY_ID = "isTransient"; //$NON-NLS-1$
68
64
	// Connection states
69
	// Connection states
65
	
70
	
66
	/**
71
	/**
(-)src/org/eclipse/datatools/connectivity/ProfileManager.java (-6 / +11 lines)
Lines 134-139 Link Here
134
	public IConnectionProfile getProfileByFullPath(String path ) {
134
	public IConnectionProfile getProfileByFullPath(String path ) {
135
		return InternalProfileManager.getInstance().getProfileByFullPath(path);
135
		return InternalProfileManager.getInstance().getProfileByFullPath(path);
136
	}
136
	}
137
138
	public IConnectionProfile createTransientProfile(String providerID, Properties baseProperties) throws ConnectionProfileException {
139
		return InternalProfileManager.getInstance().createTransientProfile(null, null, providerID, baseProperties);
140
	}
141
	
137
	/**
142
	/**
138
	 * Create connection profile
143
	 * Create connection profile
139
	 * 
144
	 * 
Lines 143-152 Link Here
143
	 * @param baseProperties
148
	 * @param baseProperties
144
	 * @throws ConnectionProfileException
149
	 * @throws ConnectionProfileException
145
	 */
150
	 */
146
	public void createProfile(String name, String description,
151
	public IConnectionProfile createProfile(String name, String description,
147
			String providerID, Properties baseProperties)
152
			String providerID, Properties baseProperties)
148
			throws ConnectionProfileException {
153
			throws ConnectionProfileException {
149
		InternalProfileManager.getInstance().createProfile(name, description,
154
		return InternalProfileManager.getInstance().createProfile(name, description,
150
				providerID, baseProperties);
155
				providerID, baseProperties);
151
	}
156
	}
152
157
Lines 160-169 Link Here
160
	 * @param parentProfile
165
	 * @param parentProfile
161
	 * @throws ConnectionProfileException
166
	 * @throws ConnectionProfileException
162
	 */
167
	 */
163
	public void createProfile(String name, String description,
168
	public IConnectionProfile createProfile(String name, String description,
164
			String providerID, Properties baseProperties, String parentProfile)
169
			String providerID, Properties baseProperties, String parentProfile)
165
			throws ConnectionProfileException {
170
			throws ConnectionProfileException {
166
		InternalProfileManager.getInstance().createProfile(name, description,
171
		return InternalProfileManager.getInstance().createProfile(name, description,
167
				providerID, baseProperties, parentProfile);
172
				providerID, baseProperties, parentProfile);
168
	}
173
	}
169
174
Lines 178-187 Link Here
178
	 * @param autoConnect
183
	 * @param autoConnect
179
	 * @throws ConnectionProfileException
184
	 * @throws ConnectionProfileException
180
	 */
185
	 */
181
	public void createProfile(String name, String description,
186
	public IConnectionProfile createProfile(String name, String description,
182
			String providerID, Properties baseProperties, String parentProfile,
187
			String providerID, Properties baseProperties, String parentProfile,
183
			boolean autoConnect) throws ConnectionProfileException {
188
			boolean autoConnect) throws ConnectionProfileException {
184
		InternalProfileManager.getInstance().createProfile(name, description,
189
		return InternalProfileManager.getInstance().createProfile(name, description,
185
				providerID, baseProperties, parentProfile, autoConnect);
190
				providerID, baseProperties, parentProfile, autoConnect);
186
	}
191
	}
187
192
(-)src/org/eclipse/datatools/connectivity/DriverConnectionBase.java (-3 / +3 lines)
Lines 31-39 Link Here
31
 */
31
 */
32
public abstract class DriverConnectionBase extends VersionProviderConnection {
32
public abstract class DriverConnectionBase extends VersionProviderConnection {
33
33
34
	private DriverInstance mDriver;
34
	protected DriverInstance mDriver;
35
	private Object mConnection;
35
	protected Object mConnection;
36
	private Throwable mConnectException;
36
	protected Throwable mConnectException;
37
37
38
	public DriverConnectionBase(IConnectionProfile profile, Class factoryClass) {
38
	public DriverConnectionBase(IConnectionProfile profile, Class factoryClass) {
39
		super(profile, factoryClass);
39
		super(profile, factoryClass);
(-)src/org/eclipse/datatools/connectivity/internal/InternalProfileManager.java (-5 / +65 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004-2008 Sybase, Inc. and others.
2
 * Copyright (c) 2004-2009 Sybase, Inc. and others.
3
 * 
3
 * 
4
 * All rights reserved. This program and the accompanying materials are made
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0 which
5
 * available under the terms of the Eclipse Public License v1.0 which
Lines 10-15 Link Here
10
 *     IBM Corporation -  fix for defect #223855
10
 *     IBM Corporation -  fix for defect #223855
11
 *     IBM Corporation -  fix for defect #241713
11
 *     IBM Corporation -  fix for defect #241713
12
 *     Actuate Corporation - fix for bug #247587
12
 *     Actuate Corporation - fix for bug #247587
13
 *     brianf - added Transient profile functionality for bug 253606
13
 ******************************************************************************/
14
 ******************************************************************************/
14
package org.eclipse.datatools.connectivity.internal;
15
package org.eclipse.datatools.connectivity.internal;
15
16
Lines 76-81 Link Here
76
77
77
	private IConnectionProfile[] mProfiles = null;
78
	private IConnectionProfile[] mProfiles = null;
78
	
79
	
80
	private ArrayList mTransientProfiles = null;
81
79
	private Set mRepositories = new HashSet();
82
	private Set mRepositories = new HashSet();
80
83
81
	private boolean mIsDirty = false;
84
	private boolean mIsDirty = false;
Lines 455-460 Link Here
455
	}
458
	}
456
459
457
	/**
460
	/**
461
	 * Create transient connection profile
462
	 * 
463
	 * @param name
464
	 * @param description
465
	 * @param providerID
466
	 * @param baseProperties
467
	 * @throws ConnectionProfileException
468
	 */
469
	public IConnectionProfile createTransientProfile(String name, String description,
470
			String providerID, Properties baseProperties) throws ConnectionProfileException {
471
		String transientName = name;
472
		if (transientName == null) {
473
			transientName = "Transient" + providerID;
474
		}
475
		transientName = findUniqueTransientProfileName(transientName, providerID);
476
		ConnectionProfile profile = new ConnectionProfile(transientName, description,
477
				providerID, "", false, UUID.createUUID()
478
						.toString());
479
		baseProperties.setProperty(IConnectionProfile.TRANSIENT_PROPERTY_ID, "");
480
		profile.setBaseProperties(baseProperties);
481
		profile.setCreated();
482
		if (mTransientProfiles == null) 
483
			mTransientProfiles = new ArrayList();
484
		mTransientProfiles.add(profile);
485
		return profile;
486
	}
487
	
488
	/**
489
	 * Private method to avoid name collisions
490
	 * @param name
491
	 * @param providerID
492
	 * @return
493
	 */
494
	private String findUniqueTransientProfileName(String name, String providerID) {
495
		if (mTransientProfiles != null) {
496
			Iterator iter = mTransientProfiles.iterator();
497
			int count = 0;
498
			while (iter.hasNext()) {
499
				IConnectionProfile profile = (IConnectionProfile) iter.next();
500
				if (profile.getProviderId().equalsIgnoreCase(providerID)) {
501
					count++;
502
				}
503
			}
504
			return name + count;
505
		}
506
		return name;
507
	}
508
509
	/**
458
	 * Create connection profile
510
	 * Create connection profile
459
	 * 
511
	 * 
460
	 * @param name
512
	 * @param name
Lines 856-865 Link Here
856
908
857
		// Changed to fix bug 247599
909
		// Changed to fix bug 247599
858
		//cps[index] = profile;
910
		//cps[index] = profile;
859
		if(cps[index] != profile) {
911
		removeProfile(cps[index]);
860
			removeProfile(cps[index]);
912
		addProfile(profile);
861
			addProfile(profile);			
862
		}
863
913
864
		mIsDirty = true;
914
		mIsDirty = true;
865
915
Lines 1097-1102 Link Here
1097
	}
1147
	}
1098
1148
1099
	/* package */void dispose() {
1149
	/* package */void dispose() {
1150
		if (mTransientProfiles != null) {
1151
			Iterator transientIter = mTransientProfiles.iterator();
1152
			while (transientIter.hasNext()) {
1153
//				((ConnectionProfile)transientIter.next()).dispose();
1154
				ConnectionProfile transientProfile = 
1155
					(ConnectionProfile) transientIter.next();
1156
				System.out.println("Disposing transient profile: " + transientProfile.getInstanceID());
1157
				transientProfile.dispose();
1158
			}
1159
		}
1100
		if (mProfiles == null) {
1160
		if (mProfiles == null) {
1101
			return;
1161
			return;
1102
		}
1162
		}
(-)src/org/eclipse/datatools/connectivity/drivers/jdbc/JDBCConnection.java (-3 / +115 lines)
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
	}

Return to bug 253606