use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class InternalXAVersionManager method makeLocalCopy.
/**
* Make a local copy of an internal version item. This will recreate the
* (global) version item with state information from our own state
* manager.
* @param history source
* @return the new copy
* @throws RepositoryException if an error occurs
*/
private InternalVersionHistoryImpl makeLocalCopy(InternalVersionHistoryImpl history) throws RepositoryException {
VersioningLock.ReadLock lock = acquireReadLock();
try {
NodeState state = (NodeState) stateMgr.getItemState(history.getId());
NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null);
return new InternalVersionHistoryImpl(this, stateEx);
} catch (ItemStateException e) {
throw new RepositoryException("Unable to make local copy", e);
} finally {
lock.release();
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class InternalXAVersionManager method makeLocalCopy.
/**
* Make a local copy of an internal version item. This will recreate the
* (global) version item with state information from our own state
* manager.
* @param act source
* @return the new copy
* @throws RepositoryException if an error occurs
*/
private InternalActivityImpl makeLocalCopy(InternalActivityImpl act) throws RepositoryException {
VersioningLock.ReadLock lock = acquireReadLock();
try {
NodeState state = (NodeState) stateMgr.getItemState(act.getId());
NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null);
return new InternalActivityImpl(this, stateEx);
} catch (ItemStateException e) {
throw new RepositoryException("Unable to make local copy", e);
} finally {
lock.release();
}
}
use of javax.jcr.RepositoryException 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 javax.jcr.RepositoryException in project jackrabbit by apache.
the class InternalVersionManagerBase method startWriteOperation.
/**
* Starts a write operation by acquiring the write lock and setting the
* item state manager to the "edit" state. If something goes wrong, the
* write lock is released and an exception is thrown.
* <p>
* The pattern for using this method and the returned helper instance is:
* <pre>
* WriteOperation operation = startWriteOperation();
* try {
* ...
* operation.save(); // if everything is OK
* ...
* } catch (...) {
* ...
* } finally {
* operation.close();
* }
* </pre>
*
* @return write operation helper
* @throws RepositoryException if the write operation could not be started
*/
private WriteOperation startWriteOperation() throws RepositoryException {
boolean success = false;
VersioningLock.WriteLock lock = acquireWriteLock();
try {
stateMgr.edit();
success = true;
return new WriteOperation(lock);
} catch (IllegalStateException e) {
throw new RepositoryException("Unable to start edit operation.", e);
} finally {
if (!success) {
lock.release();
}
}
}
use of javax.jcr.RepositoryException 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