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.io.File;
27 import java.util.HashMap;
28 import java.util.Map;
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 HSQLDBConnectionAction 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 connectionType = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("connectiontype")).getPreference().getValue();
50 String user = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("username")).getPreference().getValue();
51 String pass = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("password")).getPreference().getValue();
52
53
54 Map store = new HashMap();
55 ConnectionDescriptorManager manager = new ConnectionDescriptorManager(RdbmsConnModuleManager.instance().getDriverDescriptorManager(), store);
56 PreferenceGroup group = manager.createGroup("New connection");
57 group.setPreferenceValue(RdbmsConnConstants.CD_DRIVER,"HyperSonic SQL JDBC Driver (1.7.1)");
58 group.setPreferenceValue(RdbmsConnConstants.CD_USER,user);
59 group.setPreferenceValue(RdbmsConnConstants.CD_PASS,pass);
60
61
62 if (connectionType.equals("Server"))
63 {
64 String hostname = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("hostname")).getPreference().getValue();
65 Integer port = (Integer) ((PreferenceDataItem) wizard.getWizardDataValues().get("port")).getPreference().getValue();
66
67 group.setPreferenceValue(RdbmsConnConstants.CD_URL,"jdbc:hsqldb:hsql://"+hostname + ":" + port);
68 }
69 else if (connectionType.equals("Standalone"))
70 {
71 File directory = (File) ((PreferenceDataItem) wizard.getWizardDataValues().get("directory")).getPreference().getValue();
72 String dbname = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("dbname")).getPreference().getValue();
73 String directoryPath = directory.getAbsolutePath();
74
75 String location = "";
76 if (directoryPath.length() < 1)
77 {
78 location = dbname;
79 }
80 else
81 {
82 location = directoryPath + (dbname.length() > 0 ? "/" : "")+ dbname;
83 }
84
85 group.setPreferenceValue(RdbmsConnConstants.CD_URL,"jdbc:hsqldb:" + directory.getAbsolutePath() + "/" + dbname);
86 }
87 else if (connectionType.equals("In-Memory"))
88 {
89
90 group.setPreferenceValue(RdbmsConnConstants.CD_URL,"jdbc:hsqldb:.");
91 }
92
93 wizard.getWizardDataValues().put("connection_descriptor", group);
94
95 return true;
96
97 } catch (Exception e) {
98 ExceptionManagerFactory.getExceptionManager().manageException(e, "Caught exception while creating new instance of connection.");
99 }
100 return false;
101 }
102 }