Search in sources :

Example 11 with NoSuchItemStateException

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

the class EventStateCollection method createShareableNodeEvents.

//----------------------------< internal >----------------------------------
private void createShareableNodeEvents(NodeState n, ChangeLog changes, ChangeLogBasedHierarchyMgr hmgr, ItemStateManager stateMgr) throws ItemStateException {
    if (n.isShareable()) {
        // check if a share was added or removed
        for (NodeId parentId : n.getAddedShares()) {
            // ignore primary parent id
            if (n.getParentId().equals(parentId)) {
                continue;
            }
            NodeState parent = (NodeState) changes.get(parentId);
            if (parent == null) {
                // happens when mix:shareable is added to an existing node
                // usually the parent node state is in the change log
                // when a node is added to a shared set -> new child node
                // entry on parent node state.
                parent = (NodeState) stateMgr.getItemState(parentId);
            }
            Name ntName = getNodeType(parent, session).getQName();
            EventState es = EventState.childNodeAdded(parentId, getPath(parentId, hmgr), n.getNodeId(), getNameElement(n.getNodeId(), parentId, hmgr), ntName, parent.getMixinTypeNames(), session);
            es.setShareableNode(true);
            events.add(es);
        }
        for (NodeId parentId : n.getRemovedShares()) {
            // parent ids that are not primary
            if (n.getParentId().equals(parentId)) {
                continue;
            }
            NodeState parent = null;
            try {
                parent = (NodeState) changes.get(parentId);
            } catch (NoSuchItemStateException e) {
            // parent has been removed as well
            // ignore and retrieve from stateMgr
            }
            if (parent == null) {
                // happens when mix:shareable is removed from an existing
                // node. Usually the parent node state is in the change log
                // when a node is removed to a shared set -> removed child
                // node entry on parent node state.
                parent = (NodeState) stateMgr.getItemState(parentId);
            }
            Name ntName = getNodeType(parent, session).getQName();
            EventState es = EventState.childNodeRemoved(parentId, getZombiePath(parentId, hmgr), n.getNodeId(), getZombieNameElement(n.getNodeId(), parentId, hmgr), ntName, parent.getMixinTypeNames(), session);
            es.setShareableNode(true);
            events.add(es);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name)

Example 12 with NoSuchItemStateException

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

the class BundleFsPersistenceManager method destroyBundle.

/**
     * {@inheritDoc}
     */
protected synchronized void destroyBundle(NodePropBundle bundle) throws ItemStateException {
    try {
        StringBuffer buf = buildNodeFilePath(null, bundle.getId());
        itemFs.deleteFile(buf.toString());
    } catch (Exception e) {
        if (e instanceof NoSuchItemStateException) {
            throw (NoSuchItemStateException) e;
        }
        String msg = "failed to delete bundle: " + bundle.getId();
        BundleFsPersistenceManager.log.error(msg, e);
        throw new ItemStateException(msg, e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) SQLException(java.sql.SQLException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 13 with NoSuchItemStateException

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

the class MultiIndex method createIndex.

/**
     * Recursively creates an index starting with the NodeState
     * <code>node</code>.
     *
     * @param node     the current NodeState.
     * @param path     the path of the current <code>node</code> state.
     * @param stateMgr the shared item state manager.
     * @param count    the number of nodes already indexed.
     * @return the number of nodes indexed so far.
     * @throws IOException         if an error occurs while writing to the
     *                             index.
     * @throws ItemStateException  if an node state cannot be found.
     * @throws RepositoryException if any other error occurs
     */
private long createIndex(NodeState node, Path path, ItemStateManager stateMgr, long count) throws IOException, ItemStateException, RepositoryException {
    NodeId id = node.getNodeId();
    if (excludedIDs.contains(id)) {
        return count;
    }
    executeAndLog(new AddNode(getTransactionId(), id));
    if (++count % 100 == 0) {
        PathResolver resolver = new DefaultNamePathResolver(handler.getContext().getNamespaceRegistry());
        log.info("indexing... {} ({})", resolver.getJCRPath(path), count);
    }
    if (count % 10 == 0) {
        checkIndexingQueue(true);
    }
    checkVolatileCommit();
    for (ChildNodeEntry child : node.getChildNodeEntries()) {
        Path childPath = PATH_FACTORY.create(path, child.getName(), child.getIndex(), false);
        NodeState childState = null;
        try {
            childState = (NodeState) stateMgr.getItemState(child.getId());
        } catch (NoSuchItemStateException e) {
            handler.getOnWorkspaceInconsistencyHandler().handleMissingChildNode(e, handler, path, node, child);
        } catch (ItemStateException e) {
            // JCR-3268 log bundle corruption and continue
            handler.getOnWorkspaceInconsistencyHandler().logError(e, handler, childPath, node, child);
        }
        if (childState != null) {
            count = createIndex(childState, childPath, stateMgr, count);
        }
    }
    return count;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) PathResolver(org.apache.jackrabbit.spi.commons.conversion.PathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 14 with NoSuchItemStateException

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

the class NodeIndexer method createDoc.

/**
     * Creates a lucene Document.
     *
     * @return the lucene Document with the index layout.
     * @throws RepositoryException if an error occurs while reading property
     *                             values from the <code>ItemStateProvider</code>.
     */
public Document createDoc() throws RepositoryException {
    doNotUseInExcerpt.clear();
    Document doc = new Document();
    doc.setBoost(getNodeBoost());
    // special fields
    // UUID
    doc.add(new IDField(node.getNodeId()));
    try {
        // parent UUID
        if (node.getParentId() == null) {
            // root node
            Field parent = new Field(FieldNames.PARENT, false, "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO);
            parent.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
            doc.add(parent);
            addNodeName(doc, "", "");
        } else if (node.getSharedSet().isEmpty()) {
            addParentChildRelation(doc, node.getParentId());
        } else {
            // shareable node
            for (NodeId id : node.getSharedSet()) {
                addParentChildRelation(doc, id);
            }
            // mark shareable nodes
            doc.add(new Field(FieldNames.SHAREABLE_NODE, false, "", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
        }
    } catch (NoSuchItemStateException e) {
        throwRepositoryException(e);
    } catch (ItemStateException e) {
        throwRepositoryException(e);
    } catch (NamespaceException e) {
    // will never happen, because this.mappings will dynamically add
    // unknown uri<->prefix mappings
    }
    Set<Name> props = node.getPropertyNames();
    for (Name propName : props) {
        if (isIndexed(propName)) {
            PropertyId id = new PropertyId(node.getNodeId(), propName);
            try {
                PropertyState propState = (PropertyState) stateProvider.getItemState(id);
                // beginning with V2
                if (indexFormatVersion.getVersion() >= IndexFormatVersion.V2.getVersion()) {
                    addPropertyName(doc, propState.getName());
                }
                InternalValue[] values = propState.getValues();
                for (InternalValue value : values) {
                    addValue(doc, value, propState.getName());
                }
                if (values.length > 1) {
                    // real multi-valued
                    addMVPName(doc, propState.getName());
                }
            } catch (NoSuchItemStateException e) {
                throwRepositoryException(e);
            } catch (ItemStateException e) {
                throwRepositoryException(e);
            }
        }
    }
    // now add fields that are not used in excerpt (must go at the end)
    for (Fieldable field : doNotUseInExcerpt) {
        doc.add(field);
    }
    return doc;
}
Also used : Document(org.apache.lucene.document.Document) InternalValue(org.apache.jackrabbit.core.value.InternalValue) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Field(org.apache.lucene.document.Field) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) Fieldable(org.apache.lucene.document.Fieldable) NodeId(org.apache.jackrabbit.core.id.NodeId) NamespaceException(javax.jcr.NamespaceException)

Example 15 with NoSuchItemStateException

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

the class XMLPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String propFilePath = buildPropFilePath(id);
    try {
        if (!itemStateFS.isFile(propFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(propFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            PropertyState state = createNew(id);
            readState(walker, state);
            return state;
        } finally {
            in.close();
        }
    } catch (IOException ioe) {
        e = ioe;
    // fall through
    } catch (FileSystemException fse) {
        e = fse;
    // fall through
    }
    String msg = "failed to read property state: " + id.toString();
    log.debug(msg);
    throw new ItemStateException(msg, e);
}
Also used : DOMWalker(org.apache.jackrabbit.core.util.DOMWalker) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InputStream(java.io.InputStream) IOException(java.io.IOException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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