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

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

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

Node.checkin介绍

[英]Creates a new version of this node and returns that Versionobject. The new version becomes the base version of this node. The name of the new version is implementaion determined.

This node becomes checked-in and its jcr:checkedOut property is set to false to reflect this. On a successful check-in the change to this property is made as a workspace-write, and therefore does not require a save.

The part of the subgraph of this node that is affected by check-in becomes read-only (see the specification for details).

If this node is already checked-in, this method has no effect but returns the current base version of this node.
[中]创建此节点的新版本并返回该版本对象。新版本将成为此节点的基础版本。新版本的名称已确定。
此节点将被检入,其jcr:checkedOut属性设置为false以反映此情况。成功签入时,此属性的更改作为工作区写入进行,因此不需要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. * 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. 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. * 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. @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(): 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 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-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. /**
  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. * 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. 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. /**
  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. // 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. /**
  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. * Node.merge(): versionable subNode N checked-in: If V' is a successor (to
  3. * any degree) of V, then the merge result for N is update<br> modify a node
  4. * on the workspace1 and then merge the one in workspace2 with the one in
  5. * workspace1 precondition is that the node in workspace2 is checked in
  6. */
  7. @SuppressWarnings("deprecation")
  8. public void disable_testMergeNodeFromUpdatedSourceWorkspace() throws RepositoryException {
  9. Node originalNode = testRootNode.getNode(nodeName1);
  10. // update nodeName1 on workspace1
  11. originalNode.checkout();
  12. originalNode.checkin();
  13. testRootNode.getSession().save();
  14. // "merge" the clonedNode with the newNode from the default workspace
  15. // besteffort set to false to stop at the first failure
  16. nodeToMerge.merge(workspace.getName(), false);
  17. final String originalBaseVersionUUID = originalNode.getBaseVersion().getUUID();
  18. final String clonedBaseVersionUUID = nodeToMerge.getBaseVersion().getUUID();
  19. assertTrue("clonedNode has different version UUID than expected, it should be updated with the newNode version UUID", originalBaseVersionUUID.equals(clonedBaseVersionUUID));
  20. }

代码示例来源: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 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. });

代码示例来源: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);

相关文章