Search in sources :

Example 1 with SessionDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate 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 2 with SessionDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate 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)

Example 3 with SessionDelegate

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

the class VersionManagerImpl method restore.

@Override
public void restore(final Version[] versions, final boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException {
    if (versions.length > 1) {
        throw new UnsupportedRepositoryOperationException("OAK-168: Restore of multiple versions not implemented.");
    }
    final Version version = versions[0];
    VersionHistory history = (VersionHistory) version.getParent();
    final String versionableId = history.getVersionableIdentifier();
    if (history.getRootVersion().isSame(version)) {
        throw new VersionException("Restore of root version not possible");
    }
    final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
    sessionDelegate.performVoid(new SessionOperation<Void>("restore", true) {

        @Override
        public void performVoid() throws RepositoryException {
            // check for pending changes
            checkPendingChangesForRestore(sessionDelegate);
            NodeDelegate n = sessionDelegate.getNodeByIdentifier(versionableId);
            if (n == null) {
                throw new VersionException("Unable to restore version. " + "No versionable node with identifier: " + versionableId);
            }
            // check lock status
            checkNotLocked(n.getPath());
            // check for existing nodes
            List<NodeDelegate> existing = getExisting(version, Collections.singleton(n.getPath()));
            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(n.getParent(), n.getName(), vd);
                sessionDelegate.commit();
                success = true;
            } catch (CommitFailedException e) {
                throw new RepositoryException(e);
            } finally {
                if (!success) {
                    // refresh if one of the modifying operations fail
                    sessionDelegate.refresh(false);
                }
            }
        }
    });
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) VersionDelegate(org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) SessionDelegate(org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate) Version(javax.jcr.version.Version) 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 4 with SessionDelegate

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

the class VersionManagerImpl method internalGetVersionHistory.

/**
 * Returns the version history for the versionable node at the given path.
 *
 * @param absPathVersionable path to a versionable node.
 * @return the version history.
 * @throws PathNotFoundException if the given path does not reference an
 *                               existing node.
 * @throws UnsupportedRepositoryOperationException
 *                               if the node at the given path is not
 *                               mix:versionable.
 * @throws RepositoryException if some other error occurs.
 */
@Nonnull
private VersionHistoryDelegate internalGetVersionHistory(@Nonnull String absPathVersionable) throws RepositoryException, UnsupportedRepositoryOperationException {
    SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
    String oakPath = getOakPathOrThrowNotFound(checkNotNull(absPathVersionable));
    NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
    if (nodeDelegate == null) {
        throw new PathNotFoundException(absPathVersionable);
    }
    return versionManagerDelegate.getVersionHistory(nodeDelegate);
}
Also used : SessionDelegate(org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate) PathNotFoundException(javax.jcr.PathNotFoundException) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) Nonnull(javax.annotation.Nonnull)

Example 5 with SessionDelegate

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

the class SessionStats method refresh.

@Override
public void refresh() {
    final SessionDelegate sd = sessionDelegate;
    if (sd != null) {
        sd.safePerform(new SessionOperation<Void>("MBean initiated refresh", true) {

            @Override
            public Void perform() {
                sd.refresh(true);
                return null;
            }

            @Override
            public void checkPreconditions() throws RepositoryException {
                sd.checkAlive();
            }
        });
        sd.refresh(true);
    }
}
Also used : SessionDelegate(org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate) RepositoryException(javax.jcr.RepositoryException)

Aggregations

SessionDelegate (org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate)8 RepositoryException (javax.jcr.RepositoryException)6 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)5 ArrayList (java.util.ArrayList)3 List (java.util.List)2 ItemExistsException (javax.jcr.ItemExistsException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 VersionException (javax.jcr.version.VersionException)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 VersionDelegate (org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Nonnull (javax.annotation.Nonnull)1 Node (javax.jcr.Node)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 TraversingItemVisitor (javax.jcr.util.TraversingItemVisitor)1 Version (javax.jcr.version.Version)1 VersionHistory (javax.jcr.version.VersionHistory)1 LoginException (javax.security.auth.login.LoginException)1 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)1 RefreshStrategy (org.apache.jackrabbit.oak.jcr.session.RefreshStrategy)1