Search in sources :

Example 1 with HierarchyManager

use of org.apache.jackrabbit.core.HierarchyManager in project jackrabbit by apache.

the class SearchIndex method getRelativePath.

/**
     * Returns the relative path from <code>nodeState</code> to
     * <code>propState</code>.
     *
     * @param nodeState a node state.
     * @param propState a property state.
     * @return the relative path.
     * @throws RepositoryException if an error occurs while resolving paths.
     * @throws ItemStateException  if an error occurs while reading item
     *                             states.
     */
protected Path getRelativePath(NodeState nodeState, PropertyState propState) throws RepositoryException, ItemStateException {
    HierarchyManager hmgr = getContext().getHierarchyManager();
    Path nodePath = hmgr.getPath(nodeState.getId());
    Path propPath = hmgr.getPath(propState.getId());
    Path p = nodePath.computeRelativePath(propPath);
    // make sure it does not contain indexes
    boolean clean = true;
    Path.Element[] elements = p.getElements();
    for (int i = 0; i < elements.length; i++) {
        if (elements[i].getIndex() != 0) {
            elements[i] = PATH_FACTORY.createElement(elements[i].getName());
            clean = false;
        }
    }
    if (!clean) {
        p = PATH_FACTORY.create(elements);
    }
    return p.getNormalizedPath();
}
Also used : Path(org.apache.jackrabbit.spi.Path) HierarchyManager(org.apache.jackrabbit.core.HierarchyManager) Element(org.w3c.dom.Element)

Example 2 with HierarchyManager

use of org.apache.jackrabbit.core.HierarchyManager in project jackrabbit by apache.

the class LuceneQueryBuilder method createQuery.

/**
     * Creates a lucene {@link org.apache.lucene.search.Query} tree from an
     * abstract query tree.
     *
     * @param root            the root node of the abstract query tree.
     * @param session         of the user executing the query.
     * @param sharedItemMgr   the shared item state manager of the workspace.
     * @param nsMappings      namespace resolver for internal prefixes.
     * @param analyzer        for parsing the query statement of the contains
     *                        function.
     * @param propReg         the property type registry to lookup type
     *                        information.
     * @param synonymProvider the synonym provider or <code>null</code> if node
     *                        is configured.
     * @param  indexFormatVersion  the index format version to be used
     * @return the lucene query tree.
     * @throws RepositoryException if an error occurs during the translation.
     */
public static Query createQuery(QueryRootNode root, SessionImpl session, ItemStateManager sharedItemMgr, NamespaceMappings nsMappings, Analyzer analyzer, PropertyTypeRegistry propReg, SynonymProvider synonymProvider, IndexFormatVersion indexFormatVersion, PerQueryCache cache) throws RepositoryException {
    HierarchyManager hmgr = new HierarchyManagerImpl(RepositoryImpl.ROOT_NODE_ID, sharedItemMgr);
    LuceneQueryBuilder builder = new LuceneQueryBuilder(root, session, sharedItemMgr, hmgr, nsMappings, analyzer, propReg, synonymProvider, indexFormatVersion, cache);
    Query q = builder.createLuceneQuery();
    if (builder.exceptions.size() > 0) {
        StringBuffer msg = new StringBuffer();
        for (Exception exception : builder.exceptions) {
            msg.append(exception.toString()).append('\n');
        }
        throw new RepositoryException("Exception building query: " + msg.toString());
    }
    return q;
}
Also used : HierarchyManager(org.apache.jackrabbit.core.HierarchyManager) RepositoryException(javax.jcr.RepositoryException) HierarchyManagerImpl(org.apache.jackrabbit.core.HierarchyManagerImpl) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ParseException(org.apache.lucene.queryParser.ParseException) RepositoryException(javax.jcr.RepositoryException) NamespaceException(javax.jcr.NamespaceException) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 3 with HierarchyManager

use of org.apache.jackrabbit.core.HierarchyManager in project jackrabbit by apache.

the class ConsistencyCheck method isIgnored.

private boolean isIgnored(NodeId id) {
    try {
        final HierarchyManager hierarchyManager = handler.getContext().getHierarchyManager();
        final Path path = hierarchyManager.getPath(id);
        for (Path excludedPath : ignoredPaths) {
            if (excludedPath.isEquivalentTo(path) || excludedPath.isAncestorOf(path)) {
                return true;
            }
        }
    } catch (RepositoryException ignored) {
    }
    return false;
}
Also used : Path(org.apache.jackrabbit.spi.Path) HierarchyManager(org.apache.jackrabbit.core.HierarchyManager) RepositoryException(javax.jcr.RepositoryException)

Example 4 with HierarchyManager

use of org.apache.jackrabbit.core.HierarchyManager in project jackrabbit by apache.

the class ConsistencyCheck method isExcluded.

private boolean isExcluded(NodeId id) {
    try {
        final HierarchyManager hierarchyManager = handler.getContext().getHierarchyManager();
        final Path path = hierarchyManager.getPath(id);
        for (Path excludedPath : excludedPaths) {
            if (excludedPath.isEquivalentTo(path) || excludedPath.isAncestorOf(path)) {
                return true;
            }
        }
    } catch (RepositoryException ignored) {
    }
    return false;
}
Also used : Path(org.apache.jackrabbit.spi.Path) HierarchyManager(org.apache.jackrabbit.core.HierarchyManager) RepositoryException(javax.jcr.RepositoryException)

Example 5 with HierarchyManager

use of org.apache.jackrabbit.core.HierarchyManager in project jackrabbit by apache.

the class SessionItemStateManager method getIdOfRootTransientNodeState.

/**
     * Returns the id of the root of the minimal subtree including all
     * transient states.
     *
     * @return id of nearest common ancestor of all transient states or null
     *         if there's no transient state.
     * @throws RepositoryException if an error occurs
     */
public NodeId getIdOfRootTransientNodeState() throws RepositoryException {
    if (transientStore.isEmpty()) {
        return null;
    }
    // short cut
    if (transientStore.containsKey(hierMgr.getRootNodeId())) {
        return hierMgr.getRootNodeId();
    }
    // the nearest common ancestor of all transient states
    // must be either
    // a) a node state with STATUS_EXISTING_MODIFIED or STATUS_STALE_DESTROYED, or
    // b) the parent node of a property state with STATUS_EXISTING_MODIFIED or STATUS_STALE_DESTROYED
    // collect all candidates based on above criteria
    Collection<NodeId> candidateIds = new LinkedList<NodeId>();
    try {
        HierarchyManager hierMgr = getHierarchyMgr();
        ItemState[] states = transientStore.values().toArray(new ItemState[0]);
        for (ItemState state : states) {
            if (state.getStatus() == ItemState.STATUS_EXISTING_MODIFIED || state.getStatus() == ItemState.STATUS_STALE_DESTROYED) {
                NodeId nodeId;
                if (state.isNode()) {
                    nodeId = (NodeId) state.getId();
                } else {
                    nodeId = state.getParentId();
                }
                // remove any descendant candidates
                boolean skip = false;
                for (Iterator<NodeId> it = candidateIds.iterator(); it.hasNext(); ) {
                    NodeId id = it.next();
                    if (nodeId.equals(id) || hierMgr.isAncestor(id, nodeId)) {
                        // already a candidate or a descendant thereof
                        // => skip
                        skip = true;
                        break;
                    }
                    if (hierMgr.isAncestor(nodeId, id)) {
                        // candidate is a descendant => remove
                        it.remove();
                    }
                }
                if (!skip) {
                    // add to candidates
                    candidateIds.add(nodeId);
                }
            }
        }
        if (candidateIds.size() == 1) {
            return candidateIds.iterator().next();
        }
        // pick (any) candidate with shortest path to start with
        NodeId candidateId = null;
        for (NodeId id : candidateIds) {
            if (candidateId == null) {
                candidateId = id;
            } else {
                if (hierMgr.getDepth(id) < hierMgr.getDepth(candidateId)) {
                    candidateId = id;
                }
            }
        }
        // starting with this candidate closest to root, find first parent
        // which is an ancestor of all candidates
        NodeState state = (NodeState) getItemState(candidateId);
        NodeId parentId = state.getParentId();
        boolean continueWithParent = false;
        while (parentId != null) {
            for (NodeId id : candidateIds) {
                if (hierMgr.getRelativeDepth(parentId, id) == -1) {
                    continueWithParent = true;
                    break;
                }
            }
            if (continueWithParent) {
                state = (NodeState) getItemState(parentId);
                parentId = state.getParentId();
                continueWithParent = false;
            } else {
                break;
            }
        }
        return parentId;
    } catch (ItemStateException e) {
        throw new RepositoryException("failed to determine common root of transient changes", e);
    }
}
Also used : CachingHierarchyManager(org.apache.jackrabbit.core.CachingHierarchyManager) ZombieHierarchyManager(org.apache.jackrabbit.core.ZombieHierarchyManager) HierarchyManager(org.apache.jackrabbit.core.HierarchyManager) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) LinkedList(java.util.LinkedList) InvalidItemStateException(javax.jcr.InvalidItemStateException)

Aggregations

HierarchyManager (org.apache.jackrabbit.core.HierarchyManager)5 RepositoryException (javax.jcr.RepositoryException)4 Path (org.apache.jackrabbit.spi.Path)3 LinkedList (java.util.LinkedList)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 NamespaceException (javax.jcr.NamespaceException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 CachingHierarchyManager (org.apache.jackrabbit.core.CachingHierarchyManager)1 HierarchyManagerImpl (org.apache.jackrabbit.core.HierarchyManagerImpl)1 ZombieHierarchyManager (org.apache.jackrabbit.core.ZombieHierarchyManager)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1 ParseException (org.apache.lucene.queryParser.ParseException)1 Element (org.w3c.dom.Element)1