use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class WorkspaceImporter method end.
/**
* {@inheritDoc}
*/
public void end() throws RepositoryException {
if (aborted) {
// the import has been aborted, get outta here...
return;
}
boolean succeeded = false;
try {
// check sanity of workspace/session first
wsp.sanityCheck();
/**
* adjust references that refer to uuids which have been mapped to
* newly generated uuids on import
*/
Iterator<Object> iter = refTracker.getProcessedReferences();
while (iter.hasNext()) {
PropertyState prop = (PropertyState) iter.next();
// being paranoid...
if (prop.getType() != PropertyType.REFERENCE && prop.getType() != PropertyType.WEAKREFERENCE) {
continue;
}
boolean modified = false;
InternalValue[] values = prop.getValues();
InternalValue[] newVals = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
if (adjusted != null) {
newVals[i] = InternalValue.create(adjusted, prop.getType() != PropertyType.REFERENCE);
modified = true;
} else {
// reference doesn't need adjusting, just copy old value
newVals[i] = values[i];
}
}
if (modified) {
prop.setValues(newVals);
itemOps.store(prop);
}
}
refTracker.clear();
// make sure import target is valid according to its definition
itemOps.validate(importTarget);
// finally store the state of the import target
// (the parent of the imported subtree)
itemOps.store(importTarget);
succeeded = true;
} finally {
if (!succeeded) {
// update operation failed, cancel all modifications
aborted = true;
itemOps.cancel();
}
}
if (!aborted) {
// finish update
itemOps.update();
}
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class NodeStateEx method store.
/**
* stores the given persistent state recursively
*
* @param state node state to store
* @throws ItemStateException if an error occurs
*/
private void store(NodeState state, boolean recursively) throws ItemStateException {
if (state.getStatus() != ItemState.STATUS_EXISTING) {
// first store all transient properties
for (Name propName : state.getPropertyNames()) {
PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
stateMgr.store(pstate);
}
}
if (recursively) {
// now store all child node entries
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
store(nstate, true);
}
}
// and store itself
stateMgr.store(state);
}
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class NodeStateEx method reload.
/**
* reloads the given persistent state recursively
*
* @param state node state
* @throws ItemStateException if an error occurs
*/
private void reload(NodeState state) throws ItemStateException {
if (state.getStatus() != ItemState.STATUS_EXISTING) {
// first discard all all transient properties
for (Name propName : state.getPropertyNames()) {
PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
pstate.discard();
}
}
// now reload all child node entries
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
reload(nstate);
}
// and reload itself
state.discard();
}
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class BatchedItemOperations method recursiveRemoveNodeState.
//------------------------------------------------------< private methods >
/**
* Recursively removes the given node state including its properties and
* child nodes.
* <p>
* The removal of child nodes is subject to the following checks:
* access rights, locking & versioning status. Referential integrity
* (references) is checked on commit.
* <p>
* Note that the child node entry refering to <code>targetState</code> is
* <b><i>not</i></b> automatically removed from <code>targetState</code>'s
* parent.
*
* @param targetState
* @throws RepositoryException if an error occurs
*/
private void recursiveRemoveNodeState(NodeState targetState) throws RepositoryException {
if (targetState.hasChildNodeEntries()) {
// remove child nodes
// use temp array to avoid ConcurrentModificationException
ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(targetState.getChildNodeEntries());
// remove from tail to avoid problems with same-name siblings
for (int i = tmp.size() - 1; i >= 0; i--) {
ChildNodeEntry entry = tmp.get(i);
NodeId nodeId = entry.getId();
try {
NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
// check if child node can be removed
// (access rights, locking & versioning status as well
// as retention and hold);
// referential integrity (references) is checked
// on commit
checkRemoveNode(nodeState, targetState.getNodeId(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_HOLD | CHECK_RETENTION);
// remove child node
recursiveRemoveNodeState(nodeState);
} catch (ItemStateException ise) {
String msg = "internal error: failed to retrieve state of " + nodeId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
// remove child node entry
targetState.removeChildNodeEntry(entry.getName(), entry.getIndex());
}
}
// remove properties
// use temp set to avoid ConcurrentModificationException
HashSet<Name> tmp = new HashSet<Name>(targetState.getPropertyNames());
for (Name propName : tmp) {
PropertyId propId = new PropertyId(targetState.getNodeId(), propName);
try {
PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
// remove property entry
targetState.removePropertyName(propId.getName());
// destroy property state
stateMgr.destroy(propState);
} catch (ItemStateException ise) {
String msg = "internal error: failed to retrieve state of " + propId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
// now actually do unlink target state
targetState.setParentId(null);
// destroy target state (pass overlayed state since target state
// might have been modified during unlinking)
stateMgr.destroy(targetState.getOverlayedState());
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class HierarchyManagerImpl method buildPath.
/**
* Adds the path element of an item id to the path currently being built.
* Recursively invoked method that may be overridden by some subclass to
* either return cached responses or add response to cache. On exit,
* <code>builder</code> contains the path of <code>state</code>.
*
* @param builder builder currently being used
* @param state item to find path of
* @param detector path cycle detector
*/
protected void buildPath(PathBuilder builder, ItemState state, CycleDetector detector) throws ItemStateException, RepositoryException {
// shortcut
if (state.getId().equals(rootNodeId)) {
builder.addRoot();
return;
}
NodeId parentId = getParentId(state);
if (parentId == null) {
String msg = "failed to build path of " + state.getId() + ": orphaned item";
log.debug(msg);
throw new ItemNotFoundException(msg);
} else if (detector.checkCycle(parentId)) {
throw new InvalidItemStateException("Path cycle detected: " + parentId);
}
NodeState parent = (NodeState) getItemState(parentId);
// recursively build path of parent
buildPath(builder, parent, detector);
if (state.isNode()) {
NodeState nodeState = (NodeState) state;
NodeId id = nodeState.getNodeId();
ChildNodeEntry entry = getChildNodeEntry(parent, id);
if (entry == null) {
String msg = "failed to build path of " + state.getId() + ": " + parent.getNodeId() + " has no child entry for " + id;
log.debug(msg);
throw new ItemNotFoundException(msg);
}
// add to path
if (entry.getIndex() == 1) {
builder.addLast(entry.getName());
} else {
builder.addLast(entry.getName(), entry.getIndex());
}
} else {
PropertyState propState = (PropertyState) state;
Name name = propState.getName();
// add to path
builder.addLast(name);
}
}
Aggregations