Esempio n. 1
0
  public boolean saveRdbData(Object dsId, RdbDataId rdbId, boolean dialog) {
    boolean success = false;
    if (!mapper.isConnection()) {
      connectionDialog.setVisible(true);
    }
    if (mapper.isConnection()) {

      // If no dialog requested try a direct save.
      if (!dialog) {
        try {
          success = mapper.saveRdbData(dsId, rdbId);
        } catch (Exception exception) {
          JOptionPane.showMessageDialog(
              guiContext, exception.getMessage(), "Database error", JOptionPane.ERROR_MESSAGE);
        }
      }
      // If not saved yet bring up saveas dialog.
      if (!success) {
        groupDialog.setLoadMode(false);
        groupDialog.setDsId(dsId);
        groupDialog.setRdbDataId(rdbId);
        groupDialog.setVisible(true);
        success = groupDialog.isSuccess();
      }
    }
    return success;
  }
Esempio n. 2
0
 public DBData loadRdbData(Object dsId) {
   if (!mapper.isConnection()) {
     connectionDialog.setVisible(true);
   }
   if (mapper.isConnection()) {
     groupDialog.setLoadMode(true);
     groupDialog.setDsId(dsId);
     groupDialog.setRdbDataId(new RdbDataId());
     groupDialog.setVisible(true);
     return groupDialog.getData();
   }
   return null;
 }
  /** Method declaration */
  public void init() {

    DatabaseManager m = new DatabaseManager();

    m.main();

    try {
      m.connect(ConnectionDialog.createConnection(defDriver, defURL, defUser, defPassword));
      m.insertTestData();
      m.refreshTree();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * Method declaration
   *
   * @param ev
   */
  public void actionPerformed(ActionEvent ev) {

    String s = ev.getActionCommand();

    if (s == null) {
      if (ev.getSource() instanceof MenuItem) {
        MenuItem i;

        s = ((MenuItem) ev.getSource()).getLabel();
      }
    }

    if (s.equals("Execute")) {
      execute();
    } else if (s.equals("Exit")) {
      windowClosing(null);
    } else if (s.equals("Transfer")) {
      Transfer.work(null);
    } else if (s.equals("Dump")) {
      Transfer.work(new String[] {"-d"});

      /* NB - 26052002 Restore is not implemented yet in the transfer tool */
      /*
              } else if (s.equals("Restore")) {
                  Transfer.work(new String[]{"-r"});
      */
    } else if (s.equals("Logging on")) {
      jdbcSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
      jdbcSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
      refreshTree();
    } else if (s.startsWith("#")) {
      int i = Integer.parseInt(s.substring(1));

      txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
      connect(ConnectionDialog.createConnection(fMain, "Connect"));
      refreshTree();
    } else if (s.equals("Results in Grid")) {
      iResult = 0;

      pResult.removeAll();
      pResult.add("Center", gResult);
      pResult.doLayout();
    } else if (s.equals("Open Script...")) {
      FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
      }
    } else if (s.equals("Save Script...")) {
      FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
      }
    } else if (s.equals("Save Result...")) {
      FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        showResultInText();
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
      }
    } else if (s.equals("Results in Text")) {
      iResult = 1;

      pResult.removeAll();
      pResult.add("Center", txtResult);
      pResult.doLayout();
      showResultInText();
    } else if (s.equals("AutoCommit on")) {
      try {
        cConn.setAutoCommit(true);
      } catch (SQLException e) {
      }
    } else if (s.equals("AutoCommit off")) {
      try {
        cConn.setAutoCommit(false);
      } catch (SQLException e) {
      }
    } else if (s.equals("Enlarge Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width += 20;

      tTree.setMinimumSize(d);
      fMain.pack();
    } else if (s.equals("Shrink Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width -= 20;

      if (d.width >= 0) {
        tTree.setMinimumSize(d);
      }

      fMain.pack();
    } else if (s.equals("Enlarge Command")) {
      txtCommand.setRows(txtCommand.getRows() + 1);
      fMain.pack();
    } else if (s.equals("Shrink Command")) {
      int i = txtCommand.getRows() - 1;

      txtCommand.setRows(i < 1 ? 1 : i);
      fMain.pack();
    } else if (s.equals("Commit")) {
      try {
        cConn.commit();
      } catch (SQLException e) {
      }
    } else if (s.equals("Insert test data")) {
      insertTestData();
    } else if (s.equals("Rollback")) {
      try {
        cConn.rollback();
      } catch (SQLException e) {
      }
    } else if (s.equals("Disable MaxRows")) {
      try {
        sStatement.setMaxRows(0);
      } catch (SQLException e) {
      }
    } else if (s.equals("Set MaxRows to 100")) {
      try {
        sStatement.setMaxRows(100);
      } catch (SQLException e) {
      }
    } else if (s.equals("SELECT")) {
      showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
      showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
      showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
      showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
      showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
      showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
      showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
      showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
      showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
      showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
      showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
      showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
      showHelp(DatabaseManagerCommon.testHelp);
    }
  }
  /**
   * Method declaration
   *
   * @param arg
   */
  public static void main(String arg[]) {

    System.getProperties().put("sun.java2d.noddraw", "true");

    // (ulrivo): read all arguments from the command line
    String lowerArg;
    boolean autoConnect = false;

    for (int i = 0; i < arg.length; i++) {
      lowerArg = arg[i].toLowerCase();

      i++;

      if (i == arg.length) {
        showUsage();

        return;
      }

      if (lowerArg.equals("-driver")) {
        defDriver = arg[i];
        autoConnect = true;
      } else if (lowerArg.equals("-url")) {
        defURL = arg[i];
        autoConnect = true;
      } else if (lowerArg.equals("-user")) {
        defUser = arg[i];
        autoConnect = true;
      } else if (lowerArg.equals("-password")) {
        defPassword = arg[i];
        autoConnect = true;
      } else if (lowerArg.equals("-dir")) {
        defDirectory = arg[i];
      } else if (lowerArg.equals("-script")) {
        defScript = arg[i];
      } else {
        showUsage();

        return;
      }
    }

    bMustExit = true;

    DatabaseManager m = new DatabaseManager();

    m.main();

    Connection c = null;

    try {
      if (autoConnect) {
        c =
            ConnectionDialog.createConnection(
                defDriver, defURL,
                defUser, defPassword);
      } else {
        c = ConnectionDialog.createConnection(m.fMain, "Connect");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (c == null) {
      return;
    }

    m.connect(c);
  }
Esempio n. 6
0
 public void connect() {
   connectionDialog.setVisible(true);
 }