Exemple #1
0
  /**
   * Performs the replace function.
   *
   * @param ctx query context
   * @return {@code null}
   * @throws QueryException query exception
   */
  private Item replace(final QueryContext ctx) throws QueryException {
    checkWrite(ctx);

    final Data data = data(0, ctx);
    final String path = path(1, ctx);
    final Item doc = checkItem(expr[2], ctx);

    // collect all old documents
    final Resources res = data.resources;
    final int pre = res.doc(path);
    if (pre != -1) {
      if (res.docs(path).size() != 1) DOCTRGMULT.thrw(input);
      ctx.updates.add(new DeleteNode(pre, data, input), ctx);
    }
    // delete binary resources
    final IOFile bin = data.meta.binary(path);
    if (bin != null) ctx.updates.add(new DBDelete(data, path, input), ctx);
    ctx.updates.add(new DBAdd(data, input, doc, path, ctx.context), ctx);

    final IOFile file = data.meta.binary(path);
    if (file != null && file.exists() && !file.isDir()) {
      final Item it = checkItem(doc, ctx);
      ctx.updates.add(new DBStore(data, token(path), it, input), ctx);
    }
    return null;
  }
Exemple #2
0
  /**
   * Performs the optimize function.
   *
   * @param ctx query context
   * @return {@code null}
   * @throws QueryException query exception
   */
  private Item optimize(final QueryContext ctx) throws QueryException {
    checkWrite(ctx);

    final Data data = data(0, ctx);
    final boolean all = expr.length == 2 && checkBln(expr[1], ctx);
    ctx.updates.add(new DBOptimize(data, ctx.context, all, input), ctx);
    return null;
  }
Exemple #3
0
  /**
   * Performs the add function.
   *
   * @param ctx query context
   * @return {@code null}
   * @throws QueryException query exception
   */
  private Item add(final QueryContext ctx) throws QueryException {
    checkWrite(ctx);

    final Data data = data(0, ctx);
    final Item it = checkItem(expr[1], ctx);
    final String path = expr.length < 3 ? "" : path(2, ctx);

    ctx.updates.add(new DBAdd(data, input, it, path, ctx.context), ctx);
    return null;
  }
Exemple #4
0
  /**
   * Performs the store function.
   *
   * @param ctx query context
   * @return {@code null}
   * @throws QueryException query exception
   */
  private Item store(final QueryContext ctx) throws QueryException {
    checkWrite(ctx);

    final Data data = data(0, ctx);
    final String path = path(1, ctx);
    final IOFile file = data.meta.binary(path);
    if (file == null || file.isDir()) RESINV.thrw(input, path);

    final Item it = checkItem(expr[2], ctx);
    ctx.updates.add(new DBStore(data, token(path), it, input), ctx);
    return null;
  }
Exemple #5
0
  /**
   * Performs the delete function.
   *
   * @param ctx query context
   * @return {@code null}
   * @throws QueryException query exception
   */
  private Item delete(final QueryContext ctx) throws QueryException {
    checkWrite(ctx);

    final Data data = data(0, ctx);
    final String path = path(1, ctx);

    // delete XML resources
    final IntList docs = data.resources.docs(path);
    for (int i = 0, is = docs.size(); i < is; i++) {
      ctx.updates.add(new DeleteNode(docs.get(i), data, input), ctx);
    }
    // delete raw resources
    final IOFile bin = data.meta.binary(path);
    if (bin == null) UPDBDELERR.thrw(input, path);
    ctx.updates.add(new DBDelete(data, path, input), ctx);
    return null;
  }
Exemple #6
0
  /**
   * Performs the rename function.
   *
   * @param ctx query context
   * @return {@code null}
   * @throws QueryException query exception
   */
  private Item rename(final QueryContext ctx) throws QueryException {
    checkWrite(ctx);

    final Data data = data(0, ctx);
    final String source = path(1, ctx);
    final String target = path(2, ctx);

    // the first step of the path should be the database name
    final IntList il = data.resources.docs(source);
    for (int i = 0, is = il.size(); i < is; i++) {
      final int pre = il.get(i);
      final String trg = Rename.target(data, pre, source, target);
      if (trg.isEmpty()) EMPTYPATH.thrw(input, this);
      ctx.updates.add(new ReplaceValue(pre, data, input, token(trg)), ctx);
    }
    // rename files
    final IOFile src = data.meta.binary(source);
    final IOFile trg = data.meta.binary(target);
    if (src == null || trg == null) UPDBRENAMEERR.thrw(input, src);

    ctx.updates.add(new DBRename(data, src.path(), trg.path(), input), ctx);
    return null;
  }