use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class AbstractMetaTest method testGetSetParentVariableSpace.
@Test
public void testGetSetParentVariableSpace() throws Exception {
assertNull(meta.getParentVariableSpace());
VariableSpace variableSpace = mock(VariableSpace.class);
meta.setParentVariableSpace(variableSpace);
assertEquals(variableSpace, meta.getParentVariableSpace());
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class SetVariable method setValue.
private void setValue(Object[] rowData, int i, boolean usedefault) throws KettleException {
// Set the appropriate environment variable
//
String value = null;
if (usedefault) {
value = environmentSubstitute(meta.getDefaultValue()[i]);
} else {
int index = data.outputMeta.indexOfValue(meta.getFieldName()[i]);
if (index < 0) {
throw new KettleException("Unable to find field [" + meta.getFieldName()[i] + "] in input row");
}
ValueMetaInterface valueMeta = data.outputMeta.getValueMeta(index);
Object valueData = rowData[index];
//
if (meta.isUsingFormatting()) {
value = valueMeta.getString(valueData);
} else {
value = valueMeta.getCompatibleString(valueData);
}
}
if (value == null) {
value = "";
}
// Get variable name
String varname = meta.getVariableName()[i];
if (Utils.isEmpty(varname)) {
if (Utils.isEmpty(value)) {
throw new KettleException("Variable name nor value was specified on line #" + (i + 1));
} else {
throw new KettleException("There was no variable name specified for value [" + value + "]");
}
}
Job parentJob = null;
// We always set the variable in this step and in the parent transformation...
//
setVariable(varname, value);
// Set variable in the transformation
//
Trans trans = getTrans();
trans.setVariable(varname, value);
//
while (trans.getParentTrans() != null) {
trans = trans.getParentTrans();
trans.setVariable(varname, value);
}
//
switch(meta.getVariableType()[i]) {
case SetVariableMeta.VARIABLE_TYPE_JVM:
System.setProperty(varname, value);
parentJob = trans.getParentJob();
while (parentJob != null) {
parentJob.setVariable(varname, value);
parentJob = parentJob.getParentJob();
}
break;
case SetVariableMeta.VARIABLE_TYPE_ROOT_JOB:
// Comments by SB
// VariableSpace rootJob = null;
parentJob = trans.getParentJob();
while (parentJob != null) {
parentJob.setVariable(varname, value);
// rootJob = parentJob;
parentJob = parentJob.getParentJob();
}
break;
case SetVariableMeta.VARIABLE_TYPE_GRAND_PARENT_JOB:
// Set the variable in the parent job
//
parentJob = trans.getParentJob();
if (parentJob != null) {
parentJob.setVariable(varname, value);
} else {
throw new KettleStepException("Can't set variable [" + varname + "] on parent job: the parent job is not available");
}
// Set the variable on the grand-parent job
//
VariableSpace gpJob = trans.getParentJob().getParentJob();
if (gpJob != null) {
gpJob.setVariable(varname, value);
} else {
throw new KettleStepException("Can't set variable [" + varname + "] on grand parent job: the grand parent job is not available");
}
break;
case SetVariableMeta.VARIABLE_TYPE_PARENT_JOB:
// Set the variable in the parent job
//
parentJob = trans.getParentJob();
if (parentJob != null) {
parentJob.setVariable(varname, value);
} else {
throw new KettleStepException("Can't set variable [" + varname + "] on parent job: the parent job is not available");
}
break;
default:
break;
}
logBasic(BaseMessages.getString(PKG, "SetVariable.Log.SetVariableToValue", meta.getVariableName()[i], value));
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class ScriptValuesAddedFunctions method setParentScopeVariable.
static void setParentScopeVariable(Trans trans, String variableName, String variableValue) {
trans.setVariable(variableName, variableValue);
VariableSpace parentSpace = trans.getParentVariableSpace();
if (parentSpace != null) {
parentSpace.setVariable(variableName, variableValue);
}
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class ScriptValuesAddedFunctions method setRootScopeVariable.
static void setRootScopeVariable(Trans trans, String variableName, String variableValue) {
trans.setVariable(variableName, variableValue);
VariableSpace parentSpace = trans.getParentVariableSpace();
while (parentSpace != null) {
parentSpace.setVariable(variableName, variableValue);
parentSpace = parentSpace.getParentVariableSpace();
}
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class ScriptValuesAddedFunctions method setGrandParentScopeVariable.
static void setGrandParentScopeVariable(Trans trans, String variableName, String variableValue) {
trans.setVariable(variableName, variableValue);
VariableSpace parentSpace = trans.getParentVariableSpace();
if (parentSpace != null) {
parentSpace.setVariable(variableName, variableValue);
VariableSpace grandParentSpace = parentSpace.getParentVariableSpace();
if (grandParentSpace != null) {
grandParentSpace.setVariable(variableName, variableValue);
}
}
}
Aggregations