예제 #1
0
  /**
   * Create the command line for a psql process depending on the meta information supplied.
   *
   * @param meta The meta data to create the command line from
   * @param password Use the real password or not
   * @return The string to execute.
   * @throws KettleException Upon any exception
   */
  public String createCommandLine(GPLoadMeta meta, boolean password) throws KettleException {
    StringBuffer sb = new StringBuffer(300);

    if (meta.getGploadPath() != null) {
      try {
        FileObject fileObject =
            KettleVFS.getFileObject(environmentSubstitute(meta.getGploadPath()), getTransMeta());
        String psqlexec = KettleVFS.getFilename(fileObject);
        // sb.append('\'').append(psqlexec).append('\'');
        sb.append(psqlexec);
      } catch (Exception ex) {
        throw new KettleException("Error retrieving sqlldr string", ex);
      }
    } else {
      throw new KettleException("No psql application specified");
    }

    if (meta.getControlFile() != null) {
      try {
        FileObject fileObject =
            KettleVFS.getFileObject(environmentSubstitute(meta.getControlFile()), getTransMeta());

        sb.append(" -f ");
        // sb.append('\'').append(KettleVFS.getFilename(fileObject)).append('\'');
        sb.append(KettleVFS.getFilename(fileObject));
      } catch (Exception ex) {
        throw new KettleException("Error retrieving controlfile string", ex);
      }
    } else {
      throw new KettleException("No control file specified");
    }

    if (meta.getLogFile() != null) {
      try {
        FileObject fileObject =
            KettleVFS.getFileObject(environmentSubstitute(meta.getLogFile()), getTransMeta());

        sb.append(" -l ");
        sb.append('\'').append(KettleVFS.getFilename(fileObject)).append('\'');
      } catch (Exception ex) {
        throw new KettleException("Error retrieving logfile string", ex);
      }
    }

    // hostname, port and so on are passed through the control file
    //

    return sb.toString();
  }