use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class WorkspaceItemStateFactory method createNodeState.
/**
* Creates the node with information retrieved from the <code>RepositoryService</code>.
*/
public NodeState createNodeState(NodeId nodeId, NodeEntry entry) throws ItemNotFoundException, RepositoryException {
try {
Entry<NodeInfo> cached = cache.getNodeInfo(nodeId);
ItemInfo info;
if (isUpToDate(cached, entry)) {
info = cached.info;
} else {
// otherwise retrieve item info from service and cache the whole batch
Iterator<? extends ItemInfo> infos = service.getItemInfos(sessionInfo, nodeId);
info = first(infos, cache, entry.getGeneration());
if (info == null || !info.denotesNode()) {
throw new ItemNotFoundException("NodeId: " + nodeId);
}
}
assertMatchingPath(info, entry);
return createNodeState((NodeInfo) info, entry);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(e);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class WorkspaceItemStateFactory method createDeepNodeState.
/**
* Creates the node with information retrieved from the <code>RepositoryService</code>.
* Intermediate entries are created as needed.
*/
public NodeState createDeepNodeState(NodeId nodeId, NodeEntry anyParent) throws ItemNotFoundException, RepositoryException {
try {
// Get item info from cache
Iterator<? extends ItemInfo> infos = null;
Entry<NodeInfo> cached = cache.getNodeInfo(nodeId);
ItemInfo info;
if (cached == null) {
// or from service if not in cache
infos = service.getItemInfos(sessionInfo, nodeId);
info = first(infos, null, 0);
if (info == null || !info.denotesNode()) {
throw new ItemNotFoundException("NodeId: " + nodeId);
}
} else {
info = cached.info;
}
// Build the hierarchy entry for the item info
HierarchyEntry entry = createHierarchyEntries(info, anyParent);
if (entry == null || !entry.denotesNode()) {
throw new ItemNotFoundException("HierarchyEntry does not belong to any existing ItemInfo. No ItemState was created.");
} else {
// Now we can check whether the item info from the cache is up to date
long generation = entry.getGeneration();
if (isOutdated(cached, entry)) {
// if not, retrieve the item info from the service and put the whole batch into the cache
infos = service.getItemInfos(sessionInfo, nodeId);
info = first(infos, cache, generation);
} else if (infos != null) {
// Otherwise put the whole batch retrieved from the service earlier into the cache
cache.put(info, generation);
first(infos, cache, generation);
}
assertMatchingPath(info, entry);
return createNodeState((NodeInfo) info, (NodeEntry) entry);
}
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(e);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ReadTest method testReadNonExistingNode2.
public void testReadNonExistingNode2() throws RepositoryException {
NodeId nid = getNodeId(testPath + "/non-existing");
try {
rs.getNodeInfo(si, nid);
fail();
} catch (ItemNotFoundException e) {
// ok
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class LockManagerImpl method getLock.
/**
* {@inheritDoc}
*/
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
acquire();
try {
SessionImpl session = (SessionImpl) node.getSession();
Path path = getPath(session, node.getId());
PathMap.Element<LockInfo> element = lockMap.map(path, false);
LockInfo info = element.get();
if (info != null && (element.hasPath(path) || info.isDeep())) {
NodeImpl lockHolder = (NodeImpl) session.getItemManager().getItem(info.getId());
return new LockImpl(info, lockHolder);
} else {
throw new LockException("Node not locked: " + node);
}
} catch (ItemNotFoundException e) {
throw new LockException("Node not locked: " + node);
} finally {
release();
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class LockManagerImpl method holdsLock.
/**
* {@inheritDoc}
*/
public boolean holdsLock(NodeImpl node) throws RepositoryException {
acquire();
try {
SessionImpl session = (SessionImpl) node.getSession();
PathMap.Element<LockInfo> element = lockMap.map(getPath(session, node.getId()), true);
if (element == null) {
return false;
}
return element.get() != null;
} catch (ItemNotFoundException e) {
return false;
} finally {
release();
}
}
Aggregations