Search in sources :

Example 6 with NoSuchItemStateException

use of org.apache.jackrabbit.core.state.NoSuchItemStateException 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);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 7 with NoSuchItemStateException

use of org.apache.jackrabbit.core.state.NoSuchItemStateException 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);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 8 with NoSuchItemStateException

use of org.apache.jackrabbit.core.state.NoSuchItemStateException 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);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 9 with NoSuchItemStateException

use of org.apache.jackrabbit.core.state.NoSuchItemStateException 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 10 with NoSuchItemStateException

use of org.apache.jackrabbit.core.state.NoSuchItemStateException in project jackrabbit by apache.

the class PropertyValueOperand method getPropertyState.

/**
     * Returns the property state for the given score node or <code>null</code>
     * if none exists.
     *
     * @param sn the current score node.
     * @param context the evaluation context.
     * @return the property state or <code>null</code>.
     * @throws RepositoryException if an error occurs while reading.
     */
public final PropertyState getPropertyState(ScoreNode sn, EvaluationContext context) throws RepositoryException {
    ItemStateManager ism = context.getItemStateManager();
    PropertyId propId = new PropertyId(sn.getNodeId(), operand.getPropertyQName());
    try {
        return (PropertyState) ism.getItemState(propId);
    } catch (NoSuchItemStateException e) {
        return null;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)37 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)31 RepositoryException (javax.jcr.RepositoryException)17 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NodeState (org.apache.jackrabbit.core.state.NodeState)13 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)11 PropertyState (org.apache.jackrabbit.core.state.PropertyState)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 InvalidItemStateException (javax.jcr.InvalidItemStateException)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 ItemState (org.apache.jackrabbit.core.state.ItemState)8 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)8 SQLException (java.sql.SQLException)7 PropertyId (org.apache.jackrabbit.core.id.PropertyId)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Name (org.apache.jackrabbit.spi.Name)6 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 FilterInputStream (java.io.FilterInputStream)4