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();
}
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class VersionIteratorImpl method nextVersion.
/**
* {@inheritDoc}
*/
public Version nextVersion() {
if (versions.isEmpty()) {
throw new NoSuchElementException();
}
NodeId id = versions.removeFirst();
pos++;
try {
return (Version) session.getNodeById(id);
} catch (RepositoryException e) {
throw new ConcurrentModificationException("Unable to provide element: " + e.toString());
}
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class VersionManagerImplBase method checkoutCheckin.
/**
* Performs a checkin or checkout operation. if <code>checkin</code> is
* <code>true</code> the node is checked in. if <code>checkout</code> is
* <code>true</code> the node is checked out. if both flags are <code>true</code>
* the checkin is performed prior to the checkout and the operation is
* equivalent to a checkpoint operation.
*
* @param state node state
* @param checkin if <code>true</code> the node is checked in.
* @param checkout if <code>true</code> the node is checked out.
* @param created create time of the new version (if any),
* or <code>null</code> for the current time
* @return the node id of the base version or <code>null</code> for a pure
* checkout.
* @throws RepositoryException if an error occurs
*/
protected NodeId checkoutCheckin(NodeStateEx state, boolean checkin, boolean checkout, Calendar created) throws RepositoryException {
assert (checkin || checkout);
// check if versionable
boolean isFull = checkVersionable(state);
// check flags
if (isCheckedOut(state)) {
if (checkout && !checkin) {
// pure checkout
String msg = safeGetJCRPath(state) + ": Node is already checked-out. ignoring.";
log.debug(msg);
return null;
}
} else {
if (!checkout) {
// pure checkin
String msg = safeGetJCRPath(state) + ": Node is already checked-in. ignoring.";
log.debug(msg);
if (isFull) {
return getBaseVersionId(state);
} else {
// get base version from version history
return vMgr.getHeadVersionOfNode(state.getNodeId()).getId();
}
}
checkin = false;
}
NodeId baseId = isFull && checkout ? vMgr.canCheckout(state, currentActivity) : null;
// perform operation
WriteOperation ops = startWriteOperation();
try {
// the 2 cases could be consolidated but is clearer this way
if (checkin) {
// check for configuration
if (state.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION)) {
// collect the base versions and the the rep:versions property of the configuration
Set<NodeId> baseVersions = collectBaseVersions(state);
InternalValue[] vs = new InternalValue[baseVersions.size()];
int i = 0;
for (NodeId id : baseVersions) {
vs[i++] = InternalValue.create(id);
}
state.setPropertyValues(NameConstants.REP_VERSIONS, PropertyType.REFERENCE, vs);
state.store();
}
InternalVersion v = vMgr.checkin(session, state, created);
baseId = v.getId();
if (isFull) {
state.setPropertyValue(NameConstants.JCR_BASEVERSION, InternalValue.create(baseId));
state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
state.removeProperty(NameConstants.JCR_ACTIVITY);
}
}
if (checkout) {
if (isFull) {
state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[] { InternalValue.create(baseId) });
if (currentActivity != null) {
state.setPropertyValue(NameConstants.JCR_ACTIVITY, InternalValue.create(currentActivity));
}
}
}
state.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(checkout));
state.store();
ops.save();
return baseId;
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
}
Aggregations