Exemple #1
0
  public void apply() throws QueryException {
    // See XQuery Update Facility 1.0: 3.2.2 upd:applyUpdates
    // First all ops are sorted according to the order of their
    // application which is determined by their type.
    // The resulting list is then checked if some ops
    // are performed twice or more on the same target node
    Comparator<UpdateOp> orderByType =
        new Comparator<UpdateOp>() {
          @Override
          public int compare(UpdateOp o1, UpdateOp o2) {
            return o1.getType().compareTo(o2.getType());
          }
        };
    Collections.sort(ops, orderByType);

    for (int i = 0; i < ops.size(); i++) {
      final UpdateOp op1 = ops.get(i);
      if (checkOps.contains(op1.getType())) {
        for (int j = i + 1; j < ops.size(); j++) {
          final UpdateOp op2 = ops.get(j);

          if (op2.getType() != op1.getType()) {
            break;
          }
          checkCompatibility(op1, op2);
        }
      }
    }

    // finally apply all updates
    for (final UpdateOp op : ops) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("Applying pending update %s", op));
      }
      op.apply();
    }
  }
Exemple #2
0
 private void checkCompatibility(final UpdateOp op1, final UpdateOp op2) throws QueryException {
   switch (op1.getType()) {
     case RENAME:
       if (op1.getTarget().equals(op2.getTarget())) {
         throw new QueryException(
             ErrorCode.ERR_UPDATE_DUPLICATE_RENAME_TARGET,
             "Node %s is target of more than one replace operation.",
             op2.getTarget());
       }
       break;
     case REPLACE_NODE:
       if (op1.getTarget().equals(op2.getTarget())) {
         throw new QueryException(
             ErrorCode.ERR_UPDATE_DUPLICATE_REPLACE_NODE_TARGET,
             "Node %s is target of more than one replace node operation.",
             op2.getTarget());
       }
       break;
     case REPLACE_VALUE:
       if (op1.getTarget().equals(op2.getTarget())) {
         throw new QueryException(
             ErrorCode.ERR_UPDATE_DUPLICATE_REPLACE_VALUE_TARGET,
             "Node %s is target of more than one replace value operation.",
             op2.getTarget());
       }
       break;
     case REPLACE_ELEMENT_CONTENT:
       if (op1.getTarget().equals(op2.getTarget())) {
         throw new QueryException(
             ErrorCode.ERR_UPDATE_DUPLICATE_REPLACE_VALUE_TARGET,
             "Node %s is target of more than one replace element content operation.",
             op2.getTarget());
       }
       break;
     default:
       // Do nothing.
   }
 }