javax.jcr.Session.move()方法的使用及代码示例

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

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

Session.move介绍

[英]Moves the node at srcAbsPath (and its entire subgraph) to the new location at destAbsPath.

This is a session-write method and therefor requires a save to dispatch the change.

The identifiers of referenceable nodes must not be changed by a move. The identifiers of non-referenceable nodes may change.

A ConstraintViolationException is thrown either immediately, on dispatch or on persist, if performing this operation would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

As well, a ConstraintViolationException will be thrown on persist if an attempt is made to separately save either the source or destination node.

Note that this behavior differs from that of Workspace#move, which is a workspace-write method and therefore immediately dispatches changes.

The destAbsPath provided must not have an index on its final element. If ordering is supported by the node type of the parent node of the new location, then the newly moved node is appended to the end of the child node list.

This method cannot be used to move an individual property by itself. It moves an entire node and its subgraph.

If no node exists at srcAbsPath or no node exists one level above destAbsPath (in other words, there is no node that will serve as the parent of the moved item) then a PathNotFoundException is thrown either immediately, on dispatch or on persist. Implementations may differ on when this validation is performed.

An ItemExistsException is thrown either immediately, on dispatch or on persist, if a node already exists at destAbsPath and same-name siblings are not allowed. Implementations may differ on when this validation is performed.

Note that if a property already exists at destAbsPath, the operation succeeds, since a node may have a child node and property with the same name.

A VersionException is thrown either immediately, on dispatch or on persist, if the parent node of destAbsPath or the parent node of srcAbsPath] is read-only due to a checked-in node. Implementations may differ on when this validation is performed.

A [[$17$]] is thrown either immediately, on dispatch or on persist, if a lock prevents the [[$18$]]. Implementations may differ on when this validation is performed.
[中]将srcAbsPath处的节点(及其整个子图)移动到[$1$]处的新位置。
这是一种会话写入方法,因此需要save来分派更改。
[$3$]不能更改可引用节点的标识符。不可引用节点的标识符可能会更改。
如果执行此操作会违反节点类型或特定于实现的约束,则在分派或持久化时立即抛出ConstraintViolationException。执行此验证的时间可能会有所不同。
此外,如果试图分别save源节点或目标节点,则会在持久化上抛出ConstraintViolationException
请注意,这种行为与Workspace#move不同,后者是一种工作区写入方法,因此会立即发送更改。
提供的destAbsPath不能在其最终元素上有索引。如果新位置的父节点的节点类型支持排序,则新移动的节点将附加到子节点列表的末尾。
此方法不能用于单独移动单个属性。它移动整个节点及其子图。
如果srcAbsPath上不存在节点,或者destAbsPath上一级没有节点(换句话说,没有节点将作为移动项目的父节点),则在分派或持久化时立即抛出PathNotFoundException。执行此验证的时间可能会有所不同。
如果destAbsPath上已经存在一个节点,并且不允许使用同名同级,则ItemExistsException会在分派或持久化时立即抛出。执行此验证的时间可能会有所不同。
请注意,如果destAbsPath上已经存在属性,则操作会成功,因为节点可能具有同名的子节点和属性。
如果destAbsPath的父节点或srcAbsPath] is read-only due to a checked-in node. Implementations may differ on when this validation is performed.的父节点,则VersionException会在分派或持久化时立即抛出
A [[$17$]] is thrown either immediately, on dispatch or on persist, if a lock prevents the [[$18$]]. Implementations may differ on when this validation is performed.

代码示例

代码示例来源:origin: org.chromattic/chromattic.core

public void move(Node srcNode, Node dstNode, String dstName) throws RepositoryException {
 String dstPath = dstNode.getPath() + "/" + dstName;
 session.move(srcNode.getPath(), dstPath);
}

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

public void testMoveNode() throws Exception {
  Node n = (Node) readOnlySession.getItem(testNodePath);
  String destPath = testRootNode.getPath() + "/" + nodeName2;
  try {
    readOnlySession.move(n.getPath(), destPath);
    readOnlySession.save();
    fail("A read only session must not be allowed to move a node");
  } catch (AccessDeniedException e) {
    // expected
    log.debug(e.getMessage());
  }
}

代码示例来源:origin: pentaho/pentaho-platform

public Void doInJcr( final Session session ) throws RepositoryException {
  session.move( src, dest );
  session.save();
  return null;
 }
} );

代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine

private void moveToHistory(final Node node) {
  try {
    // the updater node was modified externally by the executor
    session.refresh(false);
    final String srcPath = node.getPath();
    final Node history = session.getNode(UPDATE_HISTORY_PATH);
    String name = node.getName();
    int count = 2;
    while (history.hasNode(name)) {
      name = node.getName() + "-" + count++;
    }
    final String destPath = UPDATE_HISTORY_PATH + "/" + name;
    session.move(srcPath, destPath);
    session.save();
  } catch (RepositoryException e) {
    log.error("Failed to remove updater from queue", e);
  }
}

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

/**
 * Move <code>node</code> to the new <code>parent</code>.
 */
protected void move(Node node, Node parent) throws RepositoryException {
  String oldPath = node.getPath();
  String newPath = parent.getPath() + "/" + node.getName();
  node.getSession().move(oldPath, newPath);
}

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

@Override
protected void move(String source, String dest, Session session) throws RepositoryException {
  session.move(source, dest);
  session.save();
}

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

/**
   * Tries to move a node using {@link javax.jcr.Session#move(String, String)}
   * where the destination parent is checked in. This should throw an {@link
   * javax.jcr.version.VersionException}.
   */
  public void testSessionMoveDestCheckedInVersionException() throws RepositoryException {
    // make sure versionable node is checked in
    versionableNode.checkin();

    try {
      // try to move the sub node this should throw an VersionException either instantly or upon save()
      superuser.move(nonVersionableNode.getPath(), versionableNode.getPath() + "/" + nodeName1);
      superuser.save();
      fail("Moving a node using Session.save() where destination parent " +
          "node is versionable and checked in should throw a VersionException!");
    } catch (VersionException e) {
      // ok, works as expected
    }
  }
}

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

/**
 * Move <code>node</code> to the new <code>parent</code>.
 */
protected void move(Node node, Node parent) throws RepositoryException {
  String oldPath = node.getPath();
  String newPath = parent.getPath() + "/" + node.getName();
  node.getSession().move(oldPath, newPath);
}

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

public void testMove() throws Exception {
    superuser.move(srcAbsPath, destAbsPath1);
    session.move(srcAbsPath, destAbsPath2);
    superuser.save();
    try {
      session.save();
      fail("InvalidItemStateException expected");
    } catch (InvalidItemStateException e) {
      // expected
    }
  }
}

代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-metadata-modeshape

public static Node moveNode(Node node, Path newPath) {
  try {
    Session session = node.getSession();
    String path = newPath.toAbsolutePath().toString();
    session.move(node.getPath(), path);
    session.save(); // save required for the move to take effect.
    return session.getNode(path);
  } catch (AccessDeniedException e) {
    log.debug("Access denied", e);
    throw new AccessControlException(e.getMessage());
  } catch (RepositoryException e) {
    throw new MetadataRepositoryException("Failed to move node to path: " + newPath, e);
  }
}

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

/**
 * Move <code>node</code> to the new <code>parent</code>.
 */
protected void move(Node node, Node parent) throws RepositoryException {
  String oldPath = node.getPath();
  String newPath = parent.getPath() + "/" + node.getName();
  node.getSession().move(oldPath, newPath);
}

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

public void testAddWithMoveFrom() throws Exception {
  testRootNode.getNode("A").addNode("D");
  session.move(testRoot + "/A/B", testRoot + "/C/B");
  superuser.save();
  try {
    session.save();
  } catch (InvalidItemStateException e) {
    fail("must not throw exception");
  }
}

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

/**
 * Test if the removeExisting-flag removes an existing node in case of uuid conflict.
 */
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithRemoveExisting() throws NotExecutableException, RepositoryException {
  // create version for parentNode of childNode
  superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
  Version parentV = versionableNode.checkin();
  // move child node in order to produce the uuid conflict
  String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
  wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
  wSuperuser.save();
  // restore the parent with removeExisting == true >> moved child node
  // must be removed.
  wSuperuser.getWorkspace().restore(new Version[]{parentV}, true);
  if (wSuperuser.itemExists(newChildPath)) {
    fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
  }
}

代码示例来源:origin: org.jcrom/jcrom

/**
   * {@inheritDoc}
   */
  @Override
  public void doMoveNode(Node parentNode, Node node, String nodeName, JcrNode jcrNode, Object entity) throws JcrMappingException, RepositoryException {
    if (parentNode.getPath().equals("/")) {
      // special case: moving a root node
      node.getSession().move(node.getPath(), parentNode.getPath() + nodeName);
    } else {
      node.getSession().move(node.getPath(), parentNode.getPath() + "/" + nodeName);
    }
  }
}

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

public void testAddWithMoveTo() throws Exception {
  testRootNode.getNode("A").addNode("D");
  session.move(testRoot + "/C", testRoot + "/A/C");
  superuser.save();
  try {
    session.save();
  } catch (InvalidItemStateException e) {
    fail("must not throw exception");
  }
}

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

/**
 * Test if the removeExisting-flag removes an existing node in case of uuid conflict.
 */
public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException {
  // create version for parentNode of childNode
  superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
  Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
  // move child node in order to produce the uuid conflict
  String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
  wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
  wSuperuser.save();
  // restore the parent with removeExisting == true >> moved child node
  // must be removed.
  wSuperuser.getWorkspace().getVersionManager().restore(new Version[]{parentV}, true);
  if (wSuperuser.itemExists(newChildPath)) {
    fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
  }
}

代码示例来源:origin: org.onehippo.cms7.hst.client-modules/hst-page-composer

private void moveContainerItems(final Node from, final Node to) throws RepositoryException {
  Session session = from.getSession();
  for (Node fromChild : new NodeIterable(from.getNodes())) {
    String newName = fromChild.getName();
    int counter = 0;
    while (to.hasNode(newName)) {
      newName = fromChild.getName() + ++counter;
    }
    session.move(fromChild.getPath(), to.getPath() + "/" + newName);
  }
}

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

public void testRemoveWithMoveFrom() throws Exception {
  Node d = testRootNode.getNode("A").addNode("D");
  superuser.save();
  d.remove();
  session.move(testRoot + "/A/B", testRoot + "/C/B");
  superuser.save();
  try {
    session.save();
  } catch (InvalidItemStateException e) {
    fail("must not throw exception");
  }
}

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

public void beforeScanning(Node node) throws RepositoryException {
    String path = node.getPath();
    if (path.startsWith("/node")) {
      log("Traversing: " + node.getPath());
    }
    if ("/node1".equals(node.getPath())) {
      String from = "/node2/node3";
      String to = "/node0/node3";
      log("Moving " + from + " -> " + to);
      sessionMover.move(from, to);
      sessionMover.save();
      sleepForFile();
    }
  }
});

代码示例来源:origin: org.onehippo.cms7.hst.toolkit-resources.addon/hst-addon-repository

private void migrateBlueprint(final Node blueprintNode) throws RepositoryException {
  if (!blueprintNode.hasNode("hst:channel")) {
    getLogger().info("No need to migrate blueprint '{}' because does not have an hst:channel node.", blueprintNode.getPath());
    return;
  }
  final Node blueprintConfigurationNode;
  if (blueprintNode.hasNode("hst:configuration")) {
    blueprintConfigurationNode = blueprintNode.getNode("hst:configuration");
  } else {
    blueprintConfigurationNode = blueprintNode.addNode("hst:configuration", "hst:configuration");
  }
  blueprintNode.getSession().move(blueprintNode.getPath() + "/hst:channel", blueprintConfigurationNode.getPath() + "/hst:channel");
}

相关文章

微信公众号

最新文章

更多