synchronized InternalVersion setVersionLabel(Name versionName, Name label, boolean move)
throws VersionException {
InternalVersion version =
(versionName != null) ? getVersion(versionName) : null;
if (versionName != null && version == null) {
throw new VersionException("Version " + versionName + " does not exist in this version history.");
}
Name prevName = labelCache.get(label);
InternalVersionImpl prev = null;
if (prevName == null) {
if (version == null) {
return null;
}
} else {
prev = (InternalVersionImpl) getVersion(prevName);
if (prev.equals(version)) {
return version;
} else if (!move) {
// already defined elsewhere, throw
throw new VersionException("Version label " + label + " already defined for version " + prev.getName());
}
}
// update persistence
try {
if (version == null) {
labelNode.removeProperty(label);
} else {
labelNode.setPropertyValue(
label, InternalValue.create(version.getId()));
}
labelNode.store();
} catch (RepositoryException e) {
throw new VersionException(e);
}
// update internal structures
if (prev != null) {
prev.internalRemoveLabel(label);