JCR checkin/checkout operations

前端 未结 2 921
忘掉有多难
忘掉有多难 2021-02-08 02:37

I\'m just starting to work with JCR (apache jackrabbit), i want to ask simple question (because i coudn\'t find good tutorial for it): So for what do i need Node.checkout and No

2条回答
  •  再見小時候
    2021-02-08 02:55

    The 'checkin' and 'checkout' methods have to do with how a JCR repository tracks the versions of content. The 'checkout' method signals to the repository that your client application is (likely) going to be modifying some versionable content. The 'checkin' methods signals to the repository that your client application has made changes to the versionable content, and that the repository should record those changes (e.g., the new version) in the version history.

    For example, let's imagine that we want to create a node at '/a/b/c' that is versionable. This is done using something like the following code:

    To create content, you simply set the 'mix:versionable' mixin (or use a mixin or primary node type that inherits from 'mix:versionable') on a node and then save your changes. At that point, the repository will initialize the version history for that node (or subgraph).

    Node b = session.getNode("/a/b");
    Node newNode = b.addNode("c");
    newNode.addMixin("mix:versionable");
    // set other properties and create children
    session.save();
    

    Upon 'session.save()', the repository will note the 'mix:versionable' mixin and will initialize the version history for the content at '/a/b/c'. From this point on, your client application uses 'checkout' and 'checkin' to add new versions to the history.

    VersionManager vm = session.getWorkspace().getVersionManager();
    vm.checkout("/a/b/c");
    // make some changes at/under '/a/b/c'
    session.save();
    // Can make more changes and save, if desired
    vm.checkin("/a/b/c");
    

    When 'checkin' is called, the repository will take the current state of '/a/b/c' and will add it to the version history. Of course, this process is repeated each time you want to make changes to versionable nodes.

提交回复
热议问题