Search in sources :

Example 26 with NodeState

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);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) TermDocs(org.apache.lucene.index.TermDocs) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SAXException(org.xml.sax.SAXException) JournalException(org.apache.jackrabbit.core.journal.JournalException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) RepositoryException(javax.jcr.RepositoryException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidQueryException(javax.jcr.query.InvalidQueryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager)

Example 27 with NodeState

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));
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState)

Example 28 with NodeState

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);
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState)

Example 29 with NodeState

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);
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState)

Example 30 with NodeState

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);
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState)

Aggregations

NodeState (org.apache.jackrabbit.core.state.NodeState)114 RepositoryException (javax.jcr.RepositoryException)53 NodeId (org.apache.jackrabbit.core.id.NodeId)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)44 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)34 Name (org.apache.jackrabbit.spi.Name)28 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)26 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 Path (org.apache.jackrabbit.spi.Path)24 PropertyId (org.apache.jackrabbit.core.id.PropertyId)23 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)16 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)16 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 ArrayList (java.util.ArrayList)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)12 InternalValue (org.apache.jackrabbit.core.value.InternalValue)12 HashSet (java.util.HashSet)10 ItemExistsException (javax.jcr.ItemExistsException)10 IOException (java.io.IOException)8 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)7