org.apache.jackrabbit.oak.api.Root类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(166)

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

Root介绍

[英]A Root instance serves as a container for a Tree. It is obtained from a ContentSession, which governs accessibility and visibility of the Tree and its sub trees.

All root instances created by a content session become invalid after the content session is closed. Any method called on an invalid root instance will throw an InvalidStateException.

Tree instances may become non existing after a call to #refresh(), #rebase() or #commit(). Any write access to non existing Tree instances will cause an InvalidStateException.
[中]根实例充当树的容器。它是从ContentSession获取的,ContentSession控制树及其子树的可访问性和可见性。
内容会话关闭后,内容会话创建的所有根实例都将无效。对无效根实例调用的任何方法都将引发InvalidStateException。
调用#refresh()、#rebase()或#commit()后,树实例可能不存在。对不存在的树实例的任何写访问都将导致InvalidStateException。

代码示例

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

@Test
public void moveToSelf() throws CommitFailedException {
  Root root = session.getLatestRoot();
  root.getTree("/").addChild("s");
  root.commit();
  assertTrue(root.move("/s", "/s"));
}

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

@Override
public void after() throws Exception {
  try {
    root.refresh();
    root.getTree(TEST_PATH).remove();
    root.commit();
  } finally {
    super.after();
  }
}

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

@Override
public boolean init(@NotNull Session session, @NotNull Root root, @NotNull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @NotNull ReferenceChangeTracker referenceTracker, @NotNull SecurityProvider securityProvider) {
  isSystemSession = root.getContentSession().getAuthInfo().getPrincipals().contains(SystemPrincipal.INSTANCE);
  return true;
}

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

void autosave() throws RepositoryException {
  if (autosave) {
    try {
      root.commit();
    } catch (CommitFailedException e) {
      throw e.asRepositoryException();
    } finally {
      root.refresh();
    }
  }
}

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

public void refresh(boolean keepChanges) {
  sessionCounters.refreshTime = clock.getTime();
  sessionCounters.refreshCount++;
  if (keepChanges && hasPendingChanges()) {
    root.rebase();
  } else {
    root.refresh();
  }
  if (permissionProvider != null) {
    permissionProvider.refresh();
  }
}

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

@Nullable
Tree getAuthorizableByPrincipal(@NotNull Principal principal) {
  if (principal instanceof TreeBasedPrincipal) {
    return root.getTree(((TreeBasedPrincipal) principal).getOakPath());
  }
  // NOTE: in contrast to JR2 the extra shortcut for ID==principalName
  // can be omitted as principals names are stored in user defined
  // index as well.
  try {
    StringBuilder stmt = new StringBuilder();
    stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']');
    stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName");
    stmt.append(QueryEngine.INTERNAL_SQL2_QUERY);
    Result result = root.getQueryEngine().executeQuery(stmt.toString(),
        Query.JCR_SQL2, 1, 0,
        Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())),
        NO_MAPPINGS);
    Iterator<? extends ResultRow> rows = result.getRows().iterator();
    if (rows.hasNext()) {
      String path = rows.next().getPath();
      return root.getTree(path);
    }
  } catch (ParseException ex) {
    log.error("Failed to retrieve authorizable by principal", ex);
  }
  return null;
}

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

@Override
public void after() throws Exception {
  try {
    if (testSession != null) {
      testSession.close();
    }
    root.getTree("/a").remove();
    root.commit();
  } finally {
    super.after();
  }
}

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

@Test
  public void testGetProperties() throws Exception {
    setupPermission("/a", testPrincipal, false, PrivilegeConstants.REP_READ_PROPERTIES);

    testRoot.refresh();
    Tree a = testRoot.getTree("/a");
    Iterable<? extends PropertyState> props = a.getProperties();
    assertFalse(props.iterator().hasNext());
  }
}

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

@Before
public void before() throws Exception {
  session = createRepository().login(null, null);
  root = session.getLatestRoot();
  qe = root.getQueryEngine();
  
  root.getTree("/oak:index/counter").setProperty("resolution", 100);
  root.getTree("/oak:index/counter").setProperty("seed", 1);
  
  Tree content = root.getTree("/").addChild("content");
  // add 200'000 nodes under /content
  for (int i = 0; i < 2000; i++) {
    Tree t = content.addChild("test" + i);
    for (int j = 0; j < 100; j++) {
      t.addChild("n" + j);
    }
  }
  root.commit();
  
  runAsyncIndex();
}

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

@Test
public void rebaseWithMove() throws CommitFailedException {
  Root root1 = session.getLatestRoot();
  Root root2 = session.getLatestRoot();
  checkEqual(root1.getTree("/"), root2.getTree("/"));
  root2.getTree("/").addChild("one").addChild("two").addChild("three")
      .setProperty("p1", "V1");
  root2.commit();
  root1.move("/x", "/y/x-moved");
  root1.rebase();
  root2.move("/x", "/y/x-moved");
  checkEqual(root1.getTree("/"), (root2.getTree("/")));
}

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

@Override
public void after() throws Exception {
  try {
    root.getTree("/test").remove();
    if (root.hasPendingChanges()) {
      root.commit();
    }
  } finally {
    super.after();
  }
}

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

@Test
public void move() throws CommitFailedException {
  Root root = session.getLatestRoot();
  Tree tree = root.getTree("/");
  Tree y = tree.getChild("y");
  Tree x = tree.getChild("x");
  assertTrue(x.exists());
  assertFalse(root.hasPendingChanges());
  root.move("/x", "/y/xx");
  assertTrue(root.hasPendingChanges());
  assertFalse(tree.hasChild("x"));
  assertTrue(y.hasChild("xx"));
  assertEquals("/y/xx", x.getPath());
  root.commit();
  assertFalse(root.hasPendingChanges());
  assertFalse(tree.hasChild("x"));
  assertTrue(tree.hasChild("y"));
  assertTrue(tree.getChild("y").hasChild("xx"));
}

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

@Before
public void before() throws Exception {
  super.before();
  testPrincipal = getTestUser().getPrincipal();
  NodeUtil rootNode = new NodeUtil(root.getTree("/"), namePathMapper);
  NodeUtil testNode = rootNode.addChild("testPath", JcrConstants.NT_UNSTRUCTURED);
  testNode.addChild("childNode", JcrConstants.NT_UNSTRUCTURED);
  addAcl(testPath, EveryonePrincipal.getInstance());
  addAcl(childPath, EveryonePrincipal.getInstance());
  root.commit();
  permissionStore = new PermissionStoreImpl(root, root.getContentSession().getWorkspaceName(), getConfig(AuthorizationConfiguration.class).getRestrictionProvider());
}

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

@Test
public void testGetTokenInfoFromInvalidLocation4() throws Exception {
  TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
  Tree tokenTree = getTokenTree(info);
  assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
  TokenInfo info2 = null;
  try {
    Tree adminTree = root.getTree(getUserManager(root).getAuthorizable(adminSession.getAuthInfo().getUserID()).getPath());
    NodeUtil node = new NodeUtil(adminTree).getOrAddChild(TOKENS_NODE_NAME, JcrConstants.NT_UNSTRUCTURED);
    assertTrue(root.move(tokenTree.getPath(), node.getTree().getPath() + '/' + tokenTree.getName()));
    info2 = tokenProvider.getTokenInfo(info.getToken());
    assertNotNull(info2);
    assertFalse(info2.matches(new TokenCredentials(info.getToken())));
  } finally {
    root.refresh();
  }
}

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

@Test
public void moveNew() {
  Root root = session.getLatestRoot();
  Tree tree = root.getTree("/");
  Tree t = tree.addChild("new");
  root.move("/new", "/y/new");
  assertEquals("/y/new", t.getPath());
  assertFalse(tree.getChild("new").exists());
}

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

@Test
public void testSyncMembershipDepthNoSync() throws Exception {
  ExternalUser externalUser = idp.listUsers().next();
  Authorizable a = syncCtx.createUser(externalUser);
  root.commit();
  assertTrue(externalUser.getDeclaredGroups().iterator().hasNext());
  syncCtx.syncMembership(externalUser, a, 0);
  assertFalse(root.hasPendingChanges());
  syncCtx.syncMembership(externalUser, a, -1);
  assertFalse(root.hasPendingChanges());
}

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

@NotNull
public QueryEngine getQueryEngine() {
  return root.getQueryEngine();
}

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

@After
public void tearDown() {
  root.refresh();
  root = null;
}

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

@Test
public void testCreateRemoveGroup() throws RepositoryException {
  Group g = mgr.createGroup("g");
  assertFalse(root.hasPendingChanges());
  g.remove();
  assertFalse(root.hasPendingChanges());
}

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

@Override
public void apply(Root root) throws RemoteCommitException {
  logger.debug("performing 'move' operation on source={}, target={}", source, target);
  boolean success = root.move(source, target);
  if (success) {
    return;
  }
  throw new RemoteCommitException("unable to move the tree");
}

相关文章