use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class PropertyImpl method setInternalValues.
/**
*
* @param qValues
* @param valueType
* @throws ConstraintViolationException
* @throws RepositoryException
*/
private void setInternalValues(QValue[] qValues, int valueType) throws ConstraintViolationException, RepositoryException {
// check for null value
if (qValues == null) {
// setting a property to null removes it automatically
remove();
return;
}
// modify the state of this property
Operation op = SetPropertyValue.create(getPropertyState(), qValues, valueType);
session.getSessionItemStateManager().execute(op);
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class NodeImpl method createProperty.
/**
*
* @param qName
* @param type
* @param def
* @param qvs
* @return
* @throws PathNotFoundException
* @throws ConstraintViolationException
* @throws RepositoryException
*/
private Property createProperty(Name qName, int type, QPropertyDefinition def, QValue[] qvs) throws ConstraintViolationException, RepositoryException {
Operation op = AddProperty.create(getNodeState(), qName, type, def, qvs);
session.getSessionItemStateManager().execute(op);
return getProperty(qName);
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class WorkspaceImpl method move.
/**
* @see javax.jcr.Workspace#move(String, String)
*/
public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
session.checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
session.checkIsAlive();
Path srcPath = session.getQPath(srcAbsPath);
Path destPath = session.getQPath(destAbsPath);
Operation op = Move.create(srcPath, destPath, getHierarchyManager(), getPathResolver(), false);
getUpdatableItemStateManager().execute(op);
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class SessionImporter method resolveUUIDConflict.
//----------------------------------------------------< Private methods >---
/**
* @param parent
* @param conflicting
* @param nodeInfo
* @return
* @throws RepositoryException
*/
NodeState resolveUUIDConflict(NodeState parent, NodeEntry conflicting, NodeInfo nodeInfo) throws ItemExistsException, RepositoryException {
NodeState nodeState;
switch(uuidBehavior) {
case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
String originalUUID = nodeInfo.getUUID();
String newUUID = UUID.randomUUID().toString();
// reset id on nodeInfo to force creation with new uuid:
nodeInfo.setUUID(newUUID);
nodeState = importNode(nodeInfo, parent);
if (nodeState != null) {
// remember uuid mapping
refTracker.mappedUUIDs(originalUUID, newUUID);
}
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
String msg = "a node with uuid " + nodeInfo.getUUID() + " already exists!";
log.debug(msg);
throw new ItemExistsException(msg);
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
// make sure conflicting node is not importTarget or an ancestor thereof
Path p0 = importTarget.getPath();
Path p1 = conflicting.getPath();
if (p1.equals(p0) || p1.isAncestorOf(p0)) {
msg = "cannot remove ancestor node";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
// do remove conflicting (recursive) including validation check
try {
Operation op = Remove.create(conflicting.getNodeState());
stateMgr.execute(op);
} catch (ItemNotFoundException e) {
// conflicting does not exist any more. no need for a removal
}
// create new with given uuid:
nodeState = importNode(nodeInfo, parent);
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
if (conflicting.getNodeState().isRoot()) {
msg = "Root node cannot be replaced";
log.debug(msg);
throw new RepositoryException(msg);
}
// 'replace' current parent with parent of conflicting
parent = conflicting.getParent().getNodeState();
// do remove conflicting (recursive), including validation checks
Operation op = Remove.create(conflicting.getNodeState());
stateMgr.execute(op);
// create new with given uuid at same location as conflicting
nodeState = importNode(nodeInfo, parent);
break;
default:
msg = "Unknown uuidBehavior: " + uuidBehavior;
log.debug(msg);
throw new RepositoryException(msg);
}
return nodeState;
}
use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.
the class TransientItemStateManager method getChangeLog.
/**
* Create the change log for the tree starting at <code>target</code>. This
* includes a check if the ChangeLog to be created is totally 'self-contained'
* and independent; items within the scope of this update operation (i.e.
* below the target) must not have dependencies outside of this tree (e.g.
* moving a node requires that the target node including both old and new
* parents are saved).
*
* @param target
* @param throwOnStale Throws InvalidItemStateException if either the given
* <code>ItemState</code> or any of its descendants is stale and the flag is true.
* @return
* @throws InvalidItemStateException if a stale <code>ItemState</code> is
* encountered while traversing the state hierarchy. The <code>changeLog</code>
* might have been populated with some transient item states. A client should
* therefore not reuse the <code>changeLog</code> if such an exception is thrown.
* @throws RepositoryException if <code>state</code> is a new item state.
*/
ChangeLog getChangeLog(ItemState target, boolean throwOnStale) throws InvalidItemStateException, ConstraintViolationException, RepositoryException {
// fail-fast test: check status of this item's state
if (target.getStatus() == Status.NEW) {
String msg = "Cannot save/revert an item with status NEW (" + target + ").";
log.debug(msg);
throw new RepositoryException(msg);
}
if (throwOnStale && Status.isStale(target.getStatus())) {
String msg = "Attempt to save/revert an item, that has been externally modified (" + target + ").";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
Set<Operation> ops = new LinkedHashSet<Operation>();
Set<ItemState> affectedStates = new LinkedHashSet<ItemState>();
HierarchyEntry he = target.getHierarchyEntry();
if (he.getParent() == null) {
// simplicity. collecting ops, states can be omitted.
if (throwOnStale && !staleStates.isEmpty()) {
String msg = "Cannot save changes: States has been modified externally.";
log.debug(msg);
throw new InvalidItemStateException(msg);
} else {
affectedStates.addAll(staleStates);
}
ops.addAll(operations);
affectedStates.addAll(addedStates);
affectedStates.addAll(modifiedStates);
affectedStates.addAll(removedStates);
} else {
// - check if there is a stale state in the scope (save only)
if (throwOnStale) {
for (ItemState state : staleStates) {
if (containedInTree(target, state)) {
String msg = "Cannot save changes: States has been modified externally.";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
}
}
// - collect all affected states within the scope of save/undo
Iterator[] its = new Iterator[] { addedStates.iterator(), removedStates.iterator(), modifiedStates.iterator() };
IteratorChain chain = new IteratorChain(its);
if (!throwOnStale) {
chain.addIterator(staleStates.iterator());
}
while (chain.hasNext()) {
ItemState state = (ItemState) chain.next();
if (containedInTree(target, state)) {
affectedStates.add(state);
}
}
// changelog.
for (Operation op : operations) {
Collection<ItemState> opStates = op.getAffectedItemStates();
for (ItemState state : opStates) {
if (affectedStates.contains(state)) {
// operation needs to be included
if (!affectedStates.containsAll(opStates)) {
// incomplete changelog: need to save a parent as well
String msg = "ChangeLog is not self contained.";
throw new ConstraintViolationException(msg);
}
// no violation: add operation an stop iteration over
// all affected states present in the operation.
ops.add(op);
break;
}
}
}
}
ChangeLog cl = new ChangeLog(target, ops, affectedStates);
return cl;
}
Aggregations