Search in sources :

Example 1 with NodeDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.

the class LockOperation method performVoid.

@Override
public void performVoid() throws RepositoryException {
    session.refresh(true);
    NodeDelegate node = session.getNode(path);
    if (node != null) {
        performVoid(node);
    } else {
        throw new PathNotFoundException("Node " + path + " not found");
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)

Example 2 with NodeDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.

the class LockOperation method perform.

@Nonnull
@Override
public T perform() throws RepositoryException {
    session.refresh(true);
    NodeDelegate node = session.getNode(path);
    if (node != null) {
        return perform(node);
    } else {
        throw new PathNotFoundException("Node " + path + " not found");
    }
}
Also used : PathNotFoundException(javax.jcr.PathNotFoundException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) Nonnull(javax.annotation.Nonnull)

Example 3 with NodeDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.

the class SessionImpl method getItemInternal.

@CheckForNull
private ItemImpl<?> getItemInternal(@Nonnull String oakPath) throws RepositoryException {
    checkAlive();
    ItemDelegate item = sd.getItem(oakPath);
    if (item instanceof NodeDelegate) {
        return NodeImpl.createNode((NodeDelegate) item, sessionContext);
    } else if (item instanceof PropertyDelegate) {
        return new PropertyImpl((PropertyDelegate) item, sessionContext);
    } else {
        return null;
    }
}
Also used : NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) ItemDelegate(org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate) CheckForNull(javax.annotation.CheckForNull)

Example 4 with NodeDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.

the class VersionManagerImpl method restore.

@Override
public void restore(final String absPath, final Version version, final boolean removeExisting) throws RepositoryException {
    final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
    sessionDelegate.performVoid(new SessionOperation<Void>("restore", true) {

        @Override
        public void performVoid() throws RepositoryException {
            String oakPath = getOakPathOrThrowNotFound(absPath);
            NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
            if (nodeDelegate != null) {
                throw new VersionException("VersionManager.restore(String, Version, boolean)" + " not allowed on existing nodes; use" + " VersionManager.restore(Version, boolean) instead: " + absPath);
            }
            // check if parent exists
            NodeDelegate parent = ensureParentExists(sessionDelegate, absPath);
            // check for pending changes
            checkPendingChangesForRestore(sessionDelegate);
            // check lock status
            checkNotLocked(parent.getPath());
            // check for existing nodes
            List<NodeDelegate> existing = getExisting(version, Collections.<String>emptySet());
            boolean success = false;
            try {
                if (!existing.isEmpty()) {
                    if (removeExisting) {
                        removeExistingNodes(existing);
                    } else {
                        List<String> paths = new ArrayList<String>();
                        for (NodeDelegate nd : existing) {
                            paths.add(nd.getPath());
                        }
                        throw new ItemExistsException("Unable to restore with " + "removeExisting=false. Existing nodes in " + "workspace: " + paths);
                    }
                }
                // ready for restore
                VersionDelegate vd = versionManagerDelegate.getVersionByIdentifier(version.getIdentifier());
                versionManagerDelegate.restore(parent, PathUtils.getName(oakPath), vd);
                sessionDelegate.commit();
                success = true;
            } catch (CommitFailedException e) {
                throw e.asRepositoryException();
            } finally {
                if (!success) {
                    // refresh if one of the modifying operations fail
                    sessionDelegate.refresh(false);
                }
            }
        }
    });
}
Also used : VersionDelegate(org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate) RepositoryException(javax.jcr.RepositoryException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) SessionDelegate(org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate) ItemExistsException(javax.jcr.ItemExistsException) ArrayList(java.util.ArrayList) List(java.util.List) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) VersionException(javax.jcr.version.VersionException)

Example 5 with NodeDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.

the class VersionManagerImpl method checkout.

@Override
public void checkout(final String absPath) throws RepositoryException {
    final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
    sessionDelegate.performVoid(new SessionOperation<Void>("checkout", true) {

        @Override
        public void performVoid() throws RepositoryException {
            String oakPath = getOakPathOrThrowNotFound(absPath);
            NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
            if (nodeDelegate == null) {
                throw new PathNotFoundException(absPath);
            }
            checkNotLocked(absPath);
            versionManagerDelegate.checkout(nodeDelegate);
        }
    });
}
Also used : SessionDelegate(org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)

Aggregations

NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)14 PathNotFoundException (javax.jcr.PathNotFoundException)7 RepositoryException (javax.jcr.RepositoryException)6 Nonnull (javax.annotation.Nonnull)5 SessionDelegate (org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate)5 Node (javax.jcr.Node)4 ArrayList (java.util.ArrayList)3 ItemExistsException (javax.jcr.ItemExistsException)3 VersionException (javax.jcr.version.VersionException)3 PropertyDelegate (org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate)3 List (java.util.List)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 Tree (org.apache.jackrabbit.oak.api.Tree)2 ItemDelegate (org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate)2 VersionDelegate (org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate)2 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 CheckForNull (javax.annotation.CheckForNull)1 NodeIterator (javax.jcr.NodeIterator)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1