Search in sources :

Example 6 with HierarchyEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry 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);
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) PathNotFoundException(javax.jcr.PathNotFoundException) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 7 with HierarchyEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry in project jackrabbit by apache.

the class ItemImpl method updateId.

/**
     *
     * @param state
     * @throws RepositoryException
     */
private static void updateId(ItemState state) throws RepositoryException {
    HierarchyEntry he = state.getHierarchyEntry();
    while (he.getStatus() != Status.INVALIDATED) {
        he = he.getParent();
        if (he == null) {
            // root reached without intermediate invalidated entry
            return;
        }
    }
    // he is INVALIDATED -> force reloading in order to be aware of id changes
    he.getItemState();
}
Also used : HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Example 8 with HierarchyEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry in project jackrabbit by apache.

the class Clone method persisted.

/**
     * @see Operation#persisted()
     */
@Override
public void persisted() {
    assert status == STATUS_PENDING;
    if (removeExisting) {
        status = STATUS_PERSISTED;
        // invalidate the complete tree -> find root-hierarchy-entry
        HierarchyEntry he = destParentState.getHierarchyEntry();
        while (he.getParent() != null) {
            he = he.getParent();
        }
        he.invalidate(true);
    } else {
        super.persisted();
    }
}
Also used : HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Example 9 with HierarchyEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry in project jackrabbit by apache.

the class Merge method persisted.

/**
     * Invalidates the target nodestate and all descendants.
     *
     * @see Operation#persisted()
     */
public void persisted() {
    assert status == STATUS_PENDING;
    status = STATUS_PERSISTED;
    if (isActivityMerge()) {
        // TODO be more specific about what needs to be invalidated
        // look for the root entry and invalidate the complete tree
        HierarchyEntry entry = nodeState.getNodeEntry();
        while (entry.getParent() != null) {
            entry = entry.getParent();
        }
        entry.invalidate(true);
    } else {
        try {
            NodeEntry vhe = mgr.getVersionHistoryEntry(nodeState);
            if (vhe != null) {
                vhe.invalidate(true);
            }
        } catch (RepositoryException e) {
            log.warn("Error while retrieving VersionHistory entry: {}", e.getMessage());
        }
        nodeState.getHierarchyEntry().invalidate(true);
    }
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) RepositoryException(javax.jcr.RepositoryException) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Example 10 with HierarchyEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry in project jackrabbit by apache.

the class RemoveActivity method persisted.

/**
     * Invalidates the <code>NodeState</code> that has been updated and all
     * its descendants. Second, the parent state gets invalidated.
     *
     * @see org.apache.jackrabbit.jcr2spi.operation.Operation#persisted()
     */
public void persisted() {
    assert status == STATUS_PENDING;
    status = STATUS_PERSISTED;
    // invalidate all references to the removed activity
    while (refs.hasNext()) {
        HierarchyEntry entry = hMgr.lookup(refs.next());
        if (entry != null) {
            entry.invalidate(false);
        }
    }
    // invalidate the activities parent
    parent.getNodeEntry().invalidate(false);
}
Also used : HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Aggregations

HierarchyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)11 RepositoryException (javax.jcr.RepositoryException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)2 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 IteratorChain (org.apache.commons.collections.iterators.IteratorChain)1 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)1 SetMixin (org.apache.jackrabbit.jcr2spi.operation.SetMixin)1 SetPrimaryType (org.apache.jackrabbit.jcr2spi.operation.SetPrimaryType)1 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)1 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)1 Path (org.apache.jackrabbit.spi.Path)1 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)1