use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class HierarchyManagerImpl method getDepth.
/**
* {@inheritDoc}
*/
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException {
// shortcut
if (id.equals(rootNodeId)) {
return 0;
}
try {
ItemState state = getItemState(id);
NodeId parentId = getParentId(state);
int depth = 0;
while (parentId != null) {
depth++;
state = getItemState(parentId);
parentId = getParentId(state);
}
return depth;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine depth of " + id;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine depth of " + id;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class HierarchyManagerImpl method getRelativeDepth.
/**
* {@inheritDoc}
*/
public int getRelativeDepth(NodeId ancestorId, ItemId descendantId) throws ItemNotFoundException, RepositoryException {
if (ancestorId.equals(descendantId)) {
return 0;
}
int depth = 1;
try {
ItemState state = getItemState(descendantId);
NodeId parentId = getParentId(state);
while (parentId != null) {
if (parentId.equals(ancestorId)) {
return depth;
}
depth++;
state = getItemState(parentId);
parentId = getParentId(state);
}
// not an ancestor
return -1;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class HierarchyManagerImpl method isAncestor.
/**
* {@inheritDoc}
*/
public boolean isAncestor(NodeId nodeId, ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (nodeId.equals(itemId)) {
// can't be ancestor of self
return false;
}
try {
ItemState state = getItemState(itemId);
NodeId parentId = getParentId(state);
while (parentId != null) {
if (parentId.equals(nodeId)) {
return true;
}
state = getItemState(parentId);
parentId = getParentId(state);
}
// not an ancestor
return false;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class NodeImpl method getOrCreateProperty.
/**
* @param name
* @param type
* @param multiValued
* @param exactTypeMatch
* @param status
* @return
* @throws ConstraintViolationException if no applicable property definition
* could be found
* @throws RepositoryException if another error occurs
*/
protected synchronized PropertyImpl getOrCreateProperty(Name name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException {
status.clear();
if (isNew() && !hasProperty(name)) {
// this is a new node and the property does not exist yet
// -> no need to check item manager
PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
PropertyImpl prop = createChildProperty(name, type, def);
status.set(CREATED);
return prop;
}
/*
* Please note, that this implementation does not win a price for beauty
* or speed. It's never a good idea to use exceptions for semantical
* control flow.
* However, compared to the previous version, this one is thread save
* and makes the test/get block atomic in respect to transactional
* commits. the test/set can still fail.
*
* Old Version:
NodeState thisState = (NodeState) state;
if (thisState.hasPropertyName(name)) {
/**
* the following call will throw ItemNotFoundException if the
* current session doesn't have read access
/
return getProperty(name);
}
[...create block...]
*/
PropertyId propId = new PropertyId(getNodeId(), name);
try {
return (PropertyImpl) itemMgr.getItem(propId);
} catch (AccessDeniedException ade) {
throw new ItemNotFoundException(name.toString());
} catch (ItemNotFoundException e) {
// does not exist yet or has been removed transiently:
// find definition for the specified property and (re-)create property
PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
PropertyImpl prop;
if (stateMgr.hasTransientItemStateInAttic(propId)) {
// remove from attic
try {
stateMgr.disposeTransientItemStateInAttic(stateMgr.getAttic().getItemState(propId));
} catch (ItemStateException ise) {
// shouldn't happen because we checked if it is in the attic
throw new RepositoryException(ise);
}
prop = (PropertyImpl) itemMgr.getItem(propId);
PropertyState state = (PropertyState) prop.getOrCreateTransientItemState();
state.setMultiValued(multiValued);
state.setType(type);
getNodeState().addPropertyName(name);
} else {
prop = createChildProperty(name, type, def);
}
status.set(CREATED);
return prop;
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class NodeImpl method getOrCreateTransientItemState.
@Override
protected synchronized ItemState getOrCreateTransientItemState() throws RepositoryException {
synchronized (data) {
if (!isTransient()) {
try {
// make transient (copy-on-write)
NodeState transientState = stateMgr.createTransientNodeState((NodeState) stateMgr.getItemState(getId()), ItemState.STATUS_EXISTING_MODIFIED);
// replace persistent with transient state
data.setState(transientState);
} catch (ItemStateException ise) {
String msg = "failed to create transient state";
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
return getItemState();
}
}
Aggregations