1 package com.explosion.expfmodules.rdbmsconn.connectwizard.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 /***
23 * @author Stephen Cowx
24 * Created on 21-Feb-2005
25 */
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import com.explosion.expfmodules.rdbmsconn.ConnectionDescriptorManager;
30 import com.explosion.expfmodules.rdbmsconn.RdbmsConnConstants;
31 import com.explosion.expfmodules.rdbmsconn.RdbmsConnModuleManager;
32 import com.explosion.expfmodules.wizard.StepAction;
33 import com.explosion.expfmodules.wizard.Wizard;
34 import com.explosion.expfmodules.wizard.standard.PreferenceDataItem;
35 import com.explosion.utilities.exception.ExceptionManagerFactory;
36 import com.explosion.utilities.preferences.groups.PreferenceGroup;
37
38 public class MySQLConnectionAction implements StepAction {
39
40 /***
41 * Creates a MySQL database connection based on the information
42 * collected in the wizard.
43 */
44 public boolean execute(Wizard wizard) {
45
46 try {
47
48
49 String hostname = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("hostname")).getPreference().getValue();
50 Integer port = (Integer) ((PreferenceDataItem) wizard.getWizardDataValues().get("port")).getPreference().getValue();
51 String dbname = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("dbname")).getPreference().getValue();
52 String user = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("username")).getPreference().getValue();
53 String pass = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("password")).getPreference().getValue();
54
55
56 Map store = new HashMap();
57 ConnectionDescriptorManager manager = new ConnectionDescriptorManager(RdbmsConnModuleManager.instance().getDriverDescriptorManager(), store);
58 PreferenceGroup group = manager.createGroup("New connection");
59 group.setPreferenceValue(RdbmsConnConstants.CD_DRIVER,"MySQL Connector Java 3.0.10 Stable");
60 group.setPreferenceValue(RdbmsConnConstants.CD_USER,user);
61 group.setPreferenceValue(RdbmsConnConstants.CD_PASS,pass);
62
63
64 group.setPreferenceValue(RdbmsConnConstants.CD_URL,"jdbc:mysql://"+hostname+":"+port+"/"+dbname);
65
66 wizard.getWizardDataValues().put("connection_descriptor", group);
67
68 return true;
69
70 } catch (Exception e) {
71 ExceptionManagerFactory.getExceptionManager().manageException(e, "Caught exception while creating new instance of connection.");
72 }
73 return false;
74 }
75 }