private void combineTempFiles(List<String> titles, List<File> files) {
   try {
     PrintWriter wtr = new PrintWriter(new FileWriter(_outFile));
     try {
       // i18n[DumpApplicationCommand.header=SQuirreL SQL Client Application Dump {0}]
       String header =
           s_stringMgr.getString(
               "DumpApplicationCommand.header", Calendar.getInstance().getTime());
       wtr.println(header);
       for (int i = 0, limit = files.size(); i < limit; ++i) {
         wtr.println();
         wtr.println();
         wtr.println(SEP);
         wtr.println(titles.get(i));
         wtr.println(SEP);
         BufferedReader rdr = new BufferedReader(new FileReader(files.get(i)));
         try {
           String line = null;
           while ((line = rdr.readLine()) != null) {
             wtr.println(line);
           }
         } finally {
           rdr.close();
         }
       }
     } finally {
       wtr.close();
     }
   } catch (IOException ex) {
     // i18n[DumpApplicationCommand.error.combiningtempfiles=Error combining temp files into dump
     // file]
     final String msg = s_stringMgr.getString("DumpApplicationCommand.error.combiningtempfiles");
     _msgHandler.showMessage(msg);
     _msgHandler.showMessage(ex.toString());
     s_log.error(msg, ex);
   }
 }
示例#2
0
 public void showMessage(String msg) {
   _msgHandler.showMessage(msg);
 }
示例#3
0
 public void showMessage(Exception ex) {
   _msgHandler.showMessage(ex);
 }
  /** Dump the application. */
  public void execute() {
    List<File> files = new ArrayList<File>();
    List<String> titles = new ArrayList<String>();
    synchronized (_app) {
      ApplicationStatusBean bean = new ApplicationStatusBean();
      bean.load(_app);
      try {
        files.add(createJavaBeanDumpFile(bean));
        // i18n[DumpApplicationCommand.title.status=Application Status Bean]
        titles.add(s_stringMgr.getString("DumpApplicationCommand.title.status"));
      } catch (Throwable th) {
        // i18n[DumpApplicationCommand.error.dumpingstatus=Error dumping Application Status bean]
        final String msg = s_stringMgr.getString("DumpApplicationCommand.error.dumpingstatus");
        _msgHandler.showMessage(msg);
        _msgHandler.showMessage(th, null);
        s_log.error(msg, th);
      }

      // Dump System Properties.
      try {
        File tempFile = File.createTempFile(PREFIX, SUFFIX);
        IDataSetViewer dest = new DataSetViewerTextFileDestination(tempFile);
        dest.show(new HashtableDataSet(System.getProperties()));
        files.add(tempFile);
        // i18n[DumpApplicationCommand.title.systemprops=System Properties]
        titles.add(s_stringMgr.getString("DumpApplicationCommand.title.systemprops"));
      } catch (Throwable th) {
        // i18n[DumpApplicationCommand.error.dumpingsystemprops=Error dumping metadata]
        final String msg = s_stringMgr.getString("DumpApplicationCommand.error.dumpingsystemprops");
        _msgHandler.showMessage(msg);
        _msgHandler.showMessage(th, null);
        s_log.error(msg, th);
      }

      // Dump drivers
      try {
        File tempFile = File.createTempFile(PREFIX, SUFFIX);
        _app.getDataCache().saveDrivers(tempFile);
        files.add(tempFile);
        // i18n[DumpApplicationCommand.title.drivers=Drivers]
        titles.add(s_stringMgr.getString("DumpApplicationCommand.title.drivers"));
      } catch (Throwable th) {
        // i18n[DumpApplicationCommand.error.dumpingdrivers=Error dumping drivers]
        final String msg = s_stringMgr.getString("DumpApplicationCommand.error.dumpingdrivers");
        _msgHandler.showMessage(msg);
        _msgHandler.showMessage(th, null);
        s_log.error(msg, th);
      }

      // Dump aliases.
      try {
        File tempFile = File.createTempFile(PREFIX, SUFFIX);
        _app.getDataCache().saveAliases(tempFile);
        files.add(tempFile);
        // i18n[DumpApplicationCommand.title.aliases=Aliases]
        titles.add(s_stringMgr.getString("DumpApplicationCommand.title.aliases"));
      } catch (Throwable th) {
        // i18n[DumpApplicationCommand.error.dumpingaliases=Error dumping aliases]
        final String msg = s_stringMgr.getString("DumpApplicationCommand.error.dumpingaliases");
        _msgHandler.showMessage(msg);
        _msgHandler.showMessage(th, null);
        s_log.error(msg, th);
      }

      // Dump sessions.
      final ISession[] sessions = _app.getSessionManager().getConnectedSessions();
      final DumpSessionCommand sessionCmd = new DumpSessionCommand();
      for (int i = 0; i < sessions.length; ++i) {
        try {
          File tempFile = File.createTempFile(PREFIX, SUFFIX);
          sessionCmd.setSession(sessions[i]);
          sessionCmd.setDumpFile(tempFile);
          sessionCmd.execute();
          files.add(tempFile);
          // i18n[DumpApplicationCommand.title.sessiondump=Session Dump: {0}]
          String title =
              s_stringMgr.getString(
                  "DumpApplicationCommand.title.sessiondump", sessions[i].getIdentifier());
          titles.add(title);
        } catch (Throwable th) {
          // i18n[DumpApplicationCommand.error.sessiondump=Error dumping sessions]
          final String msg = s_stringMgr.getString("DumpApplicationCommand.error.sessiondump");
          _msgHandler.showMessage(msg);
          _msgHandler.showMessage(th, null);
          s_log.error(msg, th);
        }
      }
    }

    combineTempFiles(titles, files);
    deleteTempFiles(files);
  }