Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (revision 1446307) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (working copy) @@ -228,6 +228,32 @@ Tree addChild(String name); /** + * Changes the nature of this tree such that the order of the children + * is kept stable. The expected behavior is as follows: + * + *
    + *
  1. Calling {@code setOrderableChildren(true)} on a tree + * the first time will stabilize the order of existing children. Any + * subsequent {@link #addChild(String)} call is guaranteed to insert + * the new tree and the end of the child list.
  2. + *
  3. Calling {@code setOrderableChildren(true)} on a tree + * that already has its children ordered has no effect.
  4. + *
  5. Calling {@code setOrderableChildren(false)} on a tree that + * doesn't have ordered children has not effect
  6. + *
  7. Calling {@code setOrderableChildren(false)} on a tree + * with ordered children will remove the necessity to keep the child + * list stable. The order of children upon {@link #getChildren()} is + * subsequently undefined.
  8. + *
+ * + * Calling {@link #orderBefore(String)} on a tree, implicitly enables + * orderable children on the parent tree. + * + * @param enable Enable (or disable) orderable children for this tree. + */ + void setOrderableChildren(boolean enable); + + /** * Orders this {@code Tree} before the sibling tree with the given * {@code name}. Calling this method for the first time on this * {@code Tree} or any of its siblings will persist the current order Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java (revision 1446307) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java (working copy) @@ -209,6 +209,11 @@ } @Override + public void setOrderableChildren(boolean enable) { + throw new UnsupportedOperationException(); + } + + @Override public boolean remove() { throw new UnsupportedOperationException(); } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java (revision 1446307) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java (working copy) @@ -299,6 +299,15 @@ } @Override + public void setOrderableChildren(boolean enable) { + if (enable) { + ensureChildOrderProperty(); + } else { + nodeBuilder.removeProperty(OAK_CHILD_ORDER); + } + } + + @Override public boolean remove() { root.checkLive(); if (isDisconnected()) { @@ -571,7 +580,7 @@ * the property if it doesn't exist and initialize the value with the names * of the children as returned by {@link NodeBuilder#getChildNodeNames()}. */ - public void ensureChildOrderProperty() { + private void ensureChildOrderProperty() { PropertyState childOrder = nodeBuilder.getProperty(OAK_CHILD_ORDER); if (childOrder == null) { nodeBuilder.setProperty( Index: oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java (revision 1446307) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java (working copy) @@ -219,7 +219,7 @@ } else { aclNode = createAclNode(oakPath, tree); } - TreeUtil.ensureOrderableChildren(aclNode.getTree()); + aclNode.getTree().setOrderableChildren(true); ACL acl = (ACL) policy; for (JackrabbitAccessControlEntry ace : acl.getEntries()) { Index: oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java (revision 1446307) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java (working copy) @@ -79,18 +79,4 @@ PropertyState property = tree.getProperty(propertyName); return property != null && !property.isArray() && property.getValue(BOOLEAN); } - - /** - * FIXME: see OAK-626 for a proposal on how to clean that up. - * - * Utility method that assert that children of a tree keep the order such - * as defined by the insertion and any subsequent - * {@link Tree#orderBefore(String) reordering}. - * - * @param tree The parent tree whose children are mandated to be orderable. - */ - public static void ensureOrderableChildren(Tree tree) { - checkArgument(tree instanceof TreeImpl); - ((TreeImpl) tree).ensureChildOrderProperty(); - } } \ No newline at end of file