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

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

execute the command given.

Implements henplus::Command.

Definition at line 86 of file LoadCommand.java.

References _cwdStack, _openFiles, henplus::Command::EXEC_FAILED, openFile(), henplus::Command::SUCCESS, and henplus::Command::SYNTAX_ERROR.

                                                                     {
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();
      if (argc < 1) {
          return SYNTAX_ERROR;
      }
      HenPlus henplus = HenPlus.getInstance();
      while (st.hasMoreElements()) {
          int  commandCount = 0;
          String filename = (String) st.nextElement();
          long startTime = System.currentTimeMillis();
          File currentFile = null;
          try {
            henplus.pushBuffer();
            henplus.getDispatcher().startBatch();
                File f = openFile(filename);
            f = f.getCanonicalFile();
            if (_openFiles.contains(f)) {
                throw new IOException("recursive inclusion alert: skipping file " + f.getName());
            }
            HenPlus.msg().println(f.getName());
            currentFile = f;
            _openFiles.add(currentFile);
            _cwdStack.push(currentFile.getParentFile());
            BufferedReader reader = new BufferedReader(new FileReader(currentFile));
            String line;
            while ((line = reader.readLine()) != null) {
                byte execResult = henplus.executeLine(line);
                if (execResult == HenPlus.LINE_EXECUTED) {
                  ++commandCount;
                }
            }
          }
          catch (Exception e) {
            //e.printStackTrace();
            HenPlus.msg().println(e.getMessage());
            if (st.hasMoreElements()) {
                HenPlus.msg().println("..skipping to next file.");
                continue;
            }
            return EXEC_FAILED;
          }
          finally {
            henplus.popBuffer(); // no open state ..
            henplus.getDispatcher().endBatch();
            if (currentFile != null) {
                _openFiles.remove(currentFile);
                _cwdStack.pop();
            }
          }
          long execTime = System.currentTimeMillis() - startTime;
          HenPlus.msg().print(commandCount + " commands in ");
          TimeRenderer.printTime(execTime, HenPlus.msg());
          if (commandCount != 0) {
            HenPlus.msg().print("; avg. time ");
            TimeRenderer.printFraction(execTime, commandCount, 
                                           HenPlus.msg());
          }
          if (execTime != 0 && commandCount > 0) {
            HenPlus.msg().print("; " + 
                                    (1000 * commandCount / execTime) 
                                    + " per second");
          }
          HenPlus.msg().println(" (" + filename + ")");
      }
      return SUCCESS;
    }


Generated by  Doxygen 1.6.0   Back to index