1 package jimm.datavision.gui.cmd; 2 import jimm.datavision.Report; 3 import jimm.datavision.ErrorHandler; 4 import jimm.datavision.source.sql.Database; 5 import jimm.util.I18N; 6 7 12 public class DbConnCommand extends CommandAdapter { 13 14 protected Report report; 15 protected Database origDatabase; 16 protected String driverClassName; 17 protected String connInfo; 18 protected String dbName; 19 protected String username; 20 private String password; 21 22 32 public DbConnCommand(Report report, String driverClassName, 33 String connInfo, String dbName, String username, 34 String password) 35 { 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, dbName, 52 username, password); 53 report.setDataSource(db); 54 } 55 else { 56 db.reset(driverClassName, connInfo, dbName, username, password); 57 } 58 } 59 catch (Exception e) { 60 ErrorHandler.error(e, I18N.get("DbConnWin.connect_error")); 61 } 62 } 63 64 public void undo() { 65 try { 66 if (origDatabase == null) 67 report.setDataSource(null); 68 else 69 origDatabase.reset(driverClassName, connInfo, dbName, username, 70 password); 71 } 72 catch (Exception e) { 73 ErrorHandler.error(I18N.get("DbConnWin.revert_error") + "\n" + e, 74 I18N.get("DbConnWin.revert_error_title")); 75 } 76 } 77 78 } 79 | Popular Tags |