01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.Report;
04: import jimm.datavision.ErrorHandler;
05: import jimm.datavision.source.sql.Database;
06: import jimm.util.I18N;
07:
08: /**
09: * A command for changing a database's connection information.
10: *
11: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
12: */
13: public class DbConnCommand extends CommandAdapter {
14:
15: protected Report report;
16: protected Database origDatabase;
17: protected String driverClassName;
18: protected String connInfo;
19: protected String dbName;
20: protected String username;
21: private String password;
22:
23: /**
24: * Constructor.
25: *
26: * @param report the report using this database
27: * @param driverClassName database driver class name
28: * @param connInfo database connection info string
29: * @param dbName the database name
30: * @param username the user name to use when logging in to the database
31: * @param password the database password
32: */
33: public DbConnCommand(Report report, String driverClassName,
34: String connInfo, String dbName, String username,
35: String password) {
36: super (I18N.get("DbConnCommand.name"));
37:
38: origDatabase = (Database) report.getDataSource();
39: this .report = report;
40: this .driverClassName = driverClassName;
41: this .connInfo = connInfo;
42: this .dbName = dbName;
43: this .username = (username == null) ? "" : username;
44: this .password = password;
45: }
46:
47: public void perform() {
48: Database db = origDatabase;
49: try {
50: if (db == null) {
51: db = new Database(driverClassName, connInfo, report,
52: dbName, username, password);
53: report.setDataSource(db);
54: } else {
55: db.reset(driverClassName, connInfo, dbName, username,
56: password);
57: }
58: } catch (Exception e) {
59: ErrorHandler.error(e, I18N.get("DbConnWin.connect_error"));
60: }
61: }
62:
63: public void undo() {
64: try {
65: if (origDatabase == null)
66: report.setDataSource(null);
67: else
68: origDatabase.reset(driverClassName, connInfo, dbName,
69: username, password);
70: } catch (Exception e) {
71: ErrorHandler.error(I18N.get("DbConnWin.revert_error")
72: + "\n" + e, I18N
73: .get("DbConnWin.revert_error_title"));
74: }
75: }
76:
77: }
|