Ejemplo n.º 1
0
  public void push(Program program) throws XATransactionException {
    this.evaluator.close();
    program.reset(this.getContext().getConnectionId());
    program.setTrappingExceptions(
        program.getExceptionGroup() != null
            || (!this.programs.isEmpty() && this.programs.peek().isTrappingExceptions()));
    TempTableStore tts = getTempTableStore();
    getContext().setTempTableStore(program.getTempTableStore());
    program.getTempTableStore().setParentTempTableStore(tts);
    this.programs.push(program);
    VariableContext context = new VariableContext(true);
    context.setParentContext(this.currentVarContext);
    this.currentVarContext = context;
    VariableContext cc = new VariableContext(true);
    cc.setParentContext(this.cursorStates);
    this.cursorStates = cc;

    if (program.isAtomic() && this.blockContext == null) {
      TransactionContext tc = this.getContext().getTransactionContext();
      if (tc != null && tc.getTransactionType() == Scope.NONE) {
        // start a transaction
        this.getContext().getTransactionServer().begin(tc);
        this.blockContext = tc;
        program.setStartedTxn(true);
      }
    }
  }
Ejemplo n.º 2
0
  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;
  }
Ejemplo n.º 3
0
 public void process(ProcedurePlan procEnv) throws TeiidComponentException {
   List<?> currentRow = procEnv.getCurrentRow(rsName);
   VariableContext varContext = procEnv.getCurrentVariableContext();
   // set results to the variable context(the cursor.element is treated as variable)
   if (this.elements == null) {
     List schema = procEnv.getSchema(rsName);
     elements = new ArrayList<ElementSymbol>(schema.size());
     for (int i = 0; i < schema.size(); i++) {
       Expression element = (Expression) schema.get(i);
       ElementSymbol e =
           new ElementSymbol(rsName + Symbol.SEPARATOR + Symbol.getShortName(element));
       e.setType(element.getType());
       elements.add(e);
     }
   }
   for (int i = 0; i < elements.size(); i++) {
     varContext.setValue(elements.get(i), currentRow.get(i));
   }
 }
Ejemplo n.º 4
0
  /** @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();
  }
Ejemplo n.º 5
0
 private void removeAllCursors(VariableContext cs) {
   for (Map.Entry<Object, Object> entry : cs.getVariableMap().entrySet()) {
     removeState((CursorState) entry.getValue());
   }
 }
Ejemplo n.º 6
0
 protected void setParameterValue(ElementSymbol param, VariableContext context, Object value) {
   context.setValue(param, value);
 }