mixinTypes, versionHistoryPath, originalVersionKey,
context.getTime());
}
// Now update the node as if it's checked in (with the exception of the predecessors...)
Reference historyRef = referenceFactory.create(historyKey, true);
Reference baseVersionRef = referenceFactory.create(baseVersionKey, true);
node.setProperty(cache, propertyFactory.create(JcrLexicon.IS_CHECKED_OUT, Boolean.TRUE));
node.setReference(cache, propertyFactory.create(JcrLexicon.VERSION_HISTORY, historyRef), systemCache);
node.setReference(cache, propertyFactory.create(JcrLexicon.BASE_VERSION, baseVersionRef), systemCache);
// JSR 283 - 15.1
node.setReference(cache, propertyFactory.create(JcrLexicon.PREDECESSORS, new Object[] {baseVersionRef}),
systemCache);
} else {
// we're dealing with node which has a version history, check if there any versionable properties present
boolean hasVersioningProperties = node.hasProperty(JcrLexicon.IS_CHECKED_OUT, cache)
|| node.hasProperty(JcrLexicon.VERSION_HISTORY, cache)
|| node.hasProperty(JcrLexicon.BASE_VERSION, cache)
|| node.hasProperty(JcrLexicon.PREDECESSORS, cache);
if (!hasVersioningProperties) {
// the node doesn't have any versionable properties, so this is a case of mix:versionable removed at some
// point and then re-added. If it had any versioning properties, we might've been dealing with something
// else
// e.g. a restore
// Re-link the versionable properties, based on the existing version history
node.setProperty(cache, propertyFactory.create(JcrLexicon.IS_CHECKED_OUT, Boolean.TRUE));
JcrVersionHistoryNode versionHistoryNode = versionManager().getVersionHistory(node(node.getKey(), null));
Reference historyRef = referenceFactory.create(versionHistoryNode.key(), true);
node.setReference(cache, propertyFactory.create(JcrLexicon.VERSION_HISTORY, historyRef), systemCache);
// set the base version to the last existing version
JcrVersionNode baseVersion = null;
for (VersionIterator versionIterator = versionHistoryNode.getAllVersions(); versionIterator.hasNext();) {
JcrVersionNode version = (JcrVersionNode)versionIterator.nextVersion();
if (baseVersion == null || version.isLinearSuccessorOf(baseVersion)) {
baseVersion = version;
}
}
assert baseVersion != null;
Reference baseVersionRef = referenceFactory.create(baseVersion.key(), true);
node.setReference(cache, propertyFactory.create(JcrLexicon.BASE_VERSION, baseVersionRef), systemCache);
// set the predecessors to the same list as the base version's predecessors
Version[] baseVersionPredecessors = baseVersion.getPredecessors();
Reference[] predecessors = new Reference[baseVersionPredecessors.length];