use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class InternalVersionHistoryImpl method checkin.
/**
* Checks in a node. It creates a new version with the given name and freezes
* the state of the given node.
*
* @param name new version name
* @param src source node to version
* @param created optional created date
* @return the newly created version
* @throws RepositoryException if an error occurs
*/
synchronized InternalVersionImpl checkin(Name name, NodeStateEx src, Calendar created) throws RepositoryException {
// copy predecessors from src node
InternalValue[] predecessors;
if (src.hasProperty(NameConstants.JCR_PREDECESSORS)) {
predecessors = src.getPropertyValues(NameConstants.JCR_PREDECESSORS);
// check all predecessors
for (InternalValue pred : predecessors) {
NodeId predId = pred.getNodeId();
// check if version exist
if (!nameCache.containsValue(predId)) {
throw new RepositoryException("Invalid predecessor in source node: " + predId);
}
}
} else {
// with simple versioning, the node does not contain a predecessors
// property and we just use the 'head' version as predecessor
Iterator<NodeId> iter = nameCache.values().iterator();
NodeId last = null;
while (iter.hasNext()) {
last = iter.next();
}
if (last == null) {
// should never happen
last = rootVersion.getId();
}
predecessors = new InternalValue[] { InternalValue.create(last) };
}
NodeId versionId = vMgr.getNodeIdFactory().newNodeId();
NodeStateEx vNode = node.addNode(name, NameConstants.NT_VERSION, versionId, true);
// check for jcr:activity
if (src.hasProperty(NameConstants.JCR_ACTIVITY)) {
InternalValue act = src.getPropertyValue(NameConstants.JCR_ACTIVITY);
vNode.setPropertyValue(NameConstants.JCR_ACTIVITY, act);
}
// initialize 'created', 'predecessors' and 'successors'
if (created == null) {
created = getCurrentTime();
}
vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(created));
vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, predecessors);
vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
// checkin source node
InternalFrozenNodeImpl.checkin(vNode, NameConstants.JCR_FROZENNODE, src);
// update version graph
boolean isConfiguration = src.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION);
InternalVersionImpl version = isConfiguration ? new InternalBaselineImpl(this, vNode, name) : new InternalVersionImpl(this, vNode, name);
version.internalAttach();
// and store
node.store();
vMgr.versionCreated(version);
// update cache
versionCache.put(version.getId(), version);
nameCache.put(version.getName(), version.getId());
return version;
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class InternalVersionHistoryImpl method getVersionByLabel.
/**
* {@inheritDoc}
*/
public synchronized InternalVersion getVersionByLabel(Name label) {
Name versionName = labelCache.get(label);
if (versionName == null) {
return null;
}
NodeId id = nameCache.get(versionName);
InternalVersion v = versionCache.get(id);
if (v == null) {
v = createVersionInstance(versionName);
}
return v;
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class InternalVersionHistoryImpl method getVersion.
/**
* {@inheritDoc}
*/
public synchronized InternalVersion getVersion(Name versionName) throws VersionException {
NodeId versionId = nameCache.get(versionName);
if (versionId == null) {
throw new VersionException("Version " + versionName + " does not exist.");
}
InternalVersion v = versionCache.get(versionId);
if (v == null) {
v = createVersionInstance(versionName);
}
return v;
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class InternalVersionManagerBase method internalCheckin.
/**
* Checks in a node
*
* @param history the version history
* @param node node to checkin
* @param simple flag indicates simple versioning
* @param created optional created date.
* @return internal version
* @throws javax.jcr.RepositoryException if an error occurs
* @see javax.jcr.Node#checkin()
*/
protected InternalVersion internalCheckin(InternalVersionHistoryImpl history, NodeStateEx node, boolean simple, Calendar created) throws RepositoryException {
String versionName = calculateCheckinVersionName(history, node, simple);
InternalVersionImpl v = history.checkin(NameFactoryImpl.getInstance().create("", versionName), node, created);
// check for jcr:activity
if (node.hasProperty(JCR_ACTIVITY)) {
NodeId actId = node.getPropertyValue(JCR_ACTIVITY).getNodeId();
InternalActivityImpl act = (InternalActivityImpl) getItem(actId);
act.addVersion(v);
}
return v;
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class InternalVersionManagerBase method internalCreateActivity.
/**
* Creates a new activity.
*
* @param title title of the new activity
* @return the id of the newly created activity
* @throws RepositoryException if an error occurs
*/
NodeStateEx internalCreateActivity(String title) throws RepositoryException {
WriteOperation operation = startWriteOperation();
try {
// create deep path
NodeId activityId = nodeIdFactory.newNodeId();
NodeStateEx parent = getParentNode(getActivitiesRoot(), activityId.toString(), NameConstants.REP_ACTIVITIES);
Name name = getName(activityId.toString());
// create new activity node in the persistent state
NodeStateEx pNode = InternalActivityImpl.create(parent, name, activityId, title);
// end update
operation.save();
log.debug("Created new activity " + activityId + " with title " + title + ".");
return pNode;
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
operation.close();
}
}
Aggregations