コード例 #1
0
ファイル: Transform.java プロジェクト: nikhi/basex
  @Override
  public Value value(final QueryContext ctx) throws QueryException {
    final int o = (int) ctx.resources.output.size();
    final Updates updates = ctx.resources.updates();
    final ContextModifier tmp = updates.mod;
    final TransformModifier pu = new TransformModifier();
    updates.mod = pu;

    try {
      for (final Let fo : copies) {
        final Iter ir = ctx.iter(fo.expr);
        Item i = ir.next();
        if (!(i instanceof ANode) || ir.next() != null) throw UPCOPYMULT.get(fo.info, fo.var.name);

        // copy node to main memory data instance
        i = ((ANode) i).dbCopy(ctx.context.options);
        // add resulting node to variable
        ctx.set(fo.var, i, info);
        pu.addData(i.data());
      }
      final Value v = ctx.value(expr[0]);
      if (!v.isEmpty()) throw BASEX_MOD.get(info);

      updates.prepare();
      updates.apply();
      return ctx.value(expr[1]);
    } finally {
      ctx.resources.output.size(o);
      updates.mod = tmp;
    }
  }
コード例 #2
0
ファイル: Preds.java プロジェクト: dirkk/basex
  /**
   * Checks if the predicates are successful for the specified item.
   *
   * @param it item to be checked
   * @param qc query context
   * @return result of check
   * @throws QueryException query exception
   */
  protected final boolean preds(final Item it, final QueryContext qc) throws QueryException {
    if (preds.length == 0) return true;

    // set context value and position
    final Value cv = qc.value;
    try {
      if (qc.scoring) {
        double s = 0;
        for (final Expr p : preds) {
          qc.value = it;
          final Item i = p.test(qc, info);
          if (i == null) return false;
          s += i.score();
        }
        it.score(Scoring.avg(s, preds.length));
      } else {
        for (final Expr p : preds) {
          qc.value = it;
          if (p.test(qc, info) == null) return false;
        }
      }
      return true;
    } finally {
      qc.value = cv;
    }
  }
コード例 #3
0
ファイル: GroupBy.java プロジェクト: LeoWoerteler/basex
  /**
   * Checks two keys for equality.
   *
   * @param its1 first keys
   * @param its2 second keys
   * @param coll collations
   * @return {@code true} if the compare as equal, {@code false} otherwise
   * @throws QueryException query exception
   */
  private boolean eq(final Item[] its1, final Item[] its2, final Collation[] coll)
      throws QueryException {

    final int il = its1.length;
    for (int i = 0; i < il; i++) {
      final Item it1 = its1[i], it2 = its2[i];
      if (it1 == null ^ it2 == null || it1 != null && !it1.equiv(it2, coll[i], info)) return false;
    }
    return true;
  }
コード例 #4
0
ファイル: FNUnit.java プロジェクト: nikhi/basex
 /**
  * Performs the assert-equals function.
  *
  * @param ctx query context
  * @return resulting value
  * @throws QueryException query exception
  */
 private Item assertEquals(final QueryContext ctx) throws QueryException {
   final byte[] str = expr.length < 3 ? null : checkStr(expr[2], ctx);
   final Iter iter1 = ctx.iter(expr[0]), iter2 = ctx.iter(expr[1]);
   final Compare comp = new Compare(info);
   Item it1, it2;
   int c = 1;
   while (true) {
     it1 = iter1.next();
     it2 = iter2.next();
     final boolean empty1 = it1 == null, empty2 = it2 == null;
     if (empty1 && empty2) return null;
     if (empty1 || empty2 || !comp.deep(it1.iter(), it2.iter())) break;
     c++;
   }
   if (str != null) throw UNIT_MESSAGE.get(info, str);
   throw new UnitException(info, UNIT_ASSERT_EQUALS, it1, it2, c);
 }
コード例 #5
0
ファイル: Or.java プロジェクト: vincentml/basex
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    // compute scoring
    if (qc.scoring) {
      double s = 0;
      boolean f = false;
      for (final Expr expr : exprs) {
        final Item it = expr.ebv(qc, info);
        f |= it.bool(ii);
        s += it.score();
      }
      return Bln.get(f, Scoring.avg(s, exprs.length));
    }

    // standard evaluation
    for (final Expr expr : exprs) {
      if (expr.ebv(qc, info).bool(ii)) return Bln.TRUE;
    }
    return Bln.FALSE;
  }