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 (-1 / +71 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 23-28 Link Here
23
import java.util.ArrayList;
24
import java.util.ArrayList;
24
import java.util.Arrays;
25
import java.util.Arrays;
25
import java.util.Collection;
26
import java.util.Collection;
27
import java.util.Collections;
26
import java.util.HashMap;
28
import java.util.HashMap;
27
import java.util.HashSet;
29
import java.util.HashSet;
28
import java.util.Iterator;
30
import java.util.Iterator;
Lines 76-81 Link Here
76
78
77
	private IConnectionProfile[] mProfiles = null;
79
	private IConnectionProfile[] mProfiles = null;
78
	
80
	
81
	private List mTransientProfiles = null;
82
79
	private Set mRepositories = new HashSet();
83
	private Set mRepositories = new HashSet();
80
84
81
	private boolean mIsDirty = false;
85
	private boolean mIsDirty = false;
Lines 455-460 Link Here
455
	}
459
	}
456
460
457
	/**
461
	/**
462
	 * Create transient connection profile
463
	 * 
464
	 * @param name
465
	 * @param description
466
	 * @param providerID
467
	 * @param baseProperties
468
	 * @throws ConnectionProfileException
469
	 */
470
	public IConnectionProfile createTransientProfile(String name, String description,
471
			String providerID, Properties baseProperties) throws ConnectionProfileException {
472
		String transientName = name;
473
		if (transientName == null) {
474
			transientName = "Transient." + providerID; //$NON-NLS-1$
475
		}
476
		transientName = findUniqueTransientProfileName(transientName, providerID);
477
		ConnectionProfile profile = new ConnectionProfile(transientName, description,
478
				providerID, "", false, UUID.createUUID() //$NON-NLS-1$
479
						.toString());
480
		baseProperties.setProperty(IConnectionProfile.TRANSIENT_PROPERTY_ID, ""); //$NON-NLS-1$
481
		profile.setBaseProperties(baseProperties);
482
		profile.setCreated();
483
		if (mTransientProfiles == null) {
484
			synchronized (this) {
485
				if (mTransientProfiles == null) {
486
					mTransientProfiles = Collections.synchronizedList( new ArrayList() );
487
				}
488
			}
489
		}
490
		mTransientProfiles.add(profile);
491
		return profile;
492
	}
493
	
494
	/**
495
	 * Private method to avoid name collisions
496
	 * @param name
497
	 * @param providerID
498
	 * @return
499
	 */
500
	private String findUniqueTransientProfileName(String name, String providerID) {
501
		if (mTransientProfiles != null) {
502
			synchronized(mTransientProfiles) {
503
				Iterator iter = mTransientProfiles.iterator();
504
				int count = 0;
505
				while (iter.hasNext()) {
506
					IConnectionProfile profile = (IConnectionProfile) iter.next();
507
					if (profile.getProviderId().equalsIgnoreCase(providerID)) {
508
						count++;
509
					}
510
				}
511
				return name + count;
512
			}
513
		}
514
		return name;
515
	}
516
517
	/**
458
	 * Create connection profile
518
	 * Create connection profile
459
	 * 
519
	 * 
460
	 * @param name
520
	 * @param name
Lines 1097-1102 Link Here
1097
	}
1157
	}
1098
1158
1099
	/* package */void dispose() {
1159
	/* package */void dispose() {
1160
		if (mTransientProfiles != null) {
1161
			synchronized (mTransientProfiles) {
1162
				if (mTransientProfiles != null) {
1163
					Iterator transientIter = mTransientProfiles.iterator();
1164
					while (transientIter.hasNext()) {
1165
						((ConnectionProfile)transientIter.next()).dispose();
1166
					}
1167
				}
1168
			}
1169
		}
1100
		if (mProfiles == null) {
1170
		if (mProfiles == null) {
1101
			return;
1171
			return;
1102
		}
1172
		}
(-)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