// Collect some of the information about the node that we'll need ...
SessionCache cache = cache();
NodeKey versionedKey = node.key();
Path versionHistoryPath = versionHistoryPathFor(versionedKey);
CachedNode cachedNode = node.node();
DateTime now = session().dateFactory().create();
// Create the system content that we'll use to update the system branch ...
SessionCache systemSession = session.createSystemCache(false);
SystemContent systemContent = new SystemContent(systemSession);
MutableCachedNode version = null;
try {
// Create a new version in the history for this node; this initializes the version history if it is missing ...
List<Property> versionableProps = new ArrayList<Property>();
addVersionedPropertiesFor(node, false, versionableProps);
AtomicReference<MutableCachedNode> frozen = new AtomicReference<MutableCachedNode>();
version = systemContent.recordNewVersion(cachedNode, cache, versionHistoryPath, null, versionableProps, now, frozen);
NodeKey historyKey = version.getParentKey(systemSession);
// Update the node's 'mix:versionable' properties, using a new session ...
SessionCache versionSession = session.spawnSessionCache(false);
MutableCachedNode versionableNode = versionSession.mutable(versionedKey);
PropertyFactory props = propertyFactory();
ReferenceFactory refFactory = session.referenceFactory();
Reference historyRef = refFactory.create(historyKey, true);
Reference baseVersionRef = refFactory.create(version.getKey(), true);
versionableNode.setProperty(versionSession, props.create(JcrLexicon.VERSION_HISTORY, historyRef));
versionableNode.setProperty(versionSession, props.create(JcrLexicon.BASE_VERSION, baseVersionRef));
versionableNode.setProperty(versionSession, props.create(JcrLexicon.IS_CHECKED_OUT, Boolean.FALSE));
// The 'jcr:predecessors' set to an empty array, per Section 15.2 in JSR-283
versionableNode.setProperty(versionSession, props.create(JcrLexicon.PREDECESSORS, new Object[] {}));
// Now process the children of the versionable node, and add them under the frozen node ...
MutableCachedNode frozenNode = frozen.get();
for (ChildReference childRef : cachedNode.getChildReferences(versionSession)) {
AbstractJcrNode child = session.node(childRef.getKey(), null, versionedKey);
versionNodeAt(child, frozenNode, false, versionSession, systemSession);
}
// Now save all of the changes ...