Esempio n. 1
0
  private void createIteration() throws QueryEvaluationException {

    if (currentLength == 0L) {
      ZeroLengthPath zlp = new ZeroLengthPath(scope, startVar, endVar, contextVar);
      currentIter = this.evaluationStrategyImpl.evaluate(zlp, bindings);
      currentLength++;
    } else if (currentLength == 1) {
      TupleExpr pathExprClone = pathExpression.clone();

      if (startVarFixed && endVarFixed) {
        Var replacement =
            createAnonVar(JOINVAR_PREFIX + currentLength + "-" + pathExpression.hashCode());

        VarReplacer replacer = new VarReplacer(endVar, replacement, 0, false);
        pathExprClone.visit(replacer);
      }
      currentIter = this.evaluationStrategyImpl.evaluate(pathExprClone, bindings);
      currentLength++;
    } else {

      currentVp = valueQueue.poll();

      if (currentVp != null) {

        TupleExpr pathExprClone = pathExpression.clone();

        if (startVarFixed && endVarFixed) {

          Var startReplacement =
              createAnonVar(JOINVAR_PREFIX + currentLength + "-" + pathExpression.hashCode());
          Var endReplacement = createAnonVar("END_" + JOINVAR_PREFIX + pathExpression.hashCode());
          startReplacement.setAnonymous(false);
          endReplacement.setAnonymous(false);

          Value v = currentVp.getEndValue();
          startReplacement.setValue(v);

          VarReplacer replacer = new VarReplacer(startVar, startReplacement, 0, false);
          pathExprClone.visit(replacer);

          replacer = new VarReplacer(endVar, endReplacement, 0, false);
          pathExprClone.visit(replacer);
        } else {
          Var toBeReplaced;
          Value v;
          if (!endVarFixed) {
            toBeReplaced = startVar;
            v = currentVp.getEndValue();
          } else {
            toBeReplaced = endVar;
            v = currentVp.getStartValue();
          }

          Var replacement =
              createAnonVar(JOINVAR_PREFIX + currentLength + "-" + pathExpression.hashCode());
          replacement.setValue(v);

          VarReplacer replacer = new VarReplacer(toBeReplaced, replacement, 0, false);
          pathExprClone.visit(replacer);
        }

        currentIter = this.evaluationStrategyImpl.evaluate(pathExprClone, bindings);
      } else {
        currentIter = new EmptyIteration<BindingSet, QueryEvaluationException>();
      }
      currentLength++;
    }
  }