use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.
the class ProcedurePlan method createVariableContext.
private void createVariableContext() {
this.currentVarContext = new VariableContext(runInContext && this.params == null);
this.currentVarContext.setValue(ROWCOUNT, 0);
this.cursorStates = new VariableContext(false);
this.cursorStates.setValue(null, null);
}
use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.
the class ProcedurePlan method nextBatchDirect.
/**
* @see ProcessorPlan#nextBatch()
*/
public TupleBatch nextBatchDirect() throws TeiidComponentException, TeiidProcessingException, BlockedException {
// Already returned results?
if (done) {
// Already returned all results
TupleBatch emptyTerminationBatch = new TupleBatch(beginBatch, new List[0]);
emptyTerminationBatch.setTerminationFlag(true);
return emptyTerminationBatch;
}
// First attempt to process
if (this.finalTupleSource == null) {
// Still need to process - this should either
// throw a BlockedException or return a finalTupleSource
this.finalTupleSource = processProcedure();
}
// Next, attempt to return batches if processing completed
while (!isBatchFull()) {
// May throw BlockedException and exit here
List<?> tuple = this.finalTupleSource.nextTuple();
if (tuple == null) {
if (outParams != null) {
VariableContext vc = getCurrentVariableContext();
List<Object> paramTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
int i = this.getOutputElements().size() - this.outParams.size();
for (ElementSymbol param : outParams) {
Object value = vc.getValue(param);
checkNotNull(param, value);
paramTuple.set(i++, value);
}
addBatchRow(paramTuple, true);
}
terminateBatches();
done = true;
break;
}
addBatchRow(tuple, false);
}
return pullBatch();
}
use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.
the class ProcedurePlan method open.
public void open() throws TeiidProcessingException, TeiidComponentException {
if (!this.evaluatedParams) {
if (this.outParams != null) {
for (ElementSymbol param : this.outParams) {
setParameterValue(param, getCurrentVariableContext(), null);
}
}
if (this.params != null) {
for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet()) {
ElementSymbol param = entry.getKey();
Expression expr = entry.getValue();
VariableContext context = getCurrentVariableContext();
if (context.getVariableMap().containsKey(param)) {
continue;
}
Object value = this.evaluateExpression(expr);
// check constraint
checkNotNull(param, value);
setParameterValue(param, context, value);
}
this.evaluator.close();
} else if (runInContext) {
// if there are no params, this needs to run in the current variable context
this.currentVarContext.setParentContext(parentContext);
}
this.push(originalProgram);
}
this.evaluatedParams = true;
}
use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.
the class BatchedUpdatePlan method initialize.
/**
* @see org.teiid.query.processor.ProcessorPlan#initialize(org.teiid.query.util.CommandContext, org.teiid.query.processor.ProcessorDataManager, org.teiid.common.buffer.BufferManager)
* @since 4.2
*/
public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) {
context = context.clone();
// start a new root variable context
context.setVariableContext(new VariableContext());
this.setContext(context);
// Initialize all the child plans
for (int i = 0; i < getPlanCount(); i++) {
updatePlans[i].initialize(context, dataMgr, bufferMgr);
}
}
use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.
the class BatchedUpdatePlan method openPlan.
private void openPlan() throws TeiidComponentException, TeiidProcessingException {
// reset prior to updating the context
updatePlans[planIndex].reset();
if (this.contexts != null && !this.contexts.isEmpty()) {
CommandContext context = updatePlans[planIndex].getContext();
VariableContext vc = context.getVariableContext();
// this is just a safe guard against the plan not correctly resetting the context
while (vc.getParentContext() != null) {
vc = vc.getParentContext();
}
vc.clear();
VariableContext currentValues = this.contexts.get(planIndex);
vc.putAll(currentValues);
}
TransactionContext tc = this.getContext().getTransactionContext();
if (startTxn[planIndex] && tc != null && tc.getTransactionType() == Scope.NONE) {
this.getContext().getTransactionServer().begin(tc);
this.planContexts[planIndex] = tc;
}
updatePlans[planIndex].open();
planOpened[planIndex] = true;
}
Aggregations