Exemplo n.º 1
0
    @Override
    public TempTable process(TempTable tempTable)
        throws TeiidComponentException, TeiidProcessingException {
      if (initial) {
        // process initial plan
        if (working == null) {
          working = tempTable.clone();
          intermediate = tempTable.clone();
        }
        processPlan(tempTable, working);
        initial = false;
      }

      // continue to build the result
      while (working.getRowCount() > 0) {
        if (building) {
          return working;
        }
        building = true;
        try {
          if (workingQp == null) {
            recursive.reset();
            workingQp =
                new QueryProcessor(
                    recursive,
                    this.queryProcessor.getContext(),
                    this.queryProcessor.getBufferManager(),
                    this.queryProcessor.getProcessorDataManager());
            this.iterator = new BatchProducerTupleSource(workingQp);
          }
          processPlan(tempTable, intermediate);
          iterations++;
          if (maxIterations > 0 && iterations > maxIterations) {
            throw new TeiidProcessingException(
                QueryPlugin.Event.TEIID31158,
                QueryPlugin.Util.gs(
                    QueryPlugin.Event.TEIID31158,
                    maxIterations,
                    tempTable.getMetadataId().getName()));
          }
          this.workingQp.closeProcessing();
          this.workingQp = null;
          // swap the intermediate to be the working
          working.truncate(true);
          TempTable temp = working;
          working = intermediate;
          intermediate = temp;
        } finally {
          building = false;
        }
      }
      // we truncate rater than remove because we are cloned off of the original
      this.working.truncate(true);
      this.intermediate.truncate(true);
      tempTable.setUpdatable(false);
      return tempTable;
    }