11
votes

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 Node.checkin methods? What do they mean?

Thx

2

2 Answers

10
votes

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.

4
votes

In Jackrabbit 2.x, the methods on Node are deprecated. Instead, use VersionManager.checkout / checkin (they are available in Jackrabbit 1.x as well). Here is some sample code:

Node test = s.getRootNode().addNode("test");
Node t1 = test.addNode("t1");
t1.addMixin("mix:versionable");
s.save();
VersionManager vm = s.getWorkspace().
    getVersionManager();
vm.checkout("/test/t1");
t1.setProperty("data", "Hello" + i);
s.save();
vm.checkin("/test/t1");