use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class SearchIndex method retrieveAggregateRoot.
/**
* Retrieves the root of the indexing aggregate for <code>removedIds</code>
* and puts it into <code>map</code>.
*
* @param removedIds the ids of removed nodes.
* @param aggregates aggregate roots are collected in this map
*/
protected void retrieveAggregateRoot(Set<NodeId> removedIds, Map<NodeId, NodeState> aggregates) {
if (removedIds.isEmpty() || indexingConfig == null) {
return;
}
AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
if (aggregateRules == null) {
return;
}
int found = 0;
long time = System.currentTimeMillis();
try {
CachingMultiIndexReader reader = index.getIndexReader();
try {
Term aggregateIds = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
TermDocs tDocs = reader.termDocs();
try {
ItemStateManager ism = getContext().getItemStateManager();
for (NodeId id : removedIds) {
aggregateIds = aggregateIds.createTerm(id.toString());
tDocs.seek(aggregateIds);
while (tDocs.next()) {
Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
NodeId nId = new NodeId(doc.get(FieldNames.UUID));
NodeState nodeState = (NodeState) ism.getItemState(nId);
aggregates.put(nId, nodeState);
found++;
// JCR-2989 Support for embedded index aggregates
int sizeBefore = aggregates.size();
retrieveAggregateRoot(nodeState, aggregates);
found += aggregates.size() - sizeBefore;
}
}
} finally {
tDocs.close();
}
} finally {
reader.release();
}
} catch (NoSuchItemStateException e) {
log.info("Exception while retrieving aggregate roots. Node is not available {}.", e.getMessage());
} catch (Exception e) {
log.warn("Exception while retrieving aggregate roots", e);
}
time = System.currentTimeMillis() - time;
log.debug("Retrieved {} aggregate roots in {} ms.", found, time);
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class CachingHierarchyManagerTest method testCloneAndRemove.
/**
* Clone a node, cache its path and remove it afterwards. Should remove
* the cached path as well.
*/
public void testCloneAndRemove() throws Exception {
StaticItemStateManager ism = new StaticItemStateManager();
cache = new CachingHierarchyManager(ism.getRootNodeId(), ism);
ism.setContainer(cache);
NodeState a1 = ism.addNode(ism.getRoot(), "a1");
NodeState a2 = ism.addNode(ism.getRoot(), "a2");
NodeState b1 = ism.addNode(a1, "b1");
b1.addShare(b1.getParentId());
ism.cloneNode(b1, a2, "b2");
Path path1 = toPath("/a1/b1");
Path path2 = toPath("/a2/b2");
assertNotNull(cache.resolvePath(path1));
assertTrue(cache.isCached(b1.getNodeId(), path1));
ism.removeNode(b1);
assertNull(cache.resolvePath(path1));
assertNotNull(cache.resolvePath(path2));
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class CachingHierarchyManagerTest method testOrderBefore.
/**
* Reorder child nodes and verify that cached paths are still adequate.
*/
public void testOrderBefore() throws Exception {
StaticItemStateManager ism = new StaticItemStateManager();
cache = new CachingHierarchyManager(ism.getRootNodeId(), ism);
ism.setContainer(cache);
NodeState a = ism.addNode(ism.getRoot(), "a");
NodeState b1 = ism.addNode(a, "b");
NodeState b2 = ism.addNode(a, "b");
NodeState b3 = ism.addNode(a, "b");
Path path = cache.getPath(b1.getNodeId());
assertEquals(toPath("/a/b"), path);
ism.orderBefore(b2, b1);
ism.orderBefore(b1, b3);
path = cache.getPath(b1.getNodeId());
assertEquals(toPath("/a/b[2]"), path);
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class CachingHierarchyManagerTest method testRename.
/**
* Rename a node and verify that cached path is adapted.
*/
public void testRename() throws Exception {
StaticItemStateManager ism = new StaticItemStateManager();
cache = new CachingHierarchyManager(ism.getRootNodeId(), ism);
ism.setContainer(cache);
NodeState a1 = ism.addNode(ism.getRoot(), "a1");
NodeState b1 = ism.addNode(a1, "b");
NodeState b2 = ism.addNode(a1, "b");
Path path = cache.getPath(b1.getNodeId());
assertEquals(toPath("/a1/b"), path);
path = cache.getPath(b2.getNodeId());
assertEquals(toPath("/a1/b[2]"), path);
ism.renameNode(b1, "b1");
assertTrue(cache.isCached(b1.getNodeId(), null));
assertTrue(cache.isCached(b2.getNodeId(), null));
path = cache.getPath(b1.getNodeId());
assertEquals(toPath("/a1/b1"), path);
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class CachingHierarchyManagerTest method testMove.
/**
* Move a node and verify that cached path is adapted.
*/
public void testMove() throws Exception {
StaticItemStateManager ism = new StaticItemStateManager();
cache = new CachingHierarchyManager(ism.getRootNodeId(), ism);
ism.setContainer(cache);
NodeState a1 = ism.addNode(ism.getRoot(), "a1");
NodeState a2 = ism.addNode(ism.getRoot(), "a2");
NodeState b1 = ism.addNode(a1, "b1");
Path path = cache.getPath(b1.getNodeId());
assertEquals(toPath("/a1/b1"), path);
ism.moveNode(b1, a2, "b2");
path = cache.getPath(b1.getNodeId());
assertEquals(toPath("/a2/b2"), path);
}
Aggregations