Logo Search packages:      
Sourcecode: henplus version File versions  Download package

int henplus::commands::DumpCommand::execute ( SQLSession  session,
String  cmd,
String  param 
) [inline]

execute the command given.

Implements henplus::Command.

Definition at line 173 of file DumpCommand.java.

References henplus::Command::EXEC_FAILED, retryReadDump(), henplus::Command::SUCCESS, and henplus::Command::SYNTAX_ERROR.

                                                                     {
      //final String FILE_ENCODING = System.getProperty("file.encoding");
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();

      if ("dump-conditional".equals(cmd)) {
          if (session == null) {
            HenPlus.msg().println("not connected.");
            return EXEC_FAILED;
          }
          if ((argc < 2)) return SYNTAX_ERROR;
          String fileName = (String) st.nextElement();
          String tabName  = (String) st.nextElement();
          String whereClause = null;
          if (argc >= 3) {
            whereClause = (String) st.nextToken("\n"); // till EOL
            whereClause = whereClause.trim();
            if (whereClause.toUpperCase().startsWith("WHERE")) {
                whereClause = whereClause.substring(5);
                whereClause = whereClause.trim();
            }
          }
          PrintStream out = null;
          try {
            out = openOutputStream(fileName, FILE_ENCODING);
            int result = dumpTable(session, tabName, whereClause, out,
                               FILE_ENCODING);
            return result;
          }
          catch (Exception e) {
            HenPlus.msg().println("failed: " + e.getMessage());
            e.printStackTrace();
            return EXEC_FAILED;
          }
          finally {
            if (out != null) out.close(); 
          }
      }
      
      else if ("dump-out".equals(cmd)) {
          if (session == null) {
            HenPlus.msg().println("not connected.");
            return EXEC_FAILED;
          }
          if ((argc < 2)) return SYNTAX_ERROR;
          String fileName = (String) st.nextElement();
          PrintStream out = null;
          try {
            out = openOutputStream(fileName, FILE_ENCODING);
            while (st.hasMoreElements()) {
                String tabName  = (String) st.nextElement();
                int result = dumpTable(session, tabName, null, out,
                                 FILE_ENCODING);
                if (result != SUCCESS) {
                  return result;
                }
            }
            return SUCCESS;
          }
          catch (Exception e) {
            HenPlus.msg().println("failed: " + e.getMessage());
            e.printStackTrace();
            return EXEC_FAILED;
          }
          finally {
            if (out != null) out.close(); 
          }
      }

      else if ("dump-in".equals(cmd)) {
          if (session == null) {
            HenPlus.msg().println("not connected. Only verify-dump possible.");
            return EXEC_FAILED;
          }
          if (argc < 1 || argc > 2) return SYNTAX_ERROR;
          String fileName = (String) st.nextElement();
          int commitPoint = -1;
          if (argc == 2) {
            try {
                String val = (String) st.nextElement();
                commitPoint = Integer.valueOf(val).intValue();
            }
            catch (NumberFormatException e) {
                HenPlus.msg().println("commit point number expected: " + e);
                return SYNTAX_ERROR;
            }
          }
            return retryReadDump(fileName, session, commitPoint);
      }
      
      else if ("verify-dump".equals(cmd)) {
          if (argc != 1) return SYNTAX_ERROR;
          String fileName = (String) st.nextElement();
            return retryReadDump(fileName, null, -1);
      }
      return SYNTAX_ERROR;
    }


Generated by  Doxygen 1.6.0   Back to index