org.apache.jackrabbit.oak.api.Tree.orderBefore()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中org.apache.jackrabbit.oak.api.Tree.orderBefore()方法的一些代码示例,展示了Tree.orderBefore()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tree.orderBefore()方法的具体详情如下:
包路径:org.apache.jackrabbit.oak.api.Tree
类名称:Tree
方法名:orderBefore

Tree.orderBefore介绍

[英]Orders this Tree before the sibling tree with the given name. Calling this method for the first time on this Tree or any of its siblings will persist the current order of siblings and maintain it from this point on.
[中]在具有给定名称的兄弟树之前订购此树。首次在此树或其任何同级树上调用此方法将保持同级树的当前顺序,并从现在起保持该顺序。

代码示例

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testOrderBeforeOnHiddenTree() {
  try {
    Tree hidden = parent.getChild(HIDDEN_NAME);
    hidden.orderBefore("someother");
    fail("IllegalStateException expected");
  } catch (IllegalStateException e) {
    // success
  }
}

代码示例来源:origin: apache/jackrabbit-oak

public void orderBefore(String source, String target)
    throws ItemNotFoundException, InvalidItemStateException {
  Tree tree = getTree();
  if (!tree.getChild(source).exists()) {
    throw new ItemNotFoundException("Not a child: " + source);
  } else if (target != null && !tree.getChild(target).exists()) {
    throw new ItemNotFoundException("Not a child: " + target);
  } else {
    tree.getChild(source).orderBefore(target);
  }
}

代码示例来源:origin: org.apache.jackrabbit/oak-jcr

public void orderBefore(String source, String target)
    throws ItemNotFoundException, InvalidItemStateException {
  Tree tree = getTree();
  if (!tree.getChild(source).exists()) {
    throw new ItemNotFoundException("Not a child: " + source);
  } else if (target != null && !tree.getChild(target).exists()) {
    throw new ItemNotFoundException("Not a child: " + target);
  } else {
    tree.getChild(source).orderBefore(target);
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

public void orderBefore(String source, String target)
    throws ItemNotFoundException, InvalidItemStateException {
  Tree tree = getTree();
  if (!tree.getChild(source).exists()) {
    throw new ItemNotFoundException("Not a child: " + source);
  } else if (target != null && !tree.getChild(target).exists()) {
    throw new ItemNotFoundException("Not a child: " + target);
  } else {
    tree.getChild(source).orderBefore(target);
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
@Before
public void before() throws Exception {
  super.before();
  Tree b = root.getTree("/a/b");
  b.orderBefore("bb");
  root.commit();
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testReorderAce() throws Exception {
  Tree entry = getEntry(testPrincipal, testPath, 0);
  assertIndex(0, entry);
  Tree aclTree = root.getTree(testPath + "/rep:policy");
  aclTree.getChildren().iterator().next().orderBefore(null);
  root.commit();
  entry = getEntry(testPrincipal, testPath, 1);
  assertIndex(1, entry);
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testReorderAddAndRemoveAces() throws Exception {
  Tree entry = getEntry(testPrincipal, testPath, 0);
  assertIndex(0, entry);
  Tree aclTree = root.getTree(testPath + "/rep:policy");
  // reorder testPrincipal entry to the end
  aclTree.getChildren().iterator().next().orderBefore(null);
  Iterator<Tree> aceIt = aclTree.getChildren().iterator();
  // remove the everyone entry
  aceIt.next().remove();
  // remember the name of the testPrincipal entry.
  String name = aceIt.next().getName();
  // add a new entry
  NodeUtil ace = new NodeUtil(aclTree).addChild("denyEveryoneLockMgt", NT_REP_DENY_ACE);
  ace.setString(REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
  ace.setNames(AccessControlConstants.REP_PRIVILEGES, JCR_LOCK_MANAGEMENT);
  // reorder the new entry before the remaining existing entry
  ace.getTree().orderBefore(name);
  root.commit();
  entry = getEntry(testPrincipal, testPath, 1);
  assertIndex(1, entry);
}

代码示例来源:origin: apache/jackrabbit-oak

Tree t2 = r2.getTree("/");
t1.getChild("node2").orderBefore("node1");
t1.getChild("node3").orderBefore(null);
r1.commit();
assertSequence(t1.getChildren(), "node2", "node1", "node3");
t2.getChild("node3").orderBefore("node1");
t2.getChild("node2").orderBefore(null);
r2.commit();
t2.getChild("node3").orderBefore("node1");
t2.getChild("node2").orderBefore(null);
r2.commit();
assertSequence(t2.getChildren(), "node3", "node1", "node2");

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testReorderAndAddAce() throws Exception {
  Tree entry = getEntry(testPrincipal, testPath, 0);
  assertIndex(0, entry);
  Tree aclTree = root.getTree(testPath + "/rep:policy");
  // reorder
  aclTree.getChildren().iterator().next().orderBefore(null);
  // add a new entry
  NodeUtil ace = new NodeUtil(aclTree).addChild("denyEveryoneLockMgt", NT_REP_DENY_ACE);
  ace.setString(REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
  ace.setNames(AccessControlConstants.REP_PRIVILEGES, JCR_LOCK_MANAGEMENT);
  root.commit();
  entry = getEntry(testPrincipal, testPath, 1);
  assertIndex(1, entry);
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
  public void testChildOrderWithoutPropertyReadAccess() throws Exception {
    root.getTree("/a").setOrderableChildren(true);        
    root.getTree("/a/bb").orderBefore("b");
    root.commit();
    setupPermission("/", testPrincipal, true, PrivilegeConstants.REP_READ_NODES);

    Root testRoot = getTestRoot();
    Tree aTree = testRoot.getTree("/a");
    // verify that properties cannot be read:
    assertFalse(aTree.hasProperty(JcrConstants.JCR_PRIMARYTYPE));

    List<String> expected = ImmutableList.of("/a/bb", "/a/b");
    Iterable<String> childPaths = Iterables.transform(aTree.getChildren(), new Function<Tree, String>() {
      @Nullable
      @Override
      public String apply(Tree input) {
        return input.getPath();
      }
    });
    assertTrue(childPaths.toString(), Iterables.elementsEqual(expected, childPaths));
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void orderBefore() throws Exception {
  Tree t = root.getTree("/x/y/z");
  NodeUtil n = new NodeUtil(t);
  n.addChild("node1", JcrConstants.NT_UNSTRUCTURED);
  n.addChild("node2", JcrConstants.NT_UNSTRUCTURED);
  n.addChild("node3", JcrConstants.NT_UNSTRUCTURED);
  t.getChild("node1").orderBefore("node2");
  t.getChild("node3").orderBefore(null);
  root.commit();
  ImmutableTree tree = new ImmutableTree(((AbstractTree) t).getNodeState());
  assertSequence(tree.getChildren(), "node1", "node2", "node3");
  t.getChild("node3").orderBefore("node2");
  root.commit();
  tree = new ImmutableTree(((AbstractTree) t).getNodeState());
  assertSequence(tree.getChildren(), "node1", "node3", "node2");
  t.getChild("node1").orderBefore(null);
  root.commit();
  tree = new ImmutableTree(((AbstractTree) t).getNodeState());
  assertSequence(tree.getChildren(), "node3", "node2", "node1");
}

代码示例来源:origin: apache/jackrabbit-oak

Tree t2 = r2.getTree("/");
t1.getChild("node2").orderBefore("node1");
t1.getChild("node3").orderBefore(null);
t1.addChild("node4");
r1.commit();
assertSequence(t1.getChildren(), "node2", "node1", "node3", "node4");
t2.getChild("node3").orderBefore("node1");
r2.commit();
t2.getChild("node3").orderBefore("node1");
r2.commit();
assertSequence(t2.getChildren(), "node2", "node3", "node1", "node4");

代码示例来源:origin: apache/jackrabbit-oak

Tree t2 = r2.getTree("/");
t1.getChild("node2").orderBefore("node1");
t1.getChild("node3").orderBefore(null);
t1.getChild("node4").remove();
r1.commit();
assertSequence(t1.getChildren(), "node2", "node1", "node3");
t2.getChild("node3").orderBefore("node1");
r2.commit();
t2.getChild("node3").orderBefore("node1");
r2.commit();
assertSequence(t2.getChildren(), "node2", "node3", "node1");

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void concurrentOrderBeforeTargetRemoved() throws Exception {
  ContentSession s1 = repository.login(null, null);
  try {
    Root r1 = s1.getLatestRoot();
    Tree t1 = r1.getTree("/");
    t1.addChild("node1").orderBefore(null);
    t1.addChild("node2");
    t1.addChild("node3");
    t1.addChild("node4");
    r1.commit();
    ContentSession s2 = repository.login(null, null);
    try {
      Root r2 = s2.getLatestRoot();
      Tree t2 = r2.getTree("/");
      t1.getChild("node2").orderBefore("node1");
      t1.getChild("node3").remove();
      r1.commit();
      assertSequence(t1.getChildren(), "node2", "node1", "node4");
      t2.getChild("node4").orderBefore("node3");
      r2.commit();
      assertSequence(t2.getChildren(), "node2", "node1", "node4");
    } finally {
      s2.close();
    }
  } finally {
    s1.close();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

r.commit();
t.getChild("node1").orderBefore("node2");
t.getChild("node3").orderBefore(null);
assertSequence(t.getChildren(), "node1", "node2", "node3");
r.commit();
t.getChild("node3").orderBefore("node2");
assertSequence(t.getChildren(), "node1", "node3", "node2");
r.commit();
assertSequence(t.getChildren(), "node1", "node3", "node2");
t.getChild("node1").orderBefore(null);
assertSequence(t.getChildren(), "node3", "node2", "node1");
r.commit();

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void concurrentOrderBeforeRemoved() throws Exception {
  ContentSession s1 = repository.login(null, null);
  try {
    Root r1 = s1.getLatestRoot();
    Tree t1 = r1.getTree("/");
    t1.addChild("node1");
    t1.addChild("node2");
    t1.addChild("node3");
    r1.commit();
    ContentSession s2 = repository.login(null, null);
    try {
      Root r2 = s2.getLatestRoot();
      Tree t2 = r2.getTree("/");
      t1.getChild("node2").orderBefore("node1");
      t1.getChild("node3").remove();
      r1.commit();
      assertSequence(t1.getChildren(), "node2", "node1");
      t2.getChild("node3").orderBefore("node1");
      r2.commit();
      assertSequence(t2.getChildren(), "node2", "node1");
    } finally {
      s2.close();
    }
  } finally {
    s1.close();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

Root r1 = s1.getLatestRoot();
Tree t1 = r1.getTree("/").addChild("c");
t1.addChild("node1").orderBefore(null);
t1.addChild("node2");
r1.commit();
  t1.getChild("node2").orderBefore("node1");
  r1.commit();
  assertSequence(t1.getChildren(), "node2", "node1");

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void concurrentOrderBeforeAllRemoved() throws Exception {
  ContentSession s1 = repository.login(null, null);
  try {
    Root r1 = s1.getLatestRoot();
    Tree t1 = r1.getTree("/").addChild("c");
    t1.addChild("node1").orderBefore(null);
    t1.addChild("node2");
    t1.addChild("node3");
    r1.commit();
    ContentSession s2 = repository.login(null, null);
    try {
      Root r2 = s2.getLatestRoot();
      Tree t2 = r2.getTree("/c");
      t1.remove();
      // now 'c' does not have ordered children anymore
      r1.getTree("/").addChild("c");
      r1.commit();
      assertSequence(t1.getChildren());
      t2.getChild("node3").orderBefore("node1");
      r2.commit();
      assertSequence(t2.getChildren());
    } finally {
      s2.close();
    }
  } finally {
    s1.close();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
  public void moveOrderableNodes() throws Exception {
    ContentSession s = repository.login(null, null);
    try {
      Root r = s.getLatestRoot();
      Tree t = r.getTree("/");
      Tree c = t.addChild("c");
      c.addChild("node1").orderBefore(null);
      c.addChild("node2");
      t.addChild("node3");
      r.commit();

      r.move("/node3", "/c/node3");
      assertSequence(c.getChildren(), "node1", "node2", "node3");
      r.commit();
      assertSequence(c.getChildren(), "node1", "node2", "node3");
    } finally {
      s.close();
    }
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void concurrentAddChildOrderable() throws Exception {
  ContentSession s1 = repository.login(null, null);
  try {
    Root r1 = s1.getLatestRoot();
    Tree t1 = r1.getTree("/");
    t1.addChild("node1").orderBefore(null);
    t1.addChild("node2");
    r1.commit();
    ContentSession s2 = repository.login(null, null);
    try {
      Root r2 = s2.getLatestRoot();
      Tree t2 = r2.getTree("/");
      t1 = r1.getTree("/");
      // node3 from s1
      t1.addChild("node3");
      r1.commit();
      // node4 from s2
      t2.addChild("node4");
      r2.commit();
      t1 = s1.getLatestRoot().getTree("/");
      assertSequence(
          t1.getChildren(), "node1", "node2", "node3", "node4");
    } finally {
      s2.close();
    }
  } finally {
    s1.close();
  }
}

相关文章