Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 203158 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/DerbyUIPlugin.java (+12 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.datatools.connectivity.derby.internal.ui;
11
package org.eclipse.datatools.connectivity.derby.internal.ui;
12
12
13
import org.eclipse.jface.resource.ImageDescriptor;
13
import org.eclipse.ui.plugin.AbstractUIPlugin;
14
import org.eclipse.ui.plugin.AbstractUIPlugin;
14
15
15
/**
16
/**
Lines 36-39 Link Here
36
	{
37
	{
37
		return plugin;
38
		return plugin;
38
	}	
39
	}	
40
	
41
	/**
42
	 * Returns an image descriptor for the image file at the given
43
	 * plug-in relative path.
44
	 *
45
	 * @param path the path
46
	 * @return the image descriptor
47
	 */
48
	public static ImageDescriptor getImageDescriptor(String path) {
49
		return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.datatools.connectivity.derby.ui", path); //$NON-NLS-1$
50
	}
39
}
51
}
(-)META-INF/MANIFEST.MF (-1 / +5 lines)
Lines 15-21 Link Here
15
 org.eclipse.emf.ecore;bundle-version="[2.2.0,3.0.0)",
15
 org.eclipse.emf.ecore;bundle-version="[2.2.0,3.0.0)",
16
 org.eclipse.datatools.modelbase.sql;bundle-version="[0.9.0,1.5.0)",
16
 org.eclipse.datatools.modelbase.sql;bundle-version="[0.9.0,1.5.0)",
17
 org.eclipse.datatools.modelbase.derby;bundle-version="[0.9.0,1.5.0)",
17
 org.eclipse.datatools.modelbase.derby;bundle-version="[0.9.0,1.5.0)",
18
 org.eclipse.datatools.connectivity.derby;bundle-version="[0.9.1,1.5.0)"
18
 org.eclipse.datatools.connectivity.derby;bundle-version="[0.9.1,1.5.0)",
19
 org.eclipse.datatools.connectivity.db.generic;bundle-version="[0.9.1,1.5.0)",
20
 org.eclipse.datatools.connectivity.db.generic.ui;bundle-version="[0.9.1,1.5.0)",
21
 org.eclipse.datatools.connectivity;bundle-version="[0.9.1,1.5.0)",
22
 org.eclipse.datatools.connectivity.ui;bundle-version="[0.9.1,1.5.0)"
19
Eclipse-LazyStart: true
23
Eclipse-LazyStart: true
20
Bundle-Vendor: Eclipse.org
24
Bundle-Vendor: Eclipse.org
21
Bundle-RequiredExecutionEnvironment: J2SE-1.4
25
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)build.properties (-1 / +2 lines)
Lines 4-10 Link Here
4
               .,\
4
               .,\
5
               about.html,\
5
               about.html,\
6
               plugin.xml,\
6
               plugin.xml,\
7
               icons/
7
               icons/,\
8
               plugin.properties
8
src.dir			 = src/
9
src.dir			 = src/
9
plugin.version =	1.0.0.200706071
10
plugin.version =	1.0.0.200706071
10
javadoc.dir =		doc/api/
11
javadoc.dir =		doc/api/
(-)plugin.xml (+26 lines)
Lines 47-50 Link Here
47
		</contributor>
47
		</contributor>
48
	</extension>
48
	</extension>
49
	
49
	
50
	<extension
51
         point="org.eclipse.datatools.connectivity.connectionProfile">
52
      <newWizard
53
            class="org.eclipse.datatools.connectivity.derby.internal.ui.connection.NewDerbyEmbeddedConnectionProfileWizard"
54
            icon="icons/new_db_element.gif"
55
            id="org.eclipse.datatools.connectivity.db.derby.embedded.NewConnectionProfileWizard"
56
            name="%DERBY_EMBEDDED_CONNECTION_PROFILE_WIZARD_NAME"
57
            profile="org.eclipse.datatools.connectivity.db.derby.embedded.connectionProfile"/>
58
   </extension>
59
   <extension
60
         point="org.eclipse.ui.propertyPages">
61
      <page
62
            class="org.eclipse.datatools.connectivity.derby.internal.ui.connection.DerbyEmbeddedDBPropertyPage"
63
            id="org.eclipse.datatools.connectivity.db.derby.profileProperties"
64
            name="%DERBY_EMBEDDED_DB_PROPERTY_PAGE_NAME">
65
         <filter
66
               name="org.eclipse.datatools.profile.property.id"
67
               value="org.eclipse.datatools.connectivity.db.derby.embedded.connectionProfile"/>
68
         <enabledWhen>
69
            <instanceof
70
                  value="org.eclipse.datatools.connectivity.IConnectionProfile">
71
            </instanceof>
72
         </enabledWhen>
73
      </page>
74
   </extension>
75
	
50
</plugin>
76
</plugin>
(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/connection/DerbyEmbeddedDBProfileDetailsWizardPage.java (+659 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004-2006 Sybase, Inc.
3
 * 
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
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: brianf - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.datatools.connectivity.derby.internal.ui.connection;
12
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.StringTokenizer;
17
18
import javax.swing.event.ChangeEvent;
19
import javax.swing.event.ChangeListener;
20
21
import org.eclipse.core.runtime.Path;
22
import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants;
23
import org.eclipse.datatools.connectivity.derby.internal.ui.DerbyUIPlugin;
24
import org.eclipse.datatools.connectivity.drivers.DriverInstance;
25
import org.eclipse.datatools.connectivity.internal.derby.connection.IDerbyConnectionProfileConstants;
26
import org.eclipse.datatools.connectivity.internal.ui.DelimitedStringList;
27
import org.eclipse.datatools.connectivity.internal.ui.DriverListCombo;
28
import org.eclipse.datatools.connectivity.ui.wizards.ConnectionProfileDetailsPage;
29
import org.eclipse.datatools.help.ContextProviderDelegate;
30
import org.eclipse.datatools.help.HelpUtil;
31
import org.eclipse.help.IContext;
32
import org.eclipse.help.IContextProvider;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.events.ModifyEvent;
35
import org.eclipse.swt.events.ModifyListener;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.events.SelectionListener;
38
import org.eclipse.swt.layout.GridData;
39
import org.eclipse.swt.layout.GridLayout;
40
import org.eclipse.swt.widgets.Button;
41
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Control;
43
import org.eclipse.swt.widgets.DirectoryDialog;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Text;
46
47
/**
48
 * This class gathers the properties for the derby embedded DB connection profile.
49
 * 
50
 * @author brianf
51
 */
52
public class DerbyEmbeddedDBProfileDetailsWizardPage 
53
	extends ConnectionProfileDetailsPage
54
	implements IContextProvider {
55
56
	// ui pieces
57
	private Text mDatabaseNameText;
58
59
	private Text mURLText;
60
61
	private Text mDBUIDText;
62
63
	private Text mDBPWDText;
64
65
	private Button mSaveDBPWDCheckbox;
66
67
	private DelimitedStringList mDBConnProps;
68
69
	final DriverListCombo combo = new DriverListCombo();
70
	
71
	private Button mCreateDBCheckbox;
72
	
73
	private Button mUpgradeDBCheckbox;
74
75
	private Text mDBFilePathText;
76
77
	private Button mBrowseFilePathButton;
78
79
	// stashed driver instance
80
	private DriverInstance mDriverInstance;
81
	
82
	private String mDriverCategory;
83
84
	/**
85
	 * Constructor
86
	 * 
87
	 * @param pageName
88
	 */
89
	public DerbyEmbeddedDBProfileDetailsWizardPage(String pageName) {
90
		super(pageName);
91
		setTitle(Messages.getString(
92
				"DerbyEmbeddedDBProfileDetailsWizardPage.title")); //$NON-NLS-1$
93
		setDescription(Messages.getString(
94
				"DerbyEmbeddedDBProfileDetailsWizardPage.msg")); //$NON-NLS-1$
95
		setDriverCategory(IDerbyConnectionProfileConstants.DERBY_CATEGORY_ID);
96
		this.combo.setFilter("templateIDStartsWith = " + //$NON-NLS-1$
97
				IDerbyConnectionProfileConstants.DERBY_ENABLEMENT_DRIVER_PREFIX + "," +  //$NON-NLS-1$
98
				"templateIDEndsWith = " + //$NON-NLS-1$
99
				IDerbyConnectionProfileConstants.DERBY_ENABLEMENT_DRIVER_SUFFIX);
100
	}
101
102
	/*
103
	 * (non-Javadoc)
104
	 * 
105
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
106
	 */
107
	public void createCustomControl(Composite parent) {
108
		Composite content = new Composite(parent, SWT.NULL);
109
		GridLayout layout = new GridLayout(2, false);
110
		content.setLayout(layout);
111
112
		// set up the drivers combo
113
		this.combo.setLabelText(Messages.getString(
114
				"DerbyEmbeddedDBProfileDetailsWizardPage.driverCombo.label")); //$NON-NLS-1$
115
		this.combo.setCategory(getDriverCategory());
116
		this.combo.setNullDriverIsValid(false);
117
		this.combo.createContents(content);
118
		if (this.combo.getErrorMessage() != null) {
119
			setErrorMessage(this.combo.getErrorMessage());
120
		}
121
122
		// set up the fields
123
		this.mDatabaseNameText = (Text) createLabelTextPair(
124
				content,
125
				Messages.getString(
126
						"DerbyEmbeddedDBProfileDetailsWizardPage.databaseName.label"), //$NON-NLS-1$
127
				this.mURLText, SWT.BORDER, GridData.FILL_HORIZONTAL);
128
129
		Label label = new Label(content, SWT.NULL);
130
		label.setLayoutData(new GridData());
131
		label.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.0")); //$NON-NLS-1$
132
133
		Composite textAndBrowseComposite = new Composite(content, SWT.NULL);
134
		GridLayout subCompositeLayout = new GridLayout(2, false);
135
		subCompositeLayout.marginLeft = -5;
136
		subCompositeLayout.marginRight = -5;
137
		subCompositeLayout.marginTop = -5;
138
		subCompositeLayout.marginBottom = -5;
139
		textAndBrowseComposite.setLayout(subCompositeLayout);
140
		textAndBrowseComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
141
		this.mDBFilePathText = new Text(textAndBrowseComposite, SWT.BORDER);
142
		this.mDBFilePathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
143
		this.mBrowseFilePathButton = new Button(textAndBrowseComposite, SWT.PUSH);
144
		this.mBrowseFilePathButton.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.1")); //$NON-NLS-1$
145
		this.mBrowseFilePathButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
146
147
		this.mDBUIDText = (Text) createLabelTextPair(content, Messages.getString(
148
						"DerbyEmbeddedDBProfileDetailsWizardPage.userName.label"), //$NON-NLS-1$
149
				this.mDBUIDText, SWT.BORDER, GridData.FILL_HORIZONTAL);
150
151
		this.mDBPWDText = (Text) createLabelTextPair(content, Messages.getString(
152
						"DerbyEmbeddedDBProfileDetailsWizardPage.password.label"), //$NON-NLS-1$
153
				this.mDBPWDText, SWT.BORDER | SWT.PASSWORD, GridData.FILL_HORIZONTAL);
154
155
		this.mURLText = (Text) createLabelTextPair(content, Messages.getString(
156
			"DerbyEmbeddedDBProfileDetailsWizardPage.url.label"), //$NON-NLS-1$
157
			this.mURLText, SWT.BORDER, GridData.FILL_HORIZONTAL);
158
159
		this.mCreateDBCheckbox = new Button(content, SWT.CHECK);
160
		this.mCreateDBCheckbox.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.2")); //$NON-NLS-1$
161
		this.mCreateDBCheckbox.setLayoutData(new GridData(GridData.BEGINNING,
162
				GridData.CENTER, true, false, 2, 1));
163
164
		this.mUpgradeDBCheckbox = new Button(content, SWT.CHECK);
165
		this.mUpgradeDBCheckbox.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.3")); //$NON-NLS-1$
166
		this.mUpgradeDBCheckbox.setLayoutData(new GridData(GridData.BEGINNING,
167
				GridData.CENTER, true, false, 2, 1));
168
169
		this.mSaveDBPWDCheckbox = new Button(content, SWT.CHECK);
170
		this.mSaveDBPWDCheckbox.setText(Messages.getString(
171
						"DerbyEmbeddedDBProfileDetailsWizardPage.persistpassword.label")); //$NON-NLS-1$
172
		this.mSaveDBPWDCheckbox.setLayoutData(new GridData(GridData.BEGINNING,
173
				GridData.CENTER, true, false, 2, 1));
174
175
		// spacer
176
		Composite spacer = new Composite(content, SWT.NULL);
177
		GridData gdata = new GridData(GridData.FILL_HORIZONTAL);
178
		gdata.horizontalSpan = 2;
179
		gdata.heightHint = 20;
180
		spacer.setLayoutData(gdata);
181
182
		// followed by the optional properties
183
		label = new Label(content, SWT.NULL);
184
		gdata = new GridData(GridData.FILL_HORIZONTAL);
185
		gdata.horizontalSpan = 2;
186
		label.setLayoutData(gdata);
187
		label.setText(Messages.getString(
188
				"DerbyEmbeddedDBProfileDetailsWizardPage.optionalProps.label")); //$NON-NLS-1$
189
190
		this.mDBConnProps = new DelimitedStringList(content, SWT.NONE);
191
		gdata = new GridData(GridData.FILL_HORIZONTAL);
192
		gdata.horizontalSpan = 2;
193
		this.mDBConnProps.setLayoutData(gdata);
194
195
//		// now set up the initial instance
196
//		if (this.mDriverInstance == null)
197
//			this.mDriverInstance = this.combo.getSelectedDriverInstance();
198
199
		this.mDBConnProps.addChangeListener(new ChangeListener() {
200
201
			public void stateChanged(ChangeEvent arg0) {
202
				setErrorMessage(null);
203
				if (DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBConnProps.getWarning() != null) {
204
					setErrorMessage(DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBConnProps
205
							.getWarning());
206
				}
207
			}
208
209
		});
210
211
		// add a change listener to the combo box so
212
		// we know when a new driver has been selected
213
		this.combo.addChangeListener(new ChangeListener() {
214
215
			public void stateChanged(ChangeEvent arg0) {
216
				DerbyEmbeddedDBProfileDetailsWizardPage.this.mDriverInstance = DerbyEmbeddedDBProfileDetailsWizardPage.this.combo
217
						.getSelectedDriverInstance();
218
				setErrorMessage(null);
219
				if (DerbyEmbeddedDBProfileDetailsWizardPage.this.combo.getErrorMessage() != null) {
220
					setErrorMessage(DerbyEmbeddedDBProfileDetailsWizardPage.this.combo
221
							.getErrorMessage());
222
				}
223
				DerbyEmbeddedDBProfileDetailsWizardPage.this.mDatabaseNameText
224
						.setText(getDriverDatabaseName());
225
226
				DerbyEmbeddedDBProfileDetailsWizardPage.this.mURLText
227
						.setText(getDriverURL());
228
				DerbyEmbeddedDBProfileDetailsWizardPage.this.updatePropsFromURL();
229
230
				String username = DerbyEmbeddedDBProfileDetailsWizardPage.this
231
						.getPropertyFromDriverInstance(IDBDriverDefinitionConstants.USERNAME_PROP_ID);
232
				if (username == null || username.trim().length() == 0)
233
					username = new String();
234
				DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBUIDText.setText(username);
235
236
				String password = DerbyEmbeddedDBProfileDetailsWizardPage.this
237
						.getPropertyFromDriverInstance(IDBDriverDefinitionConstants.PASSWORD_PROP_ID);
238
				if (password == null || password.trim().length() == 0)
239
					password = new String();
240
				DerbyEmbeddedDBProfileDetailsWizardPage.this.mDBPWDText.setText(password);
241
242
				setPageComplete(isValid());
243
			}
244
245
		});
246
		
247
		this.mDBFilePathText.addModifyListener(new ModifyListener() {
248
			public void modifyText(ModifyEvent e) {
249
				DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps();
250
			}
251
		});
252
		
253
		this.mCreateDBCheckbox.addSelectionListener(new SelectionListener() {
254
255
			public void widgetDefaultSelected(SelectionEvent e) {
256
				DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps();
257
			}
258
259
			public void widgetSelected(SelectionEvent e) {
260
				DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps();
261
			}
262
		});
263
		
264
		this.mUpgradeDBCheckbox.addSelectionListener(new SelectionListener() {
265
266
			public void widgetDefaultSelected(SelectionEvent e) {
267
				DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps();
268
			}
269
270
			public void widgetSelected(SelectionEvent e) {
271
				DerbyEmbeddedDBProfileDetailsWizardPage.this.updateURLFromProps();
272
			}
273
		});
274
275
		this.mBrowseFilePathButton.addSelectionListener( new SelectionListener() {
276
277
			public void widgetDefaultSelected(SelectionEvent e) {
278
				DerbyEmbeddedDBProfileDetailsWizardPage.this.browseForDBFolder();
279
			}
280
281
			public void widgetSelected(SelectionEvent e) {
282
				DerbyEmbeddedDBProfileDetailsWizardPage.this.browseForDBFolder();
283
			}
284
		});
285
286
		this.combo.selectFirstItem();
287
		// now set up the initial instance
288
		if (this.mDriverInstance == null)
289
			this.mDriverInstance = this.combo.getSelectedDriverInstance();
290
		if (this.mDriverInstance != null) {
291
			this.mURLText.setText(getDriverURL());
292
		}
293
		this.mURLText.setEnabled(false);
294
295
	}
296
	
297
	/**
298
	 * Browse for the database folder
299
	 */
300
	private void browseForDBFolder() {
301
		DirectoryDialog dialog = new DirectoryDialog(getShell());
302
		dialog.setText(Messages
303
				.getString("DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.title.filebrowse")); //$NON-NLS-1$
304
		dialog.setMessage(Messages
305
				.getString("DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.msg.filebrowse")); //$NON-NLS-1$
306
307
		String dirName = mDBFilePathText.getText();
308
309
		File path = new File(dirName);
310
		if (path.exists()) {
311
			dialog.setFilterPath(new Path(dirName).toOSString());
312
		}
313
314
		String selectedDirectory = dialog.open();
315
		if (selectedDirectory != null) {
316
			this.mDBFilePathText.setText(selectedDirectory);
317
		}
318
	}
319
320
	/**
321
	 * Update the UI components from the URL
322
	 */
323
	private void updatePropsFromURL() {
324
		if (this.mDBFilePathText != null && this.mURLText != null && this.mCreateDBCheckbox != null && this.mUpgradeDBCheckbox != null) {
325
			String url = this.mURLText.getText();
326
			String[] chunks = parseString(url, ";"); //$NON-NLS-1$
327
			if (chunks.length > 0) {
328
				String[] chunks2 = parseString(chunks[0], ":"); //$NON-NLS-1$
329
				if (chunks2.length > 2) {
330
					String filepath = chunks2[2];
331
					if (chunks2.length > 3) {
332
						filepath = filepath + ":" + chunks2[3]; //$NON-NLS-1$
333
					}
334
					this.mDBFilePathText.setText(filepath);
335
				}
336
			}
337
			if (chunks.length > 1) {
338
				for (int i = 1; i < chunks.length; i++) {
339
					if (chunks[i].startsWith("create=")) //$NON-NLS-1$
340
						this.mCreateDBCheckbox.setSelection(true);
341
					else if (chunks[i].startsWith("upgrade=")) //$NON-NLS-1$
342
						this.mUpgradeDBCheckbox.setSelection(true);
343
				}
344
			}
345
		}
346
	}
347
	
348
	/**
349
	 * Update the URL from the UI components
350
	 */
351
	private void updateURLFromProps() {
352
		if (this.mDBFilePathText != null && this.mURLText != null && this.mCreateDBCheckbox != null && this.mUpgradeDBCheckbox != null) {
353
			String url = this.mURLText.getText();
354
			String filePath = this.mDBFilePathText.getText();
355
			boolean createDB = this.mCreateDBCheckbox.getSelection();
356
			boolean upgradeDB = this.mUpgradeDBCheckbox.getSelection();
357
			//jdbc:derby:C:\DerbyDatabases\MyDB;create=true
358
			String[] chunks = parseString(url, ";"); //$NON-NLS-1$
359
			if (chunks.length > 0) {
360
				String[] chunks2 = parseString(chunks[0], ":"); //$NON-NLS-1$
361
				if (chunks2.length > 2) {
362
					url = chunks2[0] + ":" + chunks2[1] + ":" + filePath; //$NON-NLS-1$ //$NON-NLS-2$
363
					if (createDB) {
364
						url = url + ";" + "create=true"; //$NON-NLS-1$ //$NON-NLS-2$
365
					}
366
					if (upgradeDB) {
367
						url = url + ";" + "upgrade=true"; //$NON-NLS-1$ //$NON-NLS-2$
368
					}
369
					this.mURLText.setText(url);
370
				}
371
			}
372
		}
373
	}
374
375
	/**
376
	 * Parse a string into a string array based on a token
377
	 * @param str_list
378
	 * @param token
379
	 * @return
380
	 */
381
	private  String[] parseString(String str_list, String token) {
382
		StringTokenizer tk = new StringTokenizer(str_list, token);
383
		String[] pieces = new String[tk.countTokens()];
384
		int index = 0;
385
		while (tk.hasMoreTokens())
386
			pieces[index++] = tk.nextToken();
387
		return pieces;
388
	}
389
390
	/**
391
	 * @param propertyID
392
	 * @return
393
	 */
394
	private String getPropertyFromDriverInstance(String propertyID) {
395
		String returnStr = new String();
396
		if (this.mDriverInstance != null
397
				&& this.mDriverInstance.getProperty(propertyID) != null) {
398
			returnStr = this.mDriverInstance.getProperty(propertyID);
399
		}
400
		return returnStr;
401
	}
402
403
	/**
404
	 * Get the sample URL from the driver instance.
405
	 * 
406
	 * @return
407
	 */
408
	public String getDriverURL() {
409
		if (this.mDriverInstance != null
410
				&& this.mDriverInstance
411
						.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID) != null)
412
			return this.mDriverInstance
413
					.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID);
414
		return new String();
415
	}
416
417
	/**
418
	 * Get the sample database name from the driver instance.
419
	 * 
420
	 * @return
421
	 */
422
	public String getDriverDatabaseName() {
423
		if (this.mDriverInstance != null
424
				&& this.mDriverInstance
425
						.getProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID) != null)
426
			return this.mDriverInstance
427
					.getProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID);
428
		return new String();
429
	}
430
431
	/**
432
	 * Get the vendor
433
	 * 
434
	 * @return
435
	 */
436
	public String getVendor() {
437
		String vendor = ""; //$NON-NLS-1$
438
		if (this.mDriverInstance != null) {
439
			vendor = this.mDriverInstance
440
					.getProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID);
441
		}
442
		return vendor;
443
	}
444
445
	/**
446
	 * Get the version
447
	 * 
448
	 * @return
449
	 */
450
	public String getVersion() {
451
		String version = ""; //$NON-NLS-1$
452
		if (this.mDriverInstance != null) {
453
			version = this.mDriverInstance
454
					.getProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID);
455
		}
456
		return version;
457
	}
458
459
	/**
460
	 * Get the driver class
461
	 * 
462
	 * @return
463
	 */
464
	public String getDriverClass() {
465
		String driverClass = ""; //$NON-NLS-1$
466
		if (this.mDriverInstance != null) {
467
			driverClass = this.mDriverInstance
468
					.getProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID);
469
		}
470
		return driverClass;
471
	}
472
	
473
	/**
474
	 * Get the user name
475
	 * 
476
	 * @return
477
	 */
478
	public String getDBUID() {
479
		return this.mDBUIDText.getText();
480
	}
481
482
	/**
483
	 * Get the password
484
	 * 
485
	 * @return
486
	 */
487
	public String getDBPWD() {
488
		return this.mDBPWDText.getText();
489
	}
490
491
	/**
492
	 * Get the password
493
	 * 
494
	 * @return
495
	 */
496
	public boolean getSaveDBPWD() {
497
		return this.mSaveDBPWDCheckbox.getSelection();
498
	}
499
500
	/**
501
	 * Get the optional connection properties
502
	 * 
503
	 * @return
504
	 */
505
	public String getDBConnProps() {
506
		return this.mDBConnProps.getSelection();
507
	}
508
509
	/**
510
	 * Get the database name
511
	 * 
512
	 * @return
513
	 */
514
	public String getDatabaseName() {
515
		return this.mDatabaseNameText.getText();
516
	}
517
518
	/**
519
	 * Get the URL for the CP
520
	 * 
521
	 * @return
522
	 */
523
	public String getURL() {
524
		return this.mURLText.getText();
525
	}
526
527
	/**
528
	 * Get the driver ID
529
	 * 
530
	 * @return
531
	 */
532
	public String getDriverID() {
533
		return this.mDriverInstance.getId();
534
	}
535
536
	/*
537
	 * Create a label and a text box side by side.
538
	 */
539
	private Control createLabelTextPair(Composite parent, String labelText,
540
			Control ctl, int style, int gData) {
541
		Label label = new Label(parent, SWT.NULL);
542
		label.setLayoutData(new GridData());
543
		label.setText(labelText);
544
545
		ctl = new Text(parent, style);
546
		ctl.setLayoutData(new GridData(gData));
547
548
		return ctl;
549
	}
550
551
	/*
552
	 * (non-Javadoc)
553
	 * 
554
	 * @see com.sybase.suade.common.ui.wizards.ISummaryDataSource#getSummaryData()
555
	 */
556
	public List getSummaryData() {
557
		List data = new ArrayList();
558
559
		data
560
				.add(new String[] {
561
						Messages.getString(
562
										"DerbyEmbeddedDBProfileDetailsWizardPage.summary.driverName.label"), //$NON-NLS-1$
563
						mDriverInstance.getName() });
564
565
		data
566
				.add(new String[] {
567
						Messages.getString(
568
										"DerbyEmbeddedDBProfileDetailsWizardPage.summary.connProps.label"), //$NON-NLS-1$
569
						getDBConnProps() });
570
571
		data
572
				.add(new String[] {
573
						Messages.getString(
574
										"DerbyEmbeddedDBProfileDetailsWizardPage.summary.userName.label"), //$NON-NLS-1$
575
						getDBUID() });
576
577
		StringBuffer pwdMask = new StringBuffer();
578
		if (getDBPWD() != null && getDBPWD().length() > 0) {
579
			for (int i = 0, count = getDBPWD().length(); i < count; ++i) {
580
				pwdMask = pwdMask.append('*');
581
			}
582
		}
583
584
		data
585
				.add(new String[] {
586
						Messages.getString(
587
										"DerbyEmbeddedDBProfileDetailsWizardPage.summary.password.label"), //$NON-NLS-1$
588
						pwdMask.toString() });
589
590
		data.add(new String[] {
591
				Messages.getString(
592
						"DerbyEmbeddedDBProfileDetailsWizardPage.summary.url.label"), //$NON-NLS-1$
593
				getURL() });
594
595
		return data;
596
	}
597
598
	private boolean isValid() {
599
		if (getErrorMessage() != null) {
600
			setPageComplete(false);
601
			return false;
602
		}
603
604
		return true;
605
	}
606
607
	/*
608
	 * (non-Javadoc)
609
	 * 
610
	 * @see org.eclipse.jface.dialogs.DialogPage#setErrorMessage(java.lang.String)
611
	 */
612
	public void setErrorMessage(String newMessage) {
613
		super.setErrorMessage(newMessage);
614
		isValid();
615
	}
616
617
	
618
	/**
619
	 * @return
620
	 */
621
	public String getDriverCategory() {
622
		return mDriverCategory;
623
	}
624
625
	
626
	/**
627
	 * Sets the driver category that should be used for displaying available
628
	 * driver defnitions.
629
	 * 
630
	 * @param driverCategory
631
	 */
632
	public void setDriverCategory(String driverCategory) {
633
		mDriverCategory = driverCategory;
634
		if (combo != null) {
635
			combo.setCategory(mDriverCategory);
636
		}
637
	}
638
639
	private ContextProviderDelegate contextProviderDelegate =
640
		new ContextProviderDelegate(DerbyUIPlugin.getDefault().getBundle().getSymbolicName());
641
642
	public IContext getContext(Object target) {
643
		return contextProviderDelegate.getContext(target);
644
	}
645
646
	public int getContextChangeMask() {
647
		return contextProviderDelegate.getContextChangeMask();
648
	}
649
650
	public String getSearchExpression(Object target) {
651
		return contextProviderDelegate.getSearchExpression(target);
652
	}
653
654
	public void createControl(Composite parent) {
655
		super.createControl(parent);
656
		getShell().setData( HelpUtil.CONTEXT_PROVIDER_KEY, this);
657
		HelpUtil.setHelp( getControl(), HelpUtil.getContextId(IHelpContextsDerbyProfile.DERBY_PROFILE_WIZARD_PAGE, DerbyUIPlugin.getDefault().getBundle().getSymbolicName()));
658
	}
659
}
(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/connection/NewDerbyEmbeddedConnectionProfileWizard.java (+98 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004-2005 Sybase, Inc.
3
 * 
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
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: brianf - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.datatools.connectivity.derby.internal.ui.connection;
12
13
import java.util.Properties;
14
15
import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
16
import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants;
17
import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants;
18
import org.eclipse.datatools.connectivity.db.generic.ui.NewConnectionProfileWizard;
19
import org.eclipse.datatools.connectivity.derby.internal.ui.DerbyUIPlugin;
20
import org.eclipse.datatools.help.ContextProviderDelegate;
21
import org.eclipse.datatools.help.HelpUtil;
22
import org.eclipse.help.IContext;
23
import org.eclipse.jface.wizard.Wizard;
24
import org.eclipse.swt.widgets.Composite;
25
26
/**
27
 * @see Wizard
28
 */
29
public class NewDerbyEmbeddedConnectionProfileWizard extends
30
		NewConnectionProfileWizard {
31
32
	protected DerbyEmbeddedDBProfileDetailsWizardPage mPropPage;
33
34
	public NewDerbyEmbeddedConnectionProfileWizard() {
35
		setWindowTitle(Messages.getString("NewDerbyEmbeddedConnectionProfileWizard.DerbyEmbeddedDatabaseWizardTitle")); //$NON-NLS-1$
36
	}
37
38
	/**
39
	 * @see org.eclipse.datatools.connectivity.ui.wizards.NewDerbyEmbeddedConnectionProfileWizard#addCustomPages()
40
	 */
41
	public void addCustomPages() {
42
		mPropPage = new DerbyEmbeddedDBProfileDetailsWizardPage("detailsPage"); //$NON-NLS-1$
43
		addPage(mPropPage);
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.datatools.connectivity.db.generic.ui.NewConnectionProfileWizard#getProfileProperties()
48
	 */
49
	public Properties getProfileProperties() {
50
		Properties props = new Properties();
51
		props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID,
52
				this.mPropPage.getDriverID());
53
		props.setProperty(
54
				IDBConnectionProfileConstants.CONNECTION_PROPERTIES_PROP_ID,
55
				this.mPropPage.getDBConnProps());
56
		props.setProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, this.mPropPage
57
				.getDriverClass());
58
		props.setProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, this.mPropPage
59
				.getVendor());		
60
		props.setProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, this.mPropPage
61
				.getVersion());			
62
		props.setProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, this.mPropPage
63
				.getDatabaseName());
64
		props.setProperty(IDBDriverDefinitionConstants.PASSWORD_PROP_ID, this.mPropPage
65
				.getDBPWD());
66
		props.setProperty(
67
				IDBConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, String
68
						.valueOf(this.mPropPage.getSaveDBPWD()));
69
		props.setProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID, this.mPropPage
70
				.getDBUID());
71
		props.setProperty(IDBDriverDefinitionConstants.URL_PROP_ID,
72
				this.mPropPage.getURL());
73
		return props;
74
	}
75
76
	private ContextProviderDelegate contextProviderDelegate =
77
		new ContextProviderDelegate(DerbyUIPlugin.getDefault().getBundle().getSymbolicName());
78
79
	public IContext getContext(Object target) {
80
		return contextProviderDelegate.getContext(target);
81
	}
82
83
	public int getContextChangeMask() {
84
		return contextProviderDelegate.getContextChangeMask();
85
	}
86
87
	public String getSearchExpression(Object target) {
88
		return contextProviderDelegate.getSearchExpression(target);
89
	}
90
91
	public void createPageControls(Composite pageContainer) {
92
		super.createPageControls(pageContainer);
93
		getShell().setData(HelpUtil.CONTEXT_PROVIDER_KEY, this);
94
		HelpUtil.setHelp(getShell(), HelpUtil.getContextId(
95
				IHelpContextsDerbyProfile.DERBY_PROFILE_WIZARD,
96
				DerbyUIPlugin.getDefault().getBundle().getSymbolicName()));
97
	}
98
}
(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/connection/DerbyEmbeddedDBPropertyPage.java (+564 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Sybase, Inc.
3
 * 
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
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: rcernich - initial API and implementation
10
 * 				 brianf - customized for Derby url requirements
11
 ******************************************************************************/
12
package org.eclipse.datatools.connectivity.derby.internal.ui.connection;
13
14
import java.io.File;
15
import java.util.Properties;
16
import java.util.StringTokenizer;
17
18
import javax.swing.event.ChangeEvent;
19
import javax.swing.event.ChangeListener;
20
21
import org.eclipse.core.runtime.Path;
22
import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
23
import org.eclipse.datatools.connectivity.IConnectionProfile;
24
import org.eclipse.datatools.connectivity.db.generic.IDBConnectionProfileConstants;
25
import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants;
26
import org.eclipse.datatools.connectivity.derby.internal.ui.DerbyUIPlugin;
27
import org.eclipse.datatools.connectivity.drivers.DriverInstance;
28
import org.eclipse.datatools.connectivity.internal.derby.connection.IDerbyConnectionProfileConstants;
29
import org.eclipse.datatools.connectivity.internal.ui.ConnectivityUIPlugin;
30
import org.eclipse.datatools.connectivity.internal.ui.DelimitedStringList;
31
import org.eclipse.datatools.connectivity.internal.ui.DriverListCombo;
32
import org.eclipse.datatools.connectivity.internal.ui.IHelpConstants;
33
import org.eclipse.datatools.connectivity.ui.wizards.ProfileDetailsPropertyPage;
34
import org.eclipse.datatools.help.ContextProviderDelegate;
35
import org.eclipse.datatools.help.HelpUtil;
36
import org.eclipse.help.IContext;
37
import org.eclipse.help.IContextProvider;
38
import org.eclipse.jface.preference.PreferencePage;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.ModifyEvent;
41
import org.eclipse.swt.events.ModifyListener;
42
import org.eclipse.swt.events.SelectionEvent;
43
import org.eclipse.swt.events.SelectionListener;
44
import org.eclipse.swt.layout.GridData;
45
import org.eclipse.swt.layout.GridLayout;
46
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Control;
49
import org.eclipse.swt.widgets.DirectoryDialog;
50
import org.eclipse.swt.widgets.Label;
51
import org.eclipse.swt.widgets.Text;
52
53
/**
54
 * Property page for Derby Embedded profiles
55
 *
56
 */
57
public class DerbyEmbeddedDBPropertyPage 
58
	extends ProfileDetailsPropertyPage
59
	implements IContextProvider {
60
61
	private static final String EMPTY_STRING = new String();
62
63
	// UI components
64
	private Text mDatabaseNameText;
65
	private Text mDBUIDText;
66
	private Text mDBPWDText;
67
	private Text mURLText;
68
	private Button mSaveDBPWDCheckbox;
69
	private Button mCreateDBCheckbox;
70
	private Button mUpgradeDBCheckbox;
71
	private Text mDBFilePathText;
72
	private Button mBrowseFilePathButton;
73
	final DriverListCombo combo = new DriverListCombo();
74
	private DelimitedStringList mDBConnProps;
75
76
	// other components
77
	private DriverInstance mDriverInstance;
78
	private String mDriverCategory;
79
80
	/**
81
	 * Constructor
82
	 */
83
	public DerbyEmbeddedDBPropertyPage() {
84
		super();
85
		noDefaultAndApplyButton();
86
		setDriverCategory(IDerbyConnectionProfileConstants.DERBY_CATEGORY_ID);
87
		this.combo.setFilter("templateIDStartsWith = " + //$NON-NLS-1$
88
				IDerbyConnectionProfileConstants.DERBY_ENABLEMENT_DRIVER_PREFIX + "," +  //$NON-NLS-1$
89
				"templateIDEndsWith = " + //$NON-NLS-1$
90
				IDerbyConnectionProfileConstants.DERBY_ENABLEMENT_DRIVER_SUFFIX);
91
	}
92
93
	/**
94
	 * @see PreferencePage#createContents(Composite)
95
	 */
96
	protected void createCustomContents(Composite parent) {
97
		Composite content = new Composite(parent, SWT.NULL);
98
		GridLayout layout = new GridLayout(2, false);
99
		content.setLayout(layout);
100
101
		this.combo.setLabelText(Messages.getString(
102
				"DerbyEmbeddedDBProfileDetailsWizardPage.driverCombo.label")); //$NON-NLS-1$
103
		this.combo.setCategory(getDriverCategory());
104
		this.combo.setNullDriverIsValid(false);
105
		this.combo.createContents(content);
106
107
		this.mDatabaseNameText = (Text) createLabelTextPair(
108
				content,
109
				Messages.getString(
110
						"DerbyEmbeddedDBProfileDetailsWizardPage.databaseName.label"), //$NON-NLS-1$
111
				this.mURLText, SWT.BORDER, GridData.FILL_HORIZONTAL);		
112
113
		Label label = new Label(content, SWT.NULL);
114
		label.setLayoutData(new GridData());
115
		label.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.0")); //$NON-NLS-1$
116
117
		Composite textAndBrowseComposite = new Composite(content, SWT.NULL);
118
		GridLayout subCompositeLayout = new GridLayout(2, false);
119
		subCompositeLayout.marginLeft = -5;
120
		subCompositeLayout.marginRight = -5;
121
		subCompositeLayout.marginTop = -5;
122
		subCompositeLayout.marginBottom = -5;
123
		textAndBrowseComposite.setLayout(subCompositeLayout);
124
		textAndBrowseComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
125
		this.mDBFilePathText = new Text(textAndBrowseComposite, SWT.BORDER);
126
		this.mDBFilePathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
127
		this.mBrowseFilePathButton = new Button(textAndBrowseComposite, SWT.PUSH);
128
		this.mBrowseFilePathButton.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.1")); //$NON-NLS-1$
129
		this.mBrowseFilePathButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
130
131
		this.mURLText = (Text) createLabelTextPair(content, Messages.getString(
132
						"DerbyEmbeddedDBProfileDetailsWizardPage.url.label"), //$NON-NLS-1$
133
				this.mURLText, SWT.BORDER, GridData.FILL_HORIZONTAL);
134
		this.mDBUIDText = (Text) createLabelTextPair(content, Messages.getString(
135
						"DerbyEmbeddedDBProfileDetailsWizardPage.userName.label"), //$NON-NLS-1$ 
136
				this.mDBUIDText, SWT.BORDER, GridData.FILL_HORIZONTAL); //$NON-NLS-1$
137
138
		this.mDBPWDText = (Text) createLabelTextPair(content, Messages.getString(
139
						"DerbyEmbeddedDBProfileDetailsWizardPage.password.label"), //$NON-NLS-1$, 
140
				this.mDBPWDText, SWT.BORDER | SWT.PASSWORD, GridData.FILL_HORIZONTAL); //$NON-NLS-1$
141
142
		this.mCreateDBCheckbox = new Button(content, SWT.CHECK);
143
		this.mCreateDBCheckbox.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.2")); //$NON-NLS-1$
144
		this.mCreateDBCheckbox.setLayoutData(new GridData(GridData.BEGINNING,
145
				GridData.CENTER, true, false, 2, 1));
146
147
		this.mUpgradeDBCheckbox = new Button(content, SWT.CHECK);
148
		this.mUpgradeDBCheckbox.setText(Messages.getString("DerbyEmbeddedDBProfileDetailsWizardPage.3")); //$NON-NLS-1$
149
		this.mUpgradeDBCheckbox.setLayoutData(new GridData(GridData.BEGINNING,
150
				GridData.CENTER, true, false, 2, 1));
151
152
		this.mSaveDBPWDCheckbox = new Button(content, SWT.CHECK);
153
		this.mSaveDBPWDCheckbox.setText(Messages
154
				.getString(
155
						"DerbyEmbeddedDBProfileDetailsWizardPage.persistpassword.label")); //$NON-NLS-1$
156
		this.mSaveDBPWDCheckbox.setLayoutData(new GridData(GridData.BEGINNING,
157
				GridData.CENTER, true, false, 2, 1));
158
159
		Composite spacer = new Composite(content, SWT.NULL);
160
		GridData gdata = new GridData(GridData.FILL_HORIZONTAL);
161
		gdata.horizontalSpan = 2;
162
		gdata.heightHint = 20;
163
		spacer.setLayoutData(gdata);
164
165
		label = new Label(content, SWT.NULL);
166
		gdata = new GridData(GridData.FILL_HORIZONTAL);
167
		gdata.horizontalSpan = 2;
168
		label.setLayoutData(gdata);
169
		label.setText(Messages.getString(
170
				"DerbyEmbeddedDBProfileDetailsWizardPage.optionalProps.label")); //$NON-NLS-1$
171
172
		this.mDBConnProps = new DelimitedStringList(content, SWT.NONE);
173
		gdata = new GridData(GridData.FILL_HORIZONTAL);
174
		gdata.horizontalSpan = 2;
175
		this.mDBConnProps.setLayoutData(gdata);
176
177
		this.mDBConnProps.addChangeListener(new ChangeListener() {
178
179
			public void stateChanged(ChangeEvent arg0) {
180
				setErrorMessage(null);
181
				if (DerbyEmbeddedDBPropertyPage.this.mDBConnProps.getWarning() != null) {
182
					setErrorMessage(DerbyEmbeddedDBPropertyPage.this.mDBConnProps
183
							.getWarning());
184
				}
185
			}
186
187
		});
188
189
		this.combo.addChangeListener(new ChangeListener() {
190
191
			public void stateChanged(ChangeEvent arg0) {
192
				DerbyEmbeddedDBPropertyPage.this.mDriverInstance = DerbyEmbeddedDBPropertyPage.this.combo
193
						.getSelectedDriverInstance();
194
				setErrorMessage(null);
195
				if (DerbyEmbeddedDBPropertyPage.this.combo.getErrorMessage() != null) {
196
					setErrorMessage(DerbyEmbeddedDBPropertyPage.this.combo
197
							.getErrorMessage());
198
				}
199
				else
200
					DerbyEmbeddedDBPropertyPage.this.mURLText
201
							.setText(getDriverURL());
202
				String username = DerbyEmbeddedDBPropertyPage.this
203
						.getPropertyFromDriverInstance(IDBDriverDefinitionConstants.USERNAME_PROP_ID);
204
				if (username == null || username.trim().length() == 0)
205
					username = new String();
206
				String oldUsername = DerbyEmbeddedDBPropertyPage.this.mDBUIDText
207
						.getText();
208
				if (oldUsername == null || oldUsername.trim().length() == 0)
209
					oldUsername = new String();
210
				if (oldUsername.length() == 0)
211
					DerbyEmbeddedDBPropertyPage.this.mDBUIDText
212
							.setText(username);
213
214
				String password = DerbyEmbeddedDBPropertyPage.this
215
						.getPropertyFromDriverInstance(IDBDriverDefinitionConstants.PASSWORD_PROP_ID);
216
				if (password == null || password.trim().length() == 0)
217
					password = new String();
218
				String oldPassword = DerbyEmbeddedDBPropertyPage.this.mDBPWDText
219
						.getText();
220
				if (oldPassword == null || oldPassword.trim().length() == 0)
221
					oldPassword = new String();
222
				if (oldPassword.length() == 0)
223
					DerbyEmbeddedDBPropertyPage.this.mDBPWDText
224
							.setText(password);
225
			}
226
227
		});
228
229
		initControls();
230
231
		this.mDBFilePathText.addModifyListener(new ModifyListener() {
232
			public void modifyText(ModifyEvent e) {
233
				DerbyEmbeddedDBPropertyPage.this.updateURLFromProps();
234
			}
235
		});
236
		
237
		this.mCreateDBCheckbox.addSelectionListener(new SelectionListener() {
238
239
			public void widgetDefaultSelected(SelectionEvent e) {
240
				DerbyEmbeddedDBPropertyPage.this.updateURLFromProps();
241
			}
242
243
			public void widgetSelected(SelectionEvent e) {
244
				DerbyEmbeddedDBPropertyPage.this.updateURLFromProps();
245
			}
246
		});
247
		
248
		this.mUpgradeDBCheckbox.addSelectionListener(new SelectionListener() {
249
250
			public void widgetDefaultSelected(SelectionEvent e) {
251
				DerbyEmbeddedDBPropertyPage.this.updateURLFromProps();
252
			}
253
254
			public void widgetSelected(SelectionEvent e) {
255
				DerbyEmbeddedDBPropertyPage.this.updateURLFromProps();
256
			}
257
		});
258
		
259
		this.mBrowseFilePathButton.addSelectionListener( new SelectionListener() {
260
261
			public void widgetDefaultSelected(SelectionEvent e) {
262
				DerbyEmbeddedDBPropertyPage.this.browseForDBFolder();
263
			}
264
265
			public void widgetSelected(SelectionEvent e) {
266
				DerbyEmbeddedDBPropertyPage.this.browseForDBFolder();
267
			}
268
		});
269
270
		// return content;
271
	}
272
273
	/*
274
	 * (non-Javadoc)
275
	 * 
276
	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
277
	 */
278
	protected Properties collectProperties() {
279
		Properties props = new Properties();
280
281
		String driverID = EMPTY_STRING;
282
283
		if (this.combo.getSelectedDriverInstance() != null) {
284
			DriverInstance instance = this.combo.getSelectedDriverInstance();
285
			driverID = instance.getId();
286
		}
287
288
		props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID,
289
				driverID);
290
		props.setProperty(
291
				IDBConnectionProfileConstants.CONNECTION_PROPERTIES_PROP_ID,
292
				this.mDBConnProps.getSelection());	
293
		props.setProperty(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, getPropertyFromDriverInstance(IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID));		
294
		props.setProperty(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, getPropertyFromDriverInstance(IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID));		
295
		props.setProperty(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, getPropertyFromDriverInstance(IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID));	
296
		props.setProperty(IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, this.mDatabaseNameText
297
				.getText());
298
		props.setProperty(IDBDriverDefinitionConstants.PASSWORD_PROP_ID, this.mDBPWDText
299
				.getText());
300
		props.setProperty(IDBDriverDefinitionConstants.USERNAME_PROP_ID, this.mDBUIDText
301
				.getText());
302
		props.setProperty(IDBDriverDefinitionConstants.URL_PROP_ID,
303
				this.mURLText.getText());
304
		props.setProperty(
305
				IDBConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, String
306
						.valueOf(this.mSaveDBPWDCheckbox.getSelection()));
307
308
		return props;
309
	}
310
311
	/**
312
	 * 
313
	 */
314
	private void initControls() {
315
		IConnectionProfile profile = getConnectionProfile();
316
		String driverID = profile.getBaseProperties().getProperty(
317
				ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID);
318
		if (driverID != null) {
319
			this.combo.setSelectionToID(driverID);
320
		}
321
322
		String connectionProps = profile.getBaseProperties().getProperty(
323
				IDBConnectionProfileConstants.CONNECTION_PROPERTIES_PROP_ID);
324
		if (connectionProps != null) {
325
			this.mDBConnProps.setSelection(connectionProps);
326
		}
327
328
		String databaseName = profile.getBaseProperties().getProperty(
329
				IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID);
330
		if (databaseName != null) {
331
			this.mDatabaseNameText.setText(databaseName);
332
		}
333
		
334
		String databasePwd = profile.getBaseProperties().getProperty(
335
				IDBDriverDefinitionConstants.PASSWORD_PROP_ID);
336
		if (databasePwd != null) {
337
			this.mDBPWDText.setText(databasePwd);
338
		}
339
340
		String databaseUid = profile.getBaseProperties().getProperty(
341
				IDBDriverDefinitionConstants.USERNAME_PROP_ID);
342
		if (databaseUid != null) {
343
			this.mDBUIDText.setText(databaseUid);
344
		}
345
346
		String urlText = profile.getBaseProperties().getProperty(
347
				IDBDriverDefinitionConstants.URL_PROP_ID);
348
		if (urlText != null) {
349
			this.mURLText.setText(urlText);
350
			this.mURLText.setEnabled(false);
351
		}
352
353
		this.mSaveDBPWDCheckbox.setSelection(Boolean.valueOf(
354
				profile.getBaseProperties().getProperty(
355
						IDBConnectionProfileConstants.SAVE_PASSWORD_PROP_ID,
356
						Boolean.FALSE.toString())).booleanValue());
357
358
		this.updatePropsFromURL();
359
360
		setErrorMessage(null);
361
		if (this.combo.getErrorMessage() != null) {
362
			setErrorMessage(this.combo.getErrorMessage());
363
		}
364
	}
365
	
366
	/**
367
	 * Browse for a DB folder
368
	 */
369
	private void browseForDBFolder() {
370
		DirectoryDialog dialog = new DirectoryDialog(getShell());
371
		dialog.setText(Messages
372
				.getString("DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.title.filebrowse")); //$NON-NLS-1$
373
		dialog.setMessage(Messages
374
				.getString("DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.msg.filebrowse")); //$NON-NLS-1$
375
376
		String dirName = mDBFilePathText.getText();
377
378
		File path = new File(dirName);
379
		if (path.exists()) {
380
			dialog.setFilterPath(new Path(dirName).toOSString());
381
		}
382
383
		String selectedDirectory = dialog.open();
384
		if (selectedDirectory != null) {
385
			this.mDBFilePathText.setText(selectedDirectory);
386
		}
387
	}
388
389
	/**
390
	 * Based on the URL, update the UI components accordingly
391
	 */
392
	private void updatePropsFromURL() {
393
		if (this.mDBFilePathText != null && this.mURLText != null && this.mCreateDBCheckbox != null && this.mUpgradeDBCheckbox != null) {
394
			String url = this.mURLText.getText();
395
			String[] chunks = parseString(url, ";"); //$NON-NLS-1$
396
			if (chunks.length > 0) {
397
				String[] chunks2 = parseString(chunks[0], ":"); //$NON-NLS-1$
398
				if (chunks2.length > 2) {
399
					String filepath = chunks2[2];
400
					if (chunks2.length > 3) {
401
						filepath = filepath + ":" + chunks2[3]; //$NON-NLS-1$
402
					}
403
					this.mDBFilePathText.setText(filepath);
404
				}
405
			}
406
			if (chunks.length > 1) {
407
				for (int i = 1; i < chunks.length; i++) {
408
					if (chunks[i].startsWith("create=")) //$NON-NLS-1$
409
						this.mCreateDBCheckbox.setSelection(true);
410
					else if (chunks[i].startsWith("upgrade=")) //$NON-NLS-1$
411
						this.mUpgradeDBCheckbox.setSelection(true);
412
				}
413
			}
414
		}
415
	}
416
	
417
	/**
418
	 * Based on the state of the UI components, reset the URL
419
	 */
420
	private void updateURLFromProps() {
421
		if (this.mDBFilePathText != null && this.mURLText != null && this.mCreateDBCheckbox != null && this.mUpgradeDBCheckbox != null) {
422
			String url = this.mURLText.getText();
423
			String filePath = this.mDBFilePathText.getText();
424
			boolean createDB = this.mCreateDBCheckbox.getSelection();
425
			boolean upgradeDB = this.mUpgradeDBCheckbox.getSelection();
426
			//jdbc:derby:C:\DerbyDatabases\MyDB;create=true
427
			String[] chunks = parseString(url, ";"); //$NON-NLS-1$
428
			if (chunks.length > 0) {
429
				String[] chunks2 = parseString(chunks[0], ":"); //$NON-NLS-1$
430
				if (chunks2.length > 2) {
431
					url = chunks2[0] + ":" + chunks2[1] + ":" + filePath; //$NON-NLS-1$ //$NON-NLS-2$
432
					if (createDB) {
433
						url = url + ";" + "create=true"; //$NON-NLS-1$ //$NON-NLS-2$
434
					}
435
					if (upgradeDB) {
436
						url = url + ";" + "upgrade=true"; //$NON-NLS-1$ //$NON-NLS-2$
437
					}
438
					this.mURLText.setText(url);
439
				}
440
			}
441
		}
442
	}
443
444
	/**
445
	 * Parse a string into an array based on a token
446
	 * @param str_list
447
	 * @param token
448
	 * @return
449
	 */
450
	private  String[] parseString(String str_list, String token) {
451
		StringTokenizer tk = new StringTokenizer(str_list, token);
452
		String[] pieces = new String[tk.countTokens()];
453
		int index = 0;
454
		while (tk.hasMoreTokens())
455
			pieces[index++] = tk.nextToken();
456
		return pieces;
457
	}
458
459
	/**
460
	 * @param propertyID
461
	 * @return
462
	 */
463
	private String getPropertyFromDriverInstance(String propertyID) {
464
		String returnStr = new String();
465
		if (this.mDriverInstance != null
466
				&& this.mDriverInstance.getProperty(propertyID) != null) {
467
			returnStr = this.mDriverInstance.getProperty(propertyID);
468
		}
469
		return returnStr;
470
	}
471
472
	/**
473
	 * @param parent
474
	 * @param labelText
475
	 * @param ctl
476
	 * @param style
477
	 * @param gData
478
	 * @return
479
	 */
480
	private Control createLabelTextPair(Composite parent, String labelText,
481
			Control ctl, int style, int gData) {
482
		Label label = new Label(parent, SWT.NULL);
483
		label.setLayoutData(new GridData());
484
		label.setText(labelText);
485
486
		ctl = new Text(parent, style);
487
		ctl.setLayoutData(new GridData(gData));
488
489
		return ctl;
490
	}
491
492
	/**
493
	 * @return
494
	 */
495
	public String getDriverURL() {
496
		return this.mDriverInstance
497
				.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID);
498
	}
499
500
	/*
501
	 * (non-Javadoc)
502
	 * 
503
	 * @see org.eclipse.jface.preference.IPreferencePage#isValid()
504
	 */
505
	public boolean isValid() {
506
		if (getErrorMessage() != null) {
507
			return false;
508
		}
509
		return super.isValid();
510
	}
511
512
	/*
513
	 * (non-Javadoc)
514
	 * 
515
	 * @see org.eclipse.jface.dialogs.DialogPage#setErrorMessage(java.lang.String)
516
	 */
517
	public void setErrorMessage(String newMessage) {
518
		super.setErrorMessage(newMessage);
519
		isValid();
520
	}
521
522
	/**
523
	 * @return
524
	 */
525
	public String getDriverCategory() {
526
		return mDriverCategory;
527
	}
528
529
	
530
	/**
531
	 * Sets the driver category that should be used for displaying available
532
	 * driver defnitions.
533
	 * 
534
	 * @param driverCategory
535
	 */
536
	public void setDriverCategory(String driverCategory) {
537
		mDriverCategory = driverCategory;
538
		if (combo != null) {
539
			combo.setCategory(mDriverCategory);
540
		}
541
	}
542
543
	private ContextProviderDelegate contextProviderDelegate =
544
		new ContextProviderDelegate(DerbyUIPlugin.getDefault().getBundle().getSymbolicName());
545
546
	public IContext getContext(Object target) {
547
		return contextProviderDelegate.getContext(target);
548
	}
549
550
	public int getContextChangeMask() {
551
		return contextProviderDelegate.getContextChangeMask();
552
	}
553
554
	public String getSearchExpression(Object target) {
555
		return contextProviderDelegate.getSearchExpression(target);
556
	}
557
558
	protected Control createContents(Composite parent) {
559
		Control contents = super.createContents(parent);
560
		getShell().setData( HelpUtil.CONTEXT_PROVIDER_KEY, this);
561
		HelpUtil.setHelp( getControl(), HelpUtil.getContextId(IHelpConstants.CONTEXT_ID_CP_PROPERTY_PAGE, ConnectivityUIPlugin.getDefault().getBundle().getSymbolicName()));
562
		return contents;
563
	}
564
}
(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/connection/messages.properties (+23 lines)
Added Link Here
1
NewDerbyEmbeddedConnectionProfileWizard.DerbyEmbeddedDatabaseWizardTitle=Derby Embedded Database
2
3
DerbyEmbeddedDBProfileDetailsWizardPage.title = Specify a Driver and Connection Details
4
DerbyEmbeddedDBProfileDetailsWizardPage.msg = Select a driver from the drop-down and provide login details for the connection.
5
DerbyEmbeddedDBProfileDetailsWizardPage.0=Database location:
6
DerbyEmbeddedDBProfileDetailsWizardPage.1=Browse...
7
DerbyEmbeddedDBProfileDetailsWizardPage.2=Create database (if required)
8
DerbyEmbeddedDBProfileDetailsWizardPage.3=Upgrade database to current version
9
DerbyEmbeddedDBProfileDetailsWizardPage.driverCombo.label = Select a driver from the drop-down:
10
DerbyEmbeddedDBProfileDetailsWizardPage.databaseName.label = Database:
11
DerbyEmbeddedDBProfileDetailsWizardPage.url.label = URL:
12
DerbyEmbeddedDBProfileDetailsWizardPage.PingButton=Test connection
13
DerbyEmbeddedDBProfileDetailsWizardPage.userName.label = User name:
14
DerbyEmbeddedDBProfileDetailsWizardPage.password.label = Password:
15
DerbyEmbeddedDBProfileDetailsWizardPage.persistpassword.label = Save Password
16
DerbyEmbeddedDBProfileDetailsWizardPage.optionalProps.label = Optional properties:
17
DerbyEmbeddedDBProfileDetailsWizardPage.summary.driverName.label = Driver name
18
DerbyEmbeddedDBProfileDetailsWizardPage.summary.connProps.label = Connection properties
19
DerbyEmbeddedDBProfileDetailsWizardPage.summary.userName.label = User name
20
DerbyEmbeddedDBProfileDetailsWizardPage.summary.password.label = Password
21
DerbyEmbeddedDBProfileDetailsWizardPage.summary.url.label = URL
22
DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.title.filebrowse = Browse for Database Folder
23
DerbyEmbeddedDBProfileDetailsWizardPage.FileDialog.msg.filebrowse = Select the folder that corresponds to your Derby database.
(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/connection/Messages.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.datatools.connectivity.derby.internal.ui.connection;
12
13
import java.util.MissingResourceException;
14
import java.util.ResourceBundle;
15
16
public class Messages {
17
	private static final String BUNDLE_NAME = "org.eclipse.datatools.connectivity.derby.internal.ui.connection.messages"; //$NON-NLS-1$
18
19
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
20
			.getBundle(BUNDLE_NAME);
21
22
	private Messages() {
23
	}
24
25
	public static String getString(String key) {
26
		// TODO Auto-generated method stub
27
		try {
28
			return RESOURCE_BUNDLE.getString(key);
29
		} catch (MissingResourceException e) {
30
			return '!' + key + '!';
31
		}
32
	}
33
}
(-)plugin.properties (+16 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2006, 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
# 
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
pluginName=Eclipse Data Tools Platform Apache Derby UI Plug-in
12
providerName=Eclipse.org
13
14
DERBY_EMBEDDED_CONNECTION_PROFILE_WIZARD_NAME=Derby Embedded Database
15
DERBY_EMBEDDED_DB_PROPERTY_PAGE_NAME=JDBC Connection Properties
16
(-)src/org/eclipse/datatools/connectivity/derby/internal/ui/connection/IHelpContextsDerbyProfile.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Sybase, Inc.
3
 * 
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
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: brianf - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.datatools.connectivity.derby.internal.ui.connection;
12
13
public interface IHelpContextsDerbyProfile {
14
15
	/**
16
	 * TPS_helpKey_constants_for_plug-in: org.eclipse.datatools.connectivity.db.derby
17
	 */
18
19
	/*
20
	 * DERBY_PROFILE_WIZARD_PAGE = the wizard page that collects Derby Embedded profile
21
	 * details such as the path to the database, user id, password, etc.
22
	 */
23
	public static final String DERBY_PROFILE_WIZARD_PAGE = "DERBY_PROFILE_WIZARD_PAGE";
24
25
	/*
26
	 * DERBY_PROFILE_PROPERTY_PAGE = the property page that collects and allows editing of
27
	 * Derby Embedded profile details such as the path to the database, user id, password, etc.
28
	 */
29
	public static final String DERBY_PROFILE_PROPERTY_PAGE = "DERBY_PROFILE_PROPERTY_PAGE";
30
	
31
	/*
32
	 * DERBY_PROFILE_WIZARD = the actual New Derby Embedded Profile wizard
33
	 */
34
	public static final String DERBY_PROFILE_WIZARD = "DERBY_PROFILE_WIZARD";
35
}
(-)icons/new_db_element.gif (+4 lines)
Added Link Here
1
GIF89a÷ZcZcZc{„{„{„œœœ­­­µŒ9µ”9½½½½ÞÞÆ½ÆÖÖÖÞÞ½çΌÿÿÿÞÞÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ!ù,œt° €Áƒh?@‚‡$8A!C&ˆ8‘¢‹2näh „&
2
8 #LJJP¹rÀ–rPҀ?`D€€¢Ü
3
 ÀP	ˆàg͛-u²´i5èТG¥.]ÙôiTS«åš5çÖ±„"5Š”À€´$
4
Uª¼èeIpàÈ;
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 18-24 Link Here
18
 org.eclipse.datatools.modelbase.sql;bundle-version="[0.9.0,1.5.0)",
18
 org.eclipse.datatools.modelbase.sql;bundle-version="[0.9.0,1.5.0)",
19
 org.eclipse.datatools.connectivity.sqm.core;bundle-version="[0.9.1,1.5.0)",
19
 org.eclipse.datatools.connectivity.sqm.core;bundle-version="[0.9.1,1.5.0)",
20
 com.ibm.icu;bundle-version="[3.4.0,4.0.0)",
20
 com.ibm.icu;bundle-version="[3.4.0,4.0.0)",
21
 org.eclipse.datatools.modelbase.derby;bundle-version="[0.9.0,1.5.0)"
21
 org.eclipse.datatools.modelbase.derby;bundle-version="[0.9.0,1.5.0)",
22
 org.eclipse.datatools.connectivity.db.generic;bundle-version="[0.9.1,1.5.0)",
23
 org.eclipse.datatools.connectivity;bundle-version="[0.9.1,1.5.0)"
22
Eclipse-LazyStart: true
24
Eclipse-LazyStart: true
23
Bundle-RequiredExecutionEnvironment: J2SE-1.4
25
Bundle-RequiredExecutionEnvironment: J2SE-1.4
24
26
(-)build.properties (-1 / +2 lines)
Lines 2-8 Link Here
2
               plugin.xml,\
2
               plugin.xml,\
3
               plugin.properties,\
3
               plugin.properties,\
4
               about.html,\
4
               about.html,\
5
               META-INF/
5
               META-INF/,\
6
               icons/
6
jars.compile.order = .
7
jars.compile.order = .
7
source.. = src/
8
source.. = src/
8
9
(-)plugin.xml (+446 lines)
Lines 65-68 Link Here
65
      </generator>
65
      </generator>
66
   </extension>
66
   </extension>
67
67
68
<extension
69
         point="org.eclipse.datatools.connectivity.connectionProfile">
70
      <connectionProfile
71
            category="org.eclipse.datatools.connectivity.db.category"
72
            icon="icons/jdbc_16.gif"
73
            pingFactory="org.eclipse.datatools.connectivity.internal.derby.connection.DerbyJDBCConnectionFactory"
74
            id="org.eclipse.datatools.connectivity.db.derby.embedded.connectionProfile"
75
            name="%DERBY_CONNECTION_PROFILE_NAME"/>
76
      <connectionFactory
77
            class="org.eclipse.datatools.connectivity.internal.derby.connection.DerbyJDBCConnectionFactory"
78
            id="java.sql.Connection"
79
            name="%DERBY_JDBC_CONNECTION_FACTORY_NAME"
80
            profile="org.eclipse.datatools.connectivity.db.derby.embedded.connectionProfile"/>
81
   </extension>
82
   
83
	<extension
84
         point="org.eclipse.datatools.connectivity.driverExtension">    
85
      <category
86
      		parentCategory="org.eclipse.datatools.connectivity.db.driverCategory"
87
            id="org.eclipse.datatools.connectivity.db.derby.driverCategory"
88
            name="%DERBY_CATEGORY_NAME"/>
89
       <category
90
      		parentCategory="org.eclipse.datatools.connectivity.db.derby.driverCategory"
91
            id="org.eclipse.datatools.connectivity.db.derby.10_0.driverCategory"
92
            name="%10_0_VERSION_CATEGORY_NAME"/> 
93
        <category
94
      		parentCategory="org.eclipse.datatools.connectivity.db.derby.driverCategory"
95
            id="org.eclipse.datatools.connectivity.db.derby.10_1.driverCategory"
96
            name="%10_1_VERSION_CATEGORY_NAME"/> 
97
        <category
98
      		parentCategory="org.eclipse.datatools.connectivity.db.derby.driverCategory"
99
            id="org.eclipse.datatools.connectivity.db.derby.10_2.driverCategory"
100
            name="%10_2_VERSION_CATEGORY_NAME"/> 
101
            
102
      <driverTemplate
103
            createDefault="false"
104
            emptyJarListIsOK="false"
105
            id="org.eclipse.datatools.connectivity.db.derby.genericDriverTemplate"
106
            jarList="derby.jar"
107
            name="%DERBY_EMBEDDED_DRIVER_TEMPLATE_NAME"
108
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_0.driverCategory">
109
         <properties>
110
            <property
111
                  generated="false"
112
                  id="org.eclipse.datatools.connectivity.db.driverClass"
113
                  name="%DRIVER_CLASS_PROPERTY_NAME"
114
                  value="org.apache.derby.jdbc.EmbeddedDriver"
115
                  required="true"
116
                  visible="false"/>
117
            <property
118
                  generated="false"
119
                  id="org.eclipse.datatools.connectivity.db.vendor"
120
                  name="%VENDOR_PROPERTY_NAME"
121
                  value="Derby"
122
                  required="true"
123
                  visible="false"/>
124
            <property
125
                  generated="false"
126
                  id="org.eclipse.datatools.connectivity.db.version"
127
                  name="%VERSION_PROPERTY_NAME"
128
                  value="10.0"
129
                  required="true"
130
                  visible="false"/>   
131
            <property
132
                  generated="false"
133
                  id="org.eclipse.datatools.connectivity.db.databaseName"
134
                  name="%DATABASE_NAME_PROPERTY_NAME"
135
                  value="SAMPLE"
136
                  required="true"
137
                  visible="true"/>                             
138
            <property
139
                  generated="false"
140
                  id="org.eclipse.datatools.connectivity.db.URL"
141
                  name="%CONNECTION_URL_PROPERTY_NAME"
142
                  value="jdbc:derby:C:\DerbyDatabases\MyDB;create=true"
143
                  required="true"
144
                  visible="true"/>
145
            <property
146
                  generated="false"
147
                  id="org.eclipse.datatools.connectivity.db.username"
148
                  name="%USER_ID_PROPERTY_NAME"
149
                  value=""
150
                  required="false"
151
                  visible="true"/>
152
            <property
153
                  generated="false"
154
                  id="org.eclipse.datatools.connectivity.db.password"
155
                  name="%PASSWORD_PROPERTY_NAME"
156
                  required="false"
157
                  visible="true"/>
158
         </properties>
159
      </driverTemplate>
160
      <driverTemplate
161
            createDefault="false"
162
            emptyJarListIsOK="false"
163
            id="org.eclipse.datatools.connectivity.db.derby101.genericDriverTemplate"
164
            jarList="derby.jar"
165
            name="%DERBY101_EMBEDDED_DRIVER_TEMPLATE_NAME"
166
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_1.driverCategory">
167
         <properties>
168
            <property
169
                  generated="false"
170
                  id="org.eclipse.datatools.connectivity.db.driverClass"
171
                  name="%DRIVER_CLASS_PROPERTY_NAME"
172
                  value="org.apache.derby.jdbc.EmbeddedDriver"
173
                  required="true"
174
                  visible="false"/>
175
            <property
176
                  generated="false"
177
                  id="org.eclipse.datatools.connectivity.db.vendor"
178
                  name="%VENDOR_PROPERTY_NAME"
179
                  value="Derby"
180
                  required="true"
181
                  visible="false"/>
182
            <property
183
                  generated="false"
184
                  id="org.eclipse.datatools.connectivity.db.version"
185
                  name="%VERSION_PROPERTY_NAME"
186
                  value="10.1"
187
                  required="true"
188
                  visible="false"/>   
189
            <property
190
                  generated="false"
191
                  id="org.eclipse.datatools.connectivity.db.databaseName"
192
                  name="%DATABASE_NAME_PROPERTY_NAME"
193
                  value="SAMPLE"
194
                  required="true"
195
                  visible="true"/>                             
196
            <property
197
                  generated="false"
198
                  id="org.eclipse.datatools.connectivity.db.URL"
199
                  name="%CONNECTION_URL_PROPERTY_NAME"
200
                  value="jdbc:derby:C:\DerbyDatabases\MyDB;create=true"
201
                  required="true"
202
                  visible="true"/>
203
            <property
204
                  generated="false"
205
                  id="org.eclipse.datatools.connectivity.db.username"
206
                  name="%USER_ID_PROPERTY_NAME"
207
                  value=""
208
                  required="false"
209
                  visible="true"/>
210
            <property
211
                  generated="false"
212
                  id="org.eclipse.datatools.connectivity.db.password"
213
                  name="%PASSWORD_PROPERTY_NAME"
214
                  required="false"
215
                  visible="true"/>
216
         </properties>
217
      </driverTemplate>
218
      <driverTemplate
219
            createDefault="false"
220
            emptyJarListIsOK="false"
221
            id="org.eclipse.datatools.connectivity.db.derby102.genericDriverTemplate"
222
            jarList="derby.jar"
223
            name="%DERBY102_EMBEDDED_DRIVER_TEMPLATE_NAME"
224
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_2.driverCategory">
225
         <properties>
226
            <property
227
                  generated="false"
228
                  id="org.eclipse.datatools.connectivity.db.driverClass"
229
                  name="%DRIVER_CLASS_PROPERTY_NAME"
230
                  value="org.apache.derby.jdbc.EmbeddedDriver"
231
                  required="true"
232
                  visible="false"/>
233
            <property
234
                  generated="false"
235
                  id="org.eclipse.datatools.connectivity.db.vendor"
236
                  name="%VENDOR_PROPERTY_NAME"
237
                  value="Derby"
238
                  required="true"
239
                  visible="false"/>
240
            <property
241
                  generated="false"
242
                  id="org.eclipse.datatools.connectivity.db.version"
243
                  name="%VERSION_PROPERTY_NAME"
244
                  value="10.2"
245
                  required="true"
246
                  visible="false"/>   
247
            <property
248
                  generated="false"
249
                  id="org.eclipse.datatools.connectivity.db.databaseName"
250
                  name="%DATABASE_NAME_PROPERTY_NAME"
251
                  value="SAMPLE"
252
                  required="true"
253
                  visible="true"/>                             
254
            <property
255
                  generated="false"
256
                  id="org.eclipse.datatools.connectivity.db.URL"
257
                  name="%CONNECTION_URL_PROPERTY_NAME"
258
                  value="jdbc:derby:C:\DerbyDatabases\MyDB;create=true"
259
                  required="true"
260
                  visible="true"/>
261
            <property
262
                  generated="false"
263
                  id="org.eclipse.datatools.connectivity.db.username"
264
                  name="%USER_ID_PROPERTY_NAME"
265
                  value=""
266
                  required="false"
267
                  visible="true"/>
268
            <property
269
                  generated="false"
270
                  id="org.eclipse.datatools.connectivity.db.password"
271
                  name="%PASSWORD_PROPERTY_NAME"
272
                  required="false"
273
                  visible="true"/>
274
         </properties>
275
      </driverTemplate>
276
      <driverTemplate
277
            createDefault="false"
278
            emptyJarListIsOK="false"
279
            id="org.eclipse.datatools.connectivity.db.derby.db2UniversalDriver"
280
            jarList="db2jcc.jar;db2jcc_license_c.jar"
281
            name="%DERBY_NETWORK_EMBEDDED_DRIVER_TEMPLATE_NAME"
282
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_0.driverCategory">
283
         <properties>
284
            <property
285
                  generated="false"
286
                  id="org.eclipse.datatools.connectivity.db.driverClass"
287
                  name="%DRIVER_CLASS_PROPERTY_NAME"
288
                  value="com.ibm.db2.jcc.DB2Driver"
289
                  required="true"
290
                  visible="true"/>
291
            <property
292
                  generated="false"
293
                  id="org.eclipse.datatools.connectivity.db.vendor"
294
                  name="%VENDOR_PROPERTY_NAME"
295
                  value="Derby"
296
                  required="true"
297
                  visible="false"/>
298
            <property
299
                  generated="false"
300
                  id="org.eclipse.datatools.connectivity.db.version"
301
                  name="%VERSION_PROPERTY_NAME"
302
                  value="10.0"
303
                  required="true"
304
                  visible="false"/>   
305
            <property
306
                  generated="false"
307
                  id="org.eclipse.datatools.connectivity.db.databaseName"
308
                  name="%DATABASE_NAME_PROPERTY_NAME"
309
                  value="SAMPLE"
310
                  required="true"
311
                  visible="true"/>                             
312
            <property
313
                  generated="false"
314
                  id="org.eclipse.datatools.connectivity.db.URL"
315
                  name="%CONNECTION_URL_PROPERTY_NAME"
316
                  value='jdbc:derby:net://localhost:1527/"C:/DerbyDatabases/MyDB";create=true:retrieveMessagesFromServerOnGetMessage=true;'
317
                  required="true"
318
                  visible="true"/>
319
            <property
320
                  generated="false"
321
                  id="org.eclipse.datatools.connectivity.db.username"
322
                  name="%USER_ID_PROPERTY_NAME"
323
                  value="user"
324
                  required="true"
325
                  visible="true"/>
326
            <property
327
                  generated="false"
328
                  id="org.eclipse.datatools.connectivity.db.password"
329
                  name="%PASSWORD_PROPERTY_NAME"
330
                  required="true"
331
                  value="pwd"
332
                  visible="true"/>
333
         </properties>
334
      </driverTemplate>
335
      <driverTemplate
336
            createDefault="false"
337
            emptyJarListIsOK="false"
338
            id="org.eclipse.datatools.connectivity.db.derby101.db2UniversalDriver"
339
            jarList="db2jcc.jar;db2jcc_license_c.jar"
340
            name="%DERBY101_NETWORK_EMBEDDED_DRIVER_TEMPLATE_NAME"
341
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_1.driverCategory">
342
         <properties>
343
            <property
344
                  generated="false"
345
                  id="org.eclipse.datatools.connectivity.db.driverClass"
346
                  name="%DRIVER_CLASS_PROPERTY_NAME"
347
                  value="com.ibm.db2.jcc.DB2Driver"
348
                  required="true"
349
                  visible="true"/>
350
            <property
351
                  generated="false"
352
                  id="org.eclipse.datatools.connectivity.db.vendor"
353
                  name="%VENDOR_PROPERTY_NAME"
354
                  value="Derby"
355
                  required="true"
356
                  visible="false"/>
357
            <property
358
                  generated="false"
359
                  id="org.eclipse.datatools.connectivity.db.version"
360
                  name="%VERSION_PROPERTY_NAME"
361
                  value="10.1"
362
                  required="true"
363
                  visible="false"/>   
364
            <property
365
                  generated="false"
366
                  id="org.eclipse.datatools.connectivity.db.databaseName"
367
                  name="%DATABASE_NAME_PROPERTY_NAME"
368
                  value="SAMPLE"
369
                  required="true"
370
                  visible="true"/>                             
371
            <property
372
                  generated="false"
373
                  id="org.eclipse.datatools.connectivity.db.URL"
374
                  name="%CONNECTION_URL_PROPERTY_NAME"
375
                  value='jdbc:derby:net://localhost:1527/"C:/DerbyDatabases/MyDB";create=true:retrieveMessagesFromServerOnGetMessage=true;'
376
                  required="true"
377
                  visible="true"/>
378
            <property
379
                  generated="false"
380
                  id="org.eclipse.datatools.connectivity.db.username"
381
                  name="%USER_ID_PROPERTY_NAME"
382
                  value="user"
383
                  required="true"
384
                  visible="true"/>
385
            <property
386
                  generated="false"
387
                  id="org.eclipse.datatools.connectivity.db.password"
388
                  name="%PASSWORD_PROPERTY_NAME"
389
                  required="true"
390
                  value="pwd"
391
                  visible="true"/>
392
         </properties>
393
      </driverTemplate>    
394
      <driverTemplate
395
            createDefault="false"
396
            emptyJarListIsOK="false"
397
            id="org.eclipse.datatools.connectivity.db.derby101.clientDriver"
398
            jarList="derbyclient.jar"
399
            name="%DERBY101_CLIENT_DRIVER_TEMPLATE_NAME"
400
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_1.driverCategory">
401
         <properties>
402
            <property
403
                  generated="false"
404
                  id="org.eclipse.datatools.connectivity.db.driverClass"
405
                  name="%DRIVER_CLASS_PROPERTY_NAME"
406
                  value="org.apache.derby.jdbc.ClientDriver"
407
                  required="true"
408
                  visible="true"/>
409
            <property
410
                  generated="false"
411
                  id="org.eclipse.datatools.connectivity.db.vendor"
412
                  name="%VENDOR_PROPERTY_NAME"
413
                  value="Derby"
414
                  required="true"
415
                  visible="false"/>
416
            <property
417
                  generated="false"
418
                  id="org.eclipse.datatools.connectivity.db.version"
419
                  name="%VERSION_PROPERTY_NAME"
420
                  value="10.1"
421
                  required="true"
422
                  visible="false"/>   
423
            <property
424
                  generated="false"
425
                  id="org.eclipse.datatools.connectivity.db.databaseName"
426
                  name="%DATABASE_NAME_PROPERTY_NAME"
427
                  value="SAMPLE"
428
                  required="true"
429
                  visible="true"/>                             
430
            <property
431
                  generated="false"
432
                  id="org.eclipse.datatools.connectivity.db.URL"
433
                  name="%CONNECTION_URL_PROPERTY_NAME"
434
                  value="jdbc:derby://localhost:1527/sample;create=true"
435
                  required="true"
436
                  visible="true"/>
437
            <property
438
                  generated="false"
439
                  id="org.eclipse.datatools.connectivity.db.username"
440
                  name="%USER_ID_PROPERTY_NAME"
441
                  value="user"
442
                  required="true"
443
                  visible="true"/>
444
            <property
445
                  generated="false"
446
                  id="org.eclipse.datatools.connectivity.db.password"
447
                  name="%PASSWORD_PROPERTY_NAME"
448
                  required="true"
449
                  value="pwd"
450
                  visible="true"/>
451
         </properties>
452
      </driverTemplate> 
453
            <driverTemplate
454
            createDefault="false"
455
            emptyJarListIsOK="false"
456
            id="org.eclipse.datatools.connectivity.db.derby102.clientDriver"
457
            jarList="derbyclient.jar"
458
            name="%DERBY102_CLIENT_DRIVER_TEMPLATE_NAME"
459
            parentCategory="org.eclipse.datatools.connectivity.db.derby.10_2.driverCategory">
460
         <properties>
461
            <property
462
                  generated="false"
463
                  id="org.eclipse.datatools.connectivity.db.driverClass"
464
                  name="%DRIVER_CLASS_PROPERTY_NAME"
465
                  value="org.apache.derby.jdbc.ClientDriver"
466
                  required="true"
467
                  visible="true"/>
468
            <property
469
                  generated="false"
470
                  id="org.eclipse.datatools.connectivity.db.vendor"
471
                  name="%VENDOR_PROPERTY_NAME"
472
                  value="Derby"
473
                  required="true"
474
                  visible="false"/>
475
            <property
476
                  generated="false"
477
                  id="org.eclipse.datatools.connectivity.db.version"
478
                  name="%VERSION_PROPERTY_NAME"
479
                  value="10.2"
480
                  required="true"
481
                  visible="false"/>   
482
            <property
483
                  generated="false"
484
                  id="org.eclipse.datatools.connectivity.db.databaseName"
485
                  name="%DATABASE_NAME_PROPERTY_NAME"
486
                  value="SAMPLE"
487
                  required="true"
488
                  visible="true"/>                             
489
            <property
490
                  generated="false"
491
                  id="org.eclipse.datatools.connectivity.db.URL"
492
                  name="%CONNECTION_URL_PROPERTY_NAME"
493
                  value="jdbc:derby://localhost:1527/sample;create=true"
494
                  required="true"
495
                  visible="true"/>
496
            <property
497
                  generated="false"
498
                  id="org.eclipse.datatools.connectivity.db.username"
499
                  name="%USER_ID_PROPERTY_NAME"
500
                  value="user"
501
                  required="true"
502
                  visible="true"/>
503
            <property
504
                  generated="false"
505
                  id="org.eclipse.datatools.connectivity.db.password"
506
                  name="%PASSWORD_PROPERTY_NAME"
507
                  required="true"
508
                  value="pwd"
509
                  visible="true"/>
510
         </properties>
511
      </driverTemplate> 
512
   </extension>
513
68
</plugin>
514
</plugin>
(-)plugin.properties (-1 / +26 lines)
Lines 10-13 Link Here
10
###############################################################################
10
###############################################################################
11
11
12
pluginName = Eclipse Data Tools Platform Derby Plug-in
12
pluginName = Eclipse Data Tools Platform Derby Plug-in
13
providerName = Eclipse.org
13
providerName = Eclipse.org
14
15
DERBY_CONNECTION_PROFILE_NAME=Derby Embedded Database
16
DERBY_JDBC_CONNECTION_FACTORY_NAME=JDBC Connection
17
DERBY_PING_CONNECTION_FACTORY_NAME=Ping Connection Factory
18
DERBY_SQL_MODEL_CONNECTION_FACTORY_NAME=SQL Model Connection
19
DRIVER_CLASS_PROPERTY_NAME=Driver Class
20
VENDOR_PROPERTY_NAME=Vendor
21
VERSION_PROPERTY_NAME=Version
22
DATABASE_NAME_PROPERTY_NAME=Database Name
23
CONNECTION_URL_PROPERTY_NAME=Connection URL
24
USER_ID_PROPERTY_NAME=User ID
25
PASSWORD_PROPERTY_NAME=Password
26
27
DERBY_CATEGORY_NAME=Derby
28
10_0_VERSION_CATEGORY_NAME = 10.0
29
10_1_VERSION_CATEGORY_NAME = 10.1
30
10_2_VERSION_CATEGORY_NAME = 10.2
31
32
DERBY_EMBEDDED_DRIVER_TEMPLATE_NAME=Derby Embedded JDBC Driver
33
DERBY101_EMBEDDED_DRIVER_TEMPLATE_NAME=Derby Embedded JDBC Driver
34
DERBY_NETWORK_EMBEDDED_DRIVER_TEMPLATE_NAME=DB2 Universal Driver
35
DERBY101_NETWORK_EMBEDDED_DRIVER_TEMPLATE_NAME=DB2 Universal Driver
36
DERBY101_CLIENT_DRIVER_TEMPLATE_NAME = Derby Client JDBC Driver
37
DERBY102_EMBEDDED_DRIVER_TEMPLATE_NAME=Derby Embedded JDBC Driver
38
DERBY102_CLIENT_DRIVER_TEMPLATE_NAME = Derby Client JDBC Driver
(-)src/org/eclipse/datatools/connectivity/internal/derby/connection/IDerbyConnectionProfileConstants.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Sybase, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    rcernich - initial API and implementation
11
 *******************************************************************************/ 
12
package org.eclipse.datatools.connectivity.internal.derby.connection;
13
14
15
public interface IDerbyConnectionProfileConstants {
16
17
	public static final String DERBY_CATEGORY_ID = "org.eclipse.datatools.connectivity.db.derby.driverCategory"; //$NON-NLS-1$
18
	public static final String DERBY_ENABLEMENT_DRIVER_PREFIX = "org.eclipse.datatools.connectivity.db.derby"; //$NON-NLS-1$
19
	public static final String DERBY_ENABLEMENT_DRIVER_SUFFIX = "genericDriverTemplate"; //$NON-NLS-1$
20
	
21
}
(-)icons/jdbc_16.gif (+3 lines)
Added Link Here
1
GIF89a³€ŸŸŸ¿ÜÛÀ¿À­®­€€¿¿¿ßß¿ÿßßîîî`_`_`_öööÑÑÑÿÿÿ!ù,sÐIֈ½?I™l ‚ƒ•HD0€‚È!Fè²$0ê
2
Â
3
?P(x?ä±($ƒÁá…gÅÓpÅ¢ÉD*‰×aA?FÁi@vÛý†Ç³ròÌD­¡RTp2<_u`'‡G‘?”•–;
(-)src/org/eclipse/datatools/connectivity/internal/derby/connection/DerbyEmbeddedJDBCConnection.java (+165 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Sybase, Inc.
3
 * 
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
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors: rcernich - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.datatools.connectivity.internal.derby.connection;
12
13
import java.sql.Connection;
14
import java.sql.Driver;
15
import java.sql.SQLException;
16
import java.util.HashMap;
17
import java.util.Map;
18
import java.util.Properties;
19
20
import org.eclipse.datatools.connectivity.IConnectionProfile;
21
import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants;
22
import org.eclipse.datatools.connectivity.db.generic.JDBCConnection;
23
24
/**
25
 * This class is used to represent Derby embedded connections. There are a
26
 * couple of particulars to Derby embedded connections which require special
27
 * treatement.
28
 * 
29
 * One, Derby only supports a single connection per JVM when operating as an
30
 * embedded DB. This class ensures that only one instance of an embedded DB
31
 * connection exists at any given time.
32
 * 
33
 * Two, java.sql.Connection.close() is not supported by the Derby embedded JDBC
34
 * driver. Embedded connections must be closed using the following:
35
 * java.sql.Driver.getConnection("&lt;url&gt;;shutdown=true").
36
 * 
37
 * @author rcernich
38
 * 
39
 * Created on Jan 30, 2006
40
 */
41
public class DerbyEmbeddedJDBCConnection extends JDBCConnection {
42
43
	/**
44
	 * Maps connection URLs to connections.
45
	 */
46
	private static Map sDerbyConnections = new HashMap();
47
	/**
48
	 * Maps connections to integers. The integer represents the number of
49
	 * DerbyEmbeddedJDBCConnection objects referencing the connection
50
	 */
51
	private static Map sConnectionReferenceCount = new HashMap();
52
53
	public DerbyEmbeddedJDBCConnection(IConnectionProfile profile,
54
										Class factoryClass) {
55
		super(profile, factoryClass);
56
	}
57
58
	public void close() {
59
		Connection connection = (Connection) getRawConnection();
60
		if (connection == null) {
61
			return;
62
		}
63
		synchronized (sDerbyConnections) {
64
			int count = ((Integer) sConnectionReferenceCount.get(connection))
65
					.intValue();
66
			if (count == 1) {
67
				/*
68
				 * If this is the last reference to the connection, close the
69
				 * connection.
70
				 */
71
				String baseDBURL = getBaseDBURL();
72
				try {
73
					/* The particulars of closing the connection. */
74
					String driverClass = getDriverDefinition().getProperty(
75
							IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID);
76
					Driver driver = (Driver) connection.getClass()
77
							.getClassLoader().loadClass(driverClass)
78
							.newInstance();
79
					driver.connect(baseDBURL + ";shutdown=true",  //$NON-NLS-1$
80
							new Properties());
81
				}
82
				catch (InstantiationException e) {
83
					/*
84
					 * We shouldn't see this, because we needed this to create
85
					 * the connection
86
					 */
87
				}
88
				catch (IllegalAccessException e) {
89
					/*
90
					 * We shouldn't see this, because we needed this to create
91
					 * the connection
92
					 */
93
				}
94
				catch (ClassNotFoundException e) {
95
					/*
96
					 * We shouldn't see this, because we needed this to create
97
					 * the connection
98
					 */
99
				}
100
				catch (SQLException e) {
101
					// Successfully closed the connection
102
					sConnectionReferenceCount.remove(connection);
103
					sDerbyConnections.remove(baseDBURL);
104
				}
105
				catch (Exception e) {
106
					/*
107
					 * Can't get the driver. This might happen if the user
108
					 * modified or deleted the driver definition in the time
109
					 * since this connection was created.
110
					 */
111
				}
112
			}
113
			else {
114
				/* Otherwise, just decrement the reference count. */
115
				sConnectionReferenceCount.put(connection, new Integer(--count));
116
			}
117
		}
118
	}
119
120
	protected Object createConnection(ClassLoader cl) throws Throwable {
121
		Connection connection;
122
		synchronized (sDerbyConnections) {
123
			String dbName = getBaseDBURL();
124
			if (sDerbyConnections.containsKey(dbName)) {
125
				/*
126
				 * Get the existing connection and increment the reference
127
				 * count.
128
				 */
129
				connection = (Connection) sDerbyConnections.get(dbName);
130
				int count = ((Integer) sConnectionReferenceCount
131
						.get(connection)).intValue();
132
				sConnectionReferenceCount.put(connection, new Integer(++count));
133
			}
134
			else {
135
				/* Create the connection and initialize the referencing scheme. */
136
				connection = (Connection) super.createConnection(cl);
137
				sDerbyConnections.put(dbName, connection);
138
				sConnectionReferenceCount.put(connection, new Integer(1));
139
			}
140
		}
141
		return connection;
142
	}
143
144
	/**
145
	 * We're only concerned with the base part of the URL. This should work for
146
	 * every Derby URL form except those using the databaseName parameter to
147
	 * specify the database name.
148
	 * 
149
	 * @return the base URL
150
	 */
151
	private String getBaseDBURL() {
152
		String baseURL;
153
		String connectURL = getConnectionProfile().getBaseProperties()
154
				.getProperty(IDBDriverDefinitionConstants.URL_PROP_ID);
155
		int propertyStart = connectURL.indexOf(';');
156
		if (propertyStart < 0) {
157
			baseURL = connectURL;
158
		}
159
		else {
160
			baseURL = connectURL.substring(0, propertyStart);
161
		}
162
		return baseURL;
163
	}
164
165
}
(-)src/org/eclipse/datatools/connectivity/internal/derby/connection/DerbyJDBCConnectionFactory.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Sybase, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    rcernich - initial API and implementation
11
 *******************************************************************************/ 
12
package org.eclipse.datatools.connectivity.internal.derby.connection;
13
14
import org.eclipse.datatools.connectivity.IConnection;
15
import org.eclipse.datatools.connectivity.IConnectionFactory;
16
import org.eclipse.datatools.connectivity.IConnectionProfile;
17
18
19
public class DerbyJDBCConnectionFactory implements IConnectionFactory {
20
21
	public DerbyJDBCConnectionFactory() {
22
		super();
23
	}
24
25
	/*
26
	 * (non-Javadoc)
27
	 * 
28
	 * @see org.eclipse.datatools.connectivity.IConnectionFactory#createConnection(org.eclipse.datatools.connectivity.IConnectionProfile)
29
	 */
30
	public IConnection createConnection(IConnectionProfile profile) {
31
		DerbyEmbeddedJDBCConnection connection = new DerbyEmbeddedJDBCConnection(profile, getClass());
32
		connection.open();
33
		return connection;
34
	}
35
36
	/*
37
	 * (non-Javadoc)
38
	 * 
39
	 * @see org.eclipse.datatools.connectivity.IConnectionFactory#createConnection(org.eclipse.datatools.connectivity.IConnectionProfile,
40
	 *      java.lang.String, java.lang.String)
41
	 */
42
	public IConnection createConnection(IConnectionProfile profile, String uid,
43
			String pwd) {
44
		return createConnection(profile);
45
	}
46
47
}

Return to bug 203158