當前位置: 首頁>>代碼示例>>Java>>正文


Java StepMetaInterface.getRequiredFields方法代碼示例

本文整理匯總了Java中org.pentaho.di.trans.step.StepMetaInterface.getRequiredFields方法的典型用法代碼示例。如果您正苦於以下問題:Java StepMetaInterface.getRequiredFields方法的具體用法?Java StepMetaInterface.getRequiredFields怎麽用?Java StepMetaInterface.getRequiredFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.pentaho.di.trans.step.StepMetaInterface的用法示例。


在下文中一共展示了StepMetaInterface.getRequiredFields方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateFieldMapping

import org.pentaho.di.trans.step.StepMetaInterface; //導入方法依賴的package包/類
/**
 * Create a new SelectValues step in between this step and the previous. If
 * the previous fields are not there, no mapping can be made, same with the
 * required fields.
 * 
 * @param stepMeta
 *            The target step to map against.
 */
@SuppressWarnings("deprecation") // retry of required fields acquisition
public void generateFieldMapping(TransMeta transMeta, StepMeta stepMeta) {
	try {
		if (stepMeta != null) {
			StepMetaInterface smi = stepMeta.getStepMetaInterface();
			RowMetaInterface targetFields = smi.getRequiredFields(transMeta);
			if (targetFields.isEmpty()) smi.getRequiredFields(); // retry, get rid of this method in 4.x
			RowMetaInterface sourceFields = transMeta.getPrevStepFields(stepMeta);

			// Build the mapping: let the user decide!!
			String[] source = sourceFields.getFieldNames();
			for (int i = 0; i < source.length; i++) {
				ValueMetaInterface v = sourceFields.getValueMeta(i);
				source[i] += EnterMappingDialog.STRING_ORIGIN_SEPARATOR + v.getOrigin() + ")";
			}
			String[] target = targetFields.getFieldNames();

			EnterMappingDialog dialog = new EnterMappingDialog(shell, source, target);
			List<SourceToTargetMapping> mappings = dialog.open();
			if (mappings != null) {
				// OK, so we now know which field maps where.
				// This allows us to generate the mapping using a
				// SelectValues Step...
				SelectValuesMeta svm = new SelectValuesMeta();
				svm.allocate(mappings.size(), 0, 0);

				for (int i = 0; i < mappings.size(); i++) {
					SourceToTargetMapping mapping = mappings.get(i);
					svm.getSelectName()[i] = sourceFields.getValueMeta(mapping.getSourcePosition()).getName();
					svm.getSelectRename()[i] = target[mapping.getTargetPosition()];
					svm.getSelectLength()[i] = -1;
					svm.getSelectPrecision()[i] = -1;
				}
				// a new comment
				// Now that we have the meta-data, create a new step info
				// object

				String stepName = stepMeta.getName() + " Mapping";
				stepName = transMeta.getAlternativeStepname(stepName); // if it's already there, rename it.

				StepMeta newStep = new StepMeta("SelectValues", stepName, svm);
				newStep.setLocation(stepMeta.getLocation().x + 20, stepMeta.getLocation().y + 20);
				newStep.setDraw(true);

				transMeta.addStep(newStep);
				addUndoNew(transMeta, new StepMeta[] { newStep }, new int[] { transMeta.indexOfStep(newStep) });

				// Redraw stuff...
				refreshTree();
				refreshGraph();
			}
		} else {
			throw new KettleException("There is no target to do a field mapping against!");
		}
	} catch (KettleException e) {
		new ErrorDialog(shell, "Error creating mapping", "There was an error when Kettle tried to generate a field mapping against the target step", e);
	}
}
 
開發者ID:icholy,項目名稱:geokettle-2.0,代碼行數:67,代碼來源:Spoon.java

示例2: generateFieldMapping

import org.pentaho.di.trans.step.StepMetaInterface; //導入方法依賴的package包/類
/**
 * Create a new SelectValues step in between this step and the previous. If
 * the previous fields are not there, no mapping can be made, same with the
 * required fields.
 * 
 * @param stepMeta
 *            The target step to map against.
 */
// retry of required fields acquisition
public void generateFieldMapping(TransMeta transMeta, StepMeta stepMeta) {
  try {
    if (stepMeta != null) {
      StepMetaInterface smi = stepMeta.getStepMetaInterface();
      RowMetaInterface targetFields = smi.getRequiredFields(transMeta);
      RowMetaInterface sourceFields = transMeta.getPrevStepFields(stepMeta);

      // Build the mapping: let the user decide!!
      String[] source = sourceFields.getFieldNames();
      for (int i = 0; i < source.length; i++) {
        ValueMetaInterface v = sourceFields.getValueMeta(i);
        source[i] += EnterMappingDialog.STRING_ORIGIN_SEPARATOR + v.getOrigin() + ")";
      }
      String[] target = targetFields.getFieldNames();

      EnterMappingDialog dialog = new EnterMappingDialog(shell, source, target);
      List<SourceToTargetMapping> mappings = dialog.open();
      if (mappings != null) {
        // OK, so we now know which field maps where.
        // This allows us to generate the mapping using a
        // SelectValues Step...
        SelectValuesMeta svm = new SelectValuesMeta();
        svm.allocate(mappings.size(), 0, 0);

        for (int i = 0; i < mappings.size(); i++) {
          SourceToTargetMapping mapping = mappings.get(i);
          svm.getSelectName()[i] = sourceFields.getValueMeta(mapping.getSourcePosition()).getName();
          svm.getSelectRename()[i] = target[mapping.getTargetPosition()];
          svm.getSelectLength()[i] = -1;
          svm.getSelectPrecision()[i] = -1;
        }
        // a new comment
        // Now that we have the meta-data, create a new step info
        // object

        String stepName = stepMeta.getName() + " Mapping";
        stepName = transMeta.getAlternativeStepname(stepName); // if
        // it's
        // already
        // there,
        // rename
        // it.

        StepMeta newStep = new StepMeta("SelectValues", stepName, svm);
        newStep.setLocation(stepMeta.getLocation().x + 20, stepMeta.getLocation().y + 20);
        newStep.setDraw(true);

        transMeta.addStep(newStep);
        addUndoNew(transMeta, new StepMeta[] { newStep }, new int[] { transMeta.indexOfStep(newStep) });

        // Redraw stuff...
        refreshTree();
        refreshGraph();
      }
    } else {
      throw new KettleException("There is no target to do a field mapping against!");
    }
  } catch (KettleException e) {
    new ErrorDialog(shell, "Error creating mapping",
        "There was an error when Kettle tried to generate a field mapping against the target step", e);
  }
}
 
開發者ID:yintaoxue,項目名稱:read-open-source-code,代碼行數:72,代碼來源:Spoon.java


注:本文中的org.pentaho.di.trans.step.StepMetaInterface.getRequiredFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。