javax.jcr.Node.checkout()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(181)

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

Node.checkout介绍

[英]Sets this versionable node to checked-out status by setting its jcr:isCheckedOut property to true. Under full versioning it also sets the jcr:predecessors property to be a reference to the current base version (the same value as held in jcr:baseVersion). These changes are made by worksapce-write and therefore do require a save.

The part of the subgraph of this node that is affected by the checked-out status of this node becomes no longer read-only.

If this node is already checked-out, this method has no effect.
[中]通过将其jcr:isCheckedOut属性设置为true,将此可版本化节点设置为签出状态。在完全版本控制下,它还将jcr:predecessors属性设置为对当前基本版本的引用(与jcr:baseVersion中的值相同)。这些更改由worksapce write进行,因此确实需要save
此节点的子图中受此节点的签出状态影响的部分不再是只读的。
如果此节点已签出,则此方法无效。

代码示例

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

  1. /**
  2. * Returns the date this version was created.
  3. */
  4. public void testGetCreated() throws RepositoryException {
  5. // create version
  6. versionableNode.checkout();
  7. Version version = versionableNode.checkin();
  8. Calendar now = GregorianCalendar.getInstance();
  9. now.add(Calendar.SECOND, 1);
  10. assertTrue("Method getCreated() should return a creation date before current date.", version.getCreated().before(now));
  11. }

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

  1. /**
  2. * Returns the predecessor versions of this version. This corresponds to
  3. * returning all the nt:version nodes whose jcr:successors property includes
  4. * a reference to the nt:version node that represents this version. A
  5. * RepositoryException is thrown if an error occurs.
  6. */
  7. public void testGetPredecessors() throws RepositoryException {
  8. // create a new version
  9. versionableNode.checkout();
  10. Version version = versionableNode.checkin();
  11. assertTrue("Version should have at minimum one predecessor version.", version.getPredecessors().length > 0);
  12. }

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

  1. /**
  2. * Node.merge(): If V' of a versionable subnode N' in the source workspace
  3. * is a successor of V (the base version of a subnode N in this workspace),
  4. * calling merge must fail.
  5. */
  6. public void testFailIfCorrespondingNodeIsSuccessor() throws RepositoryException {
  7. // make V' of a subnode N' in source workspace be a successor version of
  8. // the base version of the corresponding subnode.
  9. Node n = testRootNode.getNode(nodeName1 + "/" + nodeName2);
  10. n.checkout();
  11. n.checkin();
  12. n.checkout();
  13. try {
  14. // merge, besteffort set to false to stop at the first failure
  15. nodeToMerge.merge(workspace.getName(), false);
  16. fail("Merging a checkedout node if the version V' of the corresponding node is a successor of this node's base version must fail.");
  17. } catch (MergeException e) {
  18. // success
  19. }
  20. }

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

  1. /**
  2. * Test if InvalidItemStateException is thrown if the session affected by
  3. * Workspace.restore(Version[], boolean) has pending changes.
  4. */
  5. @SuppressWarnings("deprecation")
  6. public void testWorkspaceRestoreWithPendingChanges() throws RepositoryException {
  7. versionableNode.checkout();
  8. try {
  9. // modify node without calling save()
  10. versionableNode.setProperty(propertyName1, propertyValue);
  11. // create version in second workspace
  12. Version v = wVersionableNode.checkin();
  13. // try to restore that version
  14. superuser.getWorkspace().restore(new Version[]{v}, false);
  15. fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending.");
  16. } catch (InvalidItemStateException e) {
  17. // success
  18. }
  19. }

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

  1. /**
  2. * Node.merge(): If V' of a versionable subnode N' in the source workspace
  3. * is a predeccessor of V or V' identical to V (the base version of a
  4. * subnode N in this workspace), calling merge must be leave.
  5. */
  6. public void testLeaveIfCorrespondingNodeIsPredeccessor() throws RepositoryException {
  7. // make V' of a subnode N' in source workspace be a predeccessor version of
  8. // the base version of the corresponding subnode.
  9. Node n = testRootNodeW2.getNode(nodeName1 + "/" + nodeName2);
  10. n.checkout();
  11. n.setProperty(propertyName1, CHANGED_STRING);
  12. testRootNodeW2.save();
  13. n.checkin();
  14. n.checkout();
  15. // merge, besteffort set to false to stop at the first failure
  16. nodeToMerge.merge(workspace.getName(), false);
  17. // check if subnode has status "leave"
  18. assertTrue(n.getProperty(propertyName1).getString().equals(CHANGED_STRING));
  19. }

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

  1. /**
  2. * Test the restore of a OnParentVersion-Ignore node
  3. *
  4. * @throws javax.jcr.RepositoryException
  5. */
  6. public void testRestoreNode() throws RepositoryException {
  7. versionableNode.checkout();
  8. Version v = versionableNode.checkin();
  9. versionableNode.checkout();
  10. // add 'ignore' child
  11. String childName = addChildNode(OPVAction).getName();
  12. versionableNode.save();
  13. versionableNode.restore(v, false);
  14. if (!versionableNode.hasNode(childName)) {
  15. fail("On restore of a OnParentVersion-Ignore child node, the node needs to be untouched.");
  16. }
  17. }

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

  1. /**
  2. * Test the restore of a OnParentVersion-INITIALIZE property
  3. *
  4. * @throws javax.jcr.RepositoryException
  5. */
  6. public void testRestoreProp() throws RepositoryException {
  7. Node propParent = p.getParent();
  8. propParent.checkout();
  9. Version v = propParent.checkin();
  10. propParent.checkout();
  11. p.setValue(newPropValue);
  12. p.save();
  13. propParent.restore(v, false);
  14. assertEquals("On restore of a OnParentVersion-INITIALIZE property P, the current value of P must be left unchanged.", p.getString(), newPropValue);
  15. }

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

  1. /**
  2. * Test the restore of a OnParentVersion-IGNORE property
  3. *
  4. * @throws javax.jcr.RepositoryException
  5. */
  6. public void testRestoreProp() throws RepositoryException {
  7. Node propParent = p.getParent();
  8. propParent.checkout();
  9. Version v = propParent.checkin();
  10. propParent.checkout();
  11. p.setValue(newPropValue);
  12. p.save();
  13. propParent.restore(v, false);
  14. assertEquals("On restore of a OnParentVersion-IGNORE property P, the current value of P must be left unchanged.", p.getString(), newPropValue);
  15. }

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

  1. /**
  2. * Test the restore of a OnParentVersion-COMPUTE property
  3. *
  4. * @throws javax.jcr.RepositoryException
  5. */
  6. public void testRestoreProp() throws RepositoryException {
  7. Node propParent = p.getParent();
  8. propParent.checkout();
  9. Version v = propParent.checkin();
  10. propParent.checkout();
  11. p.setValue(newPropValue);
  12. p.save();
  13. propParent.restore(v, false);
  14. assertEquals("On restore of a OnParentVersion-COMPUTE property P, the current P in the workspace will be left unchanged.", p.getString(), newPropValue);
  15. }

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

  1. public void execute(Session session, Node test) throws RepositoryException {
  2. Node n = test.addNode("test");
  3. n.addMixin(mixVersionable);
  4. session.save();
  5. for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
  6. n.checkout();
  7. n.checkin();
  8. }
  9. n.checkout();
  10. }
  11. }, CONCURRENCY);

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

  1. public void execute(Session session, Node test) throws RepositoryException {
  2. // add versionable nodes
  3. for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
  4. Node n = test.addNode("test" + i);
  5. n.addMixin(mixVersionable);
  6. session.save();
  7. n.checkout();
  8. n.checkin();
  9. n.checkout();
  10. }
  11. }
  12. }, CONCURRENCY);

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

  1. public void testRestoreChild1() throws RepositoryException {
  2. versionableNode.addNode("child1");
  3. versionableNode.getSession().save();
  4. Version v1 = versionableNode.checkin();
  5. versionableNode.checkout();
  6. Version v2 = versionableNode.checkin();
  7. versionableNode.restore(v1, true);
  8. assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
  9. versionableNode.restore(version, true);
  10. assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
  11. try {
  12. versionableNode.restore(v2, true);
  13. } catch (RepositoryException e) {
  14. fail("Node.restore('1.3') must fail.");
  15. }
  16. }

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

  1. /**
  2. * Test the restore of a OnParentVersion-ABORT property
  3. *
  4. * @throws javax.jcr.RepositoryException
  5. */
  6. public void testRestoreProp() throws RepositoryException {
  7. try {
  8. p.getParent().checkout();
  9. p.getParent().checkin();
  10. fail("On checkin of N which has a property with OnParentVersion ABORT defined, an UnsupportedRepositoryOperationException must be thrown.");
  11. } catch (VersionException e) {
  12. // success
  13. }
  14. }

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

  1. @SuppressWarnings("deprecation")
  2. public void testRestoreChild1() throws RepositoryException {
  3. versionableNode.addNode("child1");
  4. versionableNode.getSession().save();
  5. Version v1 = versionableNode.checkin();
  6. versionableNode.checkout();
  7. Version v2 = versionableNode.checkin();
  8. versionableNode.restore(v1, true);
  9. assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
  10. versionableNode.restore(version, true);
  11. assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
  12. try {
  13. versionableNode.restore(v2, true);
  14. } catch (RepositoryException e) {
  15. fail("Node.restore('1.3') must fail.");
  16. }
  17. }

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

  1. /**
  2. * Node.merge(): bestEffort is false and any merge fails a MergeException is
  3. * thrown.<br>
  4. */
  5. @SuppressWarnings("deprecation")
  6. public void testMergeNodeBestEffortFalse() throws RepositoryException {
  7. /// create successor versions for a node
  8. // so merge fails for this node
  9. // default workspace
  10. Node originalNode = testRootNode.getNode(nodeName1);
  11. originalNode.checkout();
  12. originalNode.checkin();
  13. // "merge" the clonedNode with the newNode from the default workspace
  14. // merge, besteffort set to false
  15. try {
  16. nodeToMerge.merge(workspace.getName(), false);
  17. fail("bestEffort is false and any merge should throw a MergeException.");
  18. } catch (MergeException e) {
  19. // successful
  20. }
  21. }

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

  1. /**
  2. * Tests if VersionHistory.getVersionableUUID() returns the uuid of the
  3. * corresponding versionable node.
  4. */
  5. public void testGetVersionableUUID() throws RepositoryException {
  6. // create version
  7. versionableNode.checkout();
  8. Version version = versionableNode.checkin();
  9. assertEquals("Method getVersionableUUID() must return the UUID of the corresponding Node.",
  10. version.getContainingHistory().getVersionableUUID(),
  11. versionableNode.getUUID());
  12. }

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

  1. /**
  2. * Tests if {@link javax.jcr.version.Version#getContainingHistory()} returns
  3. * the correct VersionHistory instance.
  4. */
  5. public void testGetContainingHistory() throws RepositoryException {
  6. // create version
  7. versionableNode.checkout();
  8. Version version = versionableNode.checkin();
  9. assertTrue("Method getContainingHistory() must return the same VersionHistory " +
  10. "as getVersionHistory() of the corresponding Node.",
  11. versionableNode.getVersionHistory().isSame(version.getContainingHistory()));
  12. }
  13. }

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

  1. /**
  2. * Returns the date this version was created. This corresponds to the value
  3. * of the jcr:created property in the nt:version node that represents this
  4. * version.
  5. */
  6. public void testGetCreatedCheckAgainstProperty() throws RepositoryException {
  7. // create version
  8. versionableNode.checkout();
  9. Version version = versionableNode.checkin();
  10. Calendar calGetCreated = version.getCreated();
  11. Calendar calCreatedProp = version.getProperty(jcrCreated).getValue().getDate();
  12. assertEquals("Method getCreated() should return value of the jcr:created property.", calGetCreated, calCreatedProp);
  13. }

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

  1. public void execute(Session session, Node test) throws RepositoryException {
  2. Node n = test.addNode("test");
  3. n.addMixin(mixVersionable);
  4. session.save();
  5. // create 3 version
  6. List versions = new ArrayList();
  7. for (int i = 0; i < 3; i++) {
  8. n.checkout();
  9. versions.add(n.checkin());
  10. }
  11. // do random restores
  12. Random rand = new Random();
  13. for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) {
  14. Version v = (Version) versions.get(rand.nextInt(versions.size()));
  15. n.restore(v, true);
  16. }
  17. n.checkout();
  18. }
  19. }, CONCURRENCY);

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

  1. public void run() {
  2. long end = System.currentTimeMillis() + RUN_NUM_SECONDS * 1000;
  3. try {
  4. Node vn = (Node) s.getItem(n.getPath());
  5. while (end > System.currentTimeMillis()) {
  6. vn.checkout();
  7. vn.checkin();
  8. }
  9. } catch (RepositoryException e) {
  10. e.printStackTrace();
  11. } finally {
  12. s.logout();
  13. }
  14. }
  15. });

相关文章