Ejemplo 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$
      }
  }
Ejemplo n.º 2
0
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String[] input,
      String[] output,
      RowMetaInterface info)
      throws KettleStepException {

    RowMetaInterface out = prev.clone();
    getFields(
        out,
        stepMeta.getName(),
        new RowMetaInterface[] {
          info,
        },
        null,
        transMeta);
    if (out != null) {
      for (int i = 0; i < out.size(); i++) {
        ValueMetaInterface outvalue = out.getValueMeta(i);
        DatabaseImpact di =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_READ,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                "", //$NON-NLS-1$
                outvalue.getName(),
                outvalue.getName(),
                stepMeta.getName(),
                sql,
                Messages.getString("DynamicSQLRowMeta.DatabaseImpact.Title") // $NON-NLS-1$
                );
        impact.add(di);
      }
    }
  }