本文整理汇总了Java中org.pentaho.di.core.SourceToTargetMapping.getTargetPosition方法的典型用法代码示例。如果您正苦于以下问题:Java SourceToTargetMapping.getTargetPosition方法的具体用法?Java SourceToTargetMapping.getTargetPosition怎么用?Java SourceToTargetMapping.getTargetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pentaho.di.core.SourceToTargetMapping
的用法示例。
在下文中一共展示了SourceToTargetMapping.getTargetPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateFieldMapping
import org.pentaho.di.core.SourceToTargetMapping; //导入方法依赖的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);
}
}
示例2: generateFieldMapping
import org.pentaho.di.core.SourceToTargetMapping; //导入方法依赖的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);
}
}