Search in sources :

Example 66 with ItemStateException

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

the class EventState method nodeMovedWithInfo.

/**
     * Creates a new {@link javax.jcr.observation.Event} of type
     * <code>NODE_MOVED</code>. The parent node associated with this event type
     * is the parent node of the destination of the move!
     *
     * @param parentId the id of the parent node associated with this
     *                 <code>EventState</code>.
     * @param destPath the path of the destination of the move.
     * @param childId  the id of the child node associated with this event.
     * @param srcPath  the path of the source of the move.
     * @param nodeType the node type of the parent node.
     * @param mixins   mixins assigned to the parent node.
     * @param session  the session that removed the node.
     * @param external flag indicating whether this is an external event
     * @return an <code>EventState</code> instance.
     * @throws ItemStateException if <code>destPath</code> does not have a
     *                            parent.
     */
public static EventState nodeMovedWithInfo(NodeId parentId, Path destPath, NodeId childId, Path srcPath, Name nodeType, Set<Name> mixins, Session session, boolean external) throws ItemStateException {
    try {
        EventState es = nodeMoved(parentId, destPath.getAncestor(1), childId, destPath, nodeType, mixins, session, external);
        Map<String, InternalValue> info = new HashMap<String, InternalValue>();
        info.put(SRC_ABS_PATH, InternalValue.create(srcPath));
        info.put(DEST_ABS_PATH, InternalValue.create(destPath));
        es.setInfo(info);
        return es;
    } catch (RepositoryException e) {
        // should never happen actually
        String msg = "Unable to resolve parent for path: " + destPath;
        log.error(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 67 with ItemStateException

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

the class PersistenceCopier method copy.

/**
     * Recursively copies the identified node and all its descendants.
     * Explicitly excluded nodes and nodes that have already been copied
     * are automatically skipped.
     *
     * @param id identifier of the node to be copied
     * @throws RepositoryException if the copy operation fails
     */
public void copy(NodeId id) throws RepositoryException {
    if (!exclude.contains(id)) {
        try {
            NodeState node = source.load(id);
            for (ChildNodeEntry entry : node.getChildNodeEntries()) {
                copy(entry.getId());
            }
            copy(node);
            exclude.add(id);
        } catch (ItemStateException e) {
            throw new RepositoryException("Unable to copy " + id, e);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 68 with ItemStateException

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

the class ConsistencyCheckerImpl method repair.

/**
     * Repair any errors found during a {@link #check}. Should be run after a {#check} and
     * (if needed) {@link #doubleCheckErrors}.
     *
     * @throws RepositoryException
     */
public void repair() throws RepositoryException {
    checkLostNFound();
    bundles = new HashMap<NodeId, NodePropBundle>();
    if (hasRepairableErrors()) {
        boolean successful = false;
        final CheckerUpdate update = new CheckerUpdate();
        try {
            eventChannel.updateCreated(update);
            for (ConsistencyCheckerError error : errors) {
                if (error.isRepairable()) {
                    try {
                        error.repair(update.getChanges());
                        info(null, "Repairing " + error);
                    } catch (ItemStateException e) {
                        error(null, "Failed to repair error: " + error, e);
                    }
                }
            }
            final ChangeLog changes = update.getChanges();
            if (changes.hasUpdates()) {
                eventChannel.updatePrepared(update);
                for (NodePropBundle bundle : bundles.values()) {
                    storeBundle(bundle);
                }
                update.setAttribute(ATTRIBUTE_UPDATE_SIZE, changes.getUpdateSize());
                successful = true;
            }
        } catch (ClusterException e) {
            throw new RepositoryException("Cannot create update", e);
        } finally {
            if (successful) {
                eventChannel.updateCommitted(update, "checker@");
            } else {
                eventChannel.updateCancelled(update);
            }
        }
    }
}
Also used : ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) NodeId(org.apache.jackrabbit.core.id.NodeId) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) RepositoryException(javax.jcr.RepositoryException) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 69 with ItemStateException

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

the class BundleFsPersistenceManager method storeBundle.

/**
     * {@inheritDoc}
     */
protected synchronized void storeBundle(NodePropBundle bundle) throws ItemStateException {
    try {
        StringBuffer buf = buildNodeFolderPath(null, bundle.getId());
        buf.append('.');
        buf.append(NODEFILENAME);
        String fileName = buf.toString();
        String dir = fileName.substring(0, fileName.lastIndexOf(FileSystem.SEPARATOR_CHAR));
        if (!itemFs.exists(dir)) {
            itemFs.createFolder(dir);
        }
        OutputStream out = itemFs.getOutputStream(fileName);
        try {
            binding.writeBundle(out, bundle);
        } finally {
            out.close();
        }
    } catch (Exception e) {
        String msg = "failed to write bundle: " + bundle.getId();
        BundleFsPersistenceManager.log.error(msg, e);
        throw new ItemStateException(msg, e);
    }
}
Also used : OutputStream(java.io.OutputStream) 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 70 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException 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)

Aggregations

ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)141 RepositoryException (javax.jcr.RepositoryException)87 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)86 NodeId (org.apache.jackrabbit.core.id.NodeId)44 NodeState (org.apache.jackrabbit.core.state.NodeState)39 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)31 IOException (java.io.IOException)28 InvalidItemStateException (javax.jcr.InvalidItemStateException)27 PropertyState (org.apache.jackrabbit.core.state.PropertyState)24 SQLException (java.sql.SQLException)23 PropertyId (org.apache.jackrabbit.core.id.PropertyId)22 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)19 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)19 Name (org.apache.jackrabbit.spi.Name)17 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 InternalValue (org.apache.jackrabbit.core.value.InternalValue)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)13 InputStream (java.io.InputStream)12