Esempio n. 1
0
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {

    if (databaseMeta == null) return;

    Database db = new Database(databaseMeta);
    databases = new Database[] {db}; // Keep track of this one for cancelQuery

    // First try without connecting to the database... (can be  S L O W)
    // See if it's in the cache...
    RowMetaInterface add = null;
    String realSQL = sql;
    if (replacevars) realSQL = space.environmentSubstitute(realSQL);
    try {
      add = db.getQueryFields(realSQL, false);
    } catch (KettleDatabaseException dbe) {
      throw new KettleStepException(
          Messages.getString("DynamicSQLRowMeta.Exception.UnableToDetermineQueryFields")
              + Const.CR
              + sql,
          dbe); //$NON-NLS-1$
    }

    if (add != null) // Cache hit, just return it this...
    {
      for (int i = 0; i < add.size(); i++) {
        ValueMetaInterface v = add.getValueMeta(i);
        v.setOrigin(name);
      }
      row.addRowMeta(add);
    } else

      // No cache hit, connect to the database, do it the hard way...
      try {
        db.connect();
        add = db.getQueryFields(realSQL, false);
        for (int i = 0; i < add.size(); i++) {
          ValueMetaInterface v = add.getValueMeta(i);
          v.setOrigin(name);
        }
        row.addRowMeta(add);
        db.disconnect();
      } catch (KettleDatabaseException dbe) {
        throw new KettleStepException(
            Messages.getString("DynamicSQLRowMeta.Exception.ErrorObtainingFields"),
            dbe); //$NON-NLS-1$
      }
  }
Esempio n. 2
0
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {

    // the folderName
    ValueMetaInterface folderName = new ValueMeta("folderName", ValueMeta.TYPE_STRING);
    folderName.setLength(500);
    folderName.setPrecision(-1);
    folderName.setOrigin(name);
    row.addValueMeta(folderName);

    // the short folderName
    ValueMetaInterface short_folderName = new ValueMeta("short_folderName", ValueMeta.TYPE_STRING);
    short_folderName.setLength(500);
    short_folderName.setPrecision(-1);
    short_folderName.setOrigin(name);
    row.addValueMeta(short_folderName);

    // the path
    ValueMetaInterface path = new ValueMeta("path", ValueMeta.TYPE_STRING);
    path.setLength(500);
    path.setPrecision(-1);
    path.setOrigin(name);
    row.addValueMeta(path);

    // the ishidden
    ValueMetaInterface ishidden = new ValueMeta("ishidden", ValueMeta.TYPE_BOOLEAN);
    ishidden.setOrigin(name);
    row.addValueMeta(ishidden);

    // the isreadable
    ValueMetaInterface isreadable = new ValueMeta("isreadable", ValueMeta.TYPE_BOOLEAN);
    isreadable.setOrigin(name);
    row.addValueMeta(isreadable);

    // the iswriteable
    ValueMetaInterface iswriteable = new ValueMeta("iswriteable", ValueMeta.TYPE_BOOLEAN);
    iswriteable.setOrigin(name);
    row.addValueMeta(iswriteable);

    // the lastmodifiedtime
    ValueMetaInterface lastmodifiedtime = new ValueMeta("lastmodifiedtime", ValueMeta.TYPE_DATE);
    lastmodifiedtime.setOrigin(name);
    row.addValueMeta(lastmodifiedtime);

    // the uri
    ValueMetaInterface uri = new ValueMeta("uri", ValueMeta.TYPE_STRING);
    uri.setOrigin(name);
    row.addValueMeta(uri);

    // the rooturi
    ValueMetaInterface rooturi = new ValueMeta("rooturi", ValueMeta.TYPE_STRING);
    rooturi.setOrigin(name);
    row.addValueMeta(rooturi);

    // childrens
    ValueMetaInterface childrens =
        new ValueMeta(space.environmentSubstitute("childrens"), ValueMeta.TYPE_INTEGER);
    childrens.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
    childrens.setOrigin(name);
    row.addValueMeta(childrens);

    if (includeRowNumber) {
      ValueMetaInterface v =
          new ValueMeta(space.environmentSubstitute(rowNumberField), ValueMeta.TYPE_INTEGER);
      v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
      v.setOrigin(name);
      row.addValueMeta(v);
    }
  }