public ProcessorPlan clone(){ ProcedurePlan plan = new ProcedurePlan(originalProgram.clone()); plan.setOutputElements(this.getOutputElements()); plan.setParams(params); plan.setOutParams(outParams); plan.setMetadata(metadata); plan.updateCount = updateCount; plan.runInContext = runInContext; return plan; }
this.finalTupleSource = processProcedure(); while(! isBatchFull()) { 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, metadata); paramTuple.set(i++, value); addBatchRow(paramTuple, true); terminateBatches(); done = true; break; addBatchRow(tuple, false); return pullBatch();
/** * Constructor for ProcedurePlan. */ public ProcedurePlan(Program originalProgram) { this.originalProgram = originalProgram; createVariableContext(); }
public boolean testCondition(ProcedurePlan procEnv) throws TeiidComponentException, TeiidProcessingException { if(!procEnv.resultSetExists(rsName)) { procEnv.executePlan(plan, rsName, null, Mode.NOHOLD, false); } return procEnv.iterateCursor(rsName); }
if (this.outParams != null) { for (ElementSymbol param : this.outParams) { setParameterValue(param, getCurrentVariableContext(), null); Expression expr = entry.getValue(); VariableContext context = getCurrentVariableContext(); if (context.getVariableMap().containsKey(param)) { continue; Object value = this.evaluateExpression(expr); checkNotNull(param, value); setParameterValue(param, context, value); this.push(originalProgram);
VariableContext localContext = procEnv.getCurrentVariableContext(); Clob value = (Clob)procEnv.evaluateExpression(dynamicCommand.getSql()); command = QueryRewriter.rewrite(command, metadata, procEnv.getContext(), command instanceof CreateProcedureCommand?Collections.EMPTY_MAP:nameValueMap); idGenerator, capFinder, AnalysisRecord .createNonRecordingRecord(), procEnv .getContext()); ((ProcedurePlan)commandPlan).setValidateAccess(procEnv.isValidateAccess()); if (!procEnv.getTempTableStore().hasTempTable(groupName, true)) { procEnv.getDataManager().registerRequest(procEnv.getContext(), create, TempMetadataAdapter.TEMP_MODEL.getName(), new RegisterRequestParameter()); insert.addValue(new Constant(procEnv.getCurrentVariableContext().getValue(ProcedurePlan.ROWCOUNT))); QueryResolver.resolveCommand(insert, metadata.getDesignTimeMetadata()); TupleSource ts = procEnv.getDataManager().registerRequest(procEnv.getContext(), insert, TempMetadataAdapter.TEMP_MODEL.getName(), new RegisterRequestParameter()); ts.nextTuple(); ts.closeSource(); procEnv.getContext().pushCall(Command.getCommandToken(parentProcCommand.getUpdateType()) + " " + parentProcCommand.getVirtualGroup()); //$NON-NLS-1$ } else { if (parentProcCommand.getVirtualGroup() != null) { procEnv.getContext().pushCall(parentProcCommand.getVirtualGroup().toString()); procEnv.push(dynamicProgram);
Program program = peek(); inst = program.getCurrentInstruction(); if (inst == null){ if(last != null){ if (last.resultsBuffer == null && (last.usesLocalTemp || !txnTupleSources.isEmpty())) { last.resultsBuffer = bufferMgr.createTupleBuffer(last.processor.getOutputElements(), getContext().getConnectionId(), TupleSourceType.PROCESSOR); last.returning = true; this.pop(true); continue; getContext().setCurrentTimestamp(System.currentTimeMillis()); if (inst instanceof RepeatedInstruction) { LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Executing repeated instruction", inst); //$NON-NLS-1$ LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Passed condition, executing program " + loop.getNestedProgram()); //$NON-NLS-1$ inst.process(this); this.push(loop.getNestedProgram()); continue; this.pop(false); if (this.programs.empty()) { program = peek(); atomic |= program.isAtomic(); this.pop(false); //allow the current program to go out of scope if (atomic) {
TransactionContext tc = this.getContext().getTransactionContext(); if (this.planContext == null && tc != null && tc.getTransactionType() == Scope.NONE) { Boolean txnRequired = rowProcedure.requiresTransaction(false); boolean start = false; if (txnRequired == null) { rowProcedure.reset(); CommandContext context = getContext().clone(); this.rowProcessor = new QueryProcessor(rowProcedure, context, this.bufferMgr, this.dataMgr); Integer index = this.lookupMap.get(entry.getValue()); if (index != null) { rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), this.currentTuple.get(index)); } else { rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), eval.evaluate(entry.getValue(), this.currentTuple));
ProcedurePlan plan = new ProcedurePlan(programBlock); plan.setMetadata(metadata); plan.setOutputElements(cupc.getProjectedSymbols());
@Override public void process(ProcedurePlan env) throws TeiidComponentException, TeiidProcessingException, TeiidSQLException { Object value = env.evaluateExpression(expression); LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Processing RAISE with the value :", value); //$NON-NLS-1$ if (warning) { env.getContext().addWarning((Exception)value); return; } if (value == null) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID31122, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31122)); } throw TeiidSQLException.create((Exception)value); }
/** * <p> Updates the current variable context with a value for the Variable * defined using a DeclareInstruction, the variable value is obtained by either processing * a expression or a command(stored as a processplan). The Processing of the command is * expected to result in 1 column, 1 row tuple, if more than a row is returned an exception * is thrown. Also updates the program counter.</p> * @throws BlockedException * @throws TeiidComponentException if error processing command or expression on this instruction */ public void process(ProcedurePlan procEnv) throws BlockedException, TeiidComponentException, TeiidProcessingException { VariableContext varContext = procEnv.getCurrentVariableContext(); Object value = null; if (this.expression != null) { value = procEnv.evaluateExpression(this.expression); } varContext.setValue(getVariable(), value); LogManager.logTrace(LogConstants.CTX_DQP, new Object[] {this.toString() + " The variable " //$NON-NLS-1$ + getVariable() + " in the variablecontext is updated with the value :", value}); //$NON-NLS-1$ }
/** * This instruction will evaluate it's criteria, if it evaluates * to true, it will push the corresponding sub Program on to the top of the * program stack, and break from the loop. Regardless if whether any criteria * evaluate to true, this instruction will increment the program counter of the * current program. * @throws TeiidProcessingException * @see ProgramInstruction#process(ProcedurePlan) */ public void process(ProcedurePlan procEnv) throws BlockedException, TeiidComponentException, TeiidProcessingException { boolean evalValue = procEnv.evaluateCriteria(condition); if(evalValue) { LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[]{"IFInstruction: "+ //$NON-NLS-1$ " The criteria on the if block evaluated to true, processing the if block"}); //$NON-NLS-1$ //push the "if" Program onto the stack procEnv.push(ifProgram); } else if(elseProgram != null) { LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[]{"IFInstruction: "+ //$NON-NLS-1$ " The criteria on the if block evaluated to false, processing the else block"}); //$NON-NLS-1$ //push the "else" Program onto the stack procEnv.push(elseProgram); } }
public void reset() { super.reset(); if (evaluator != null) { evaluator.reset(); } evaluatedParams = false; if (parentContext != null) { super.getContext().setVariableContext(parentContext); } createVariableContext(); CommandContext cc = super.getContext(); if (cc != null) { //create fresh local state setContext(cc.clone()); } done = false; currentState = null; finalTupleSource = null; beginBatch = 1; batchRows = null; lastBatch = false; //reset program stack programs.clear(); LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "ProcedurePlan reset"); //$NON-NLS-1$ }
@Override public Boolean requiresTransaction(boolean transactionalReads) { Boolean requiresTxn = queryPlan.requiresTransaction(transactionalReads); if (!Boolean.FALSE.equals(requiresTxn)) { return true; } Boolean forEach = rowProcedure.requiresTransaction(transactionalReads); if (Boolean.TRUE.equals(forEach)) { return true; } if (forEach == null) { if (!singleRow) { return true; } return null; } return false; }
/** * @throws TeiidProcessingException */ public boolean testCondition(ProcedurePlan procEnv) throws TeiidComponentException, TeiidProcessingException { return procEnv.evaluateCriteria(condition); }
@Override public ProcessorPlan clone() { ForEachRowPlan clone = new ForEachRowPlan(); clone.setQueryPlan(queryPlan.clone()); clone.setRowProcedure((ProcedurePlan) rowProcedure.clone()); clone.setParams(params); clone.setLookupMap(lookupMap); return clone; }
public void process(ProcedurePlan procEnv) throws BlockedException, TeiidComponentException, TeiidProcessingException { procEnv.executePlan(plan, rsName, procAssignments, mode, usesLocalTemp); }
/** * @param procEnv * @param localContext * @throws TeiidComponentException * @throws TeiidComponentException * @throws TeiidProcessingException */ private void updateContextWithUsingValues(ProcedurePlan procEnv, VariableContext localContext) throws TeiidComponentException, TeiidProcessingException { if (dynamicCommand.getUsing() != null && !dynamicCommand.getUsing().isEmpty()) { for (SetClause setClause : dynamicCommand.getUsing().getClauses()) { Object assignment = procEnv.evaluateExpression(setClause.getValue()); LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[] { this, " The using variable ", //$NON-NLS-1$ setClause.getSymbol(), " has value :", assignment }); //$NON-NLS-1$ localContext.setValue(setClause.getSymbol(), assignment); ElementSymbol es = setClause.getSymbol().clone(); es.getGroupSymbol().setShortName(Reserved.USING); localContext.setValue(es, assignment); } } }
StoredProcedure proc = (StoredProcedure)command; for (SPParameter param : proc.getInputParameters()) { ProcedurePlan.checkNotNull(param.getParameterSymbol(), ((Constant)param.getExpression()).getValue(), context.getMetadata());
VariableContext localContext = procEnv.getCurrentVariableContext(); Clob value = (Clob)procEnv.evaluateExpression(dynamicCommand.getSql()); command = QueryRewriter.rewrite(command, metadata, procEnv.getContext(), command instanceof CreateProcedureCommand?Collections.EMPTY_MAP:nameValueMap); idGenerator, capFinder, AnalysisRecord .createNonRecordingRecord(), procEnv .getContext()); ((ProcedurePlan)commandPlan).setValidateAccess(procEnv.isValidateAccess()); if (!procEnv.getTempTableStore().hasTempTable(groupName, true)) { procEnv.getDataManager().registerRequest(procEnv.getContext(), create, TempMetadataAdapter.TEMP_MODEL.getName(), new RegisterRequestParameter()); insert.addValue(new Constant(procEnv.getCurrentVariableContext().getValue(ProcedurePlan.ROWCOUNT))); QueryResolver.resolveCommand(insert, metadata.getDesignTimeMetadata()); TupleSource ts = procEnv.getDataManager().registerRequest(procEnv.getContext(), insert, TempMetadataAdapter.TEMP_MODEL.getName(), new RegisterRequestParameter()); ts.nextTuple(); ts.closeSource(); procEnv.getContext().pushCall(Command.getCommandToken(parentProcCommand.getUpdateType()) + " " + parentProcCommand.getVirtualGroup()); //$NON-NLS-1$ } else { if (parentProcCommand.getVirtualGroup() != null) { procEnv.getContext().pushCall(parentProcCommand.getVirtualGroup().toString()); procEnv.push(dynamicProgram);