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(); } }