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);
}
}
}
});
}
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);
}
});
}
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);
}
}
}
});
}
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);
}
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);
}
}
Aggregations