use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.
the class LockManagerImpl method buildLockState.
private LockState buildLockState(NodeState nodeState) throws RepositoryException {
NodeId nId = nodeState.getNodeId();
NodeState lockHoldingState;
LockInfo lockInfo = wspManager.getLockInfo(nId);
if (lockInfo == null) {
// no lock present
return null;
}
NodeId lockNodeId = lockInfo.getNodeId();
if (lockNodeId.equals(nId)) {
lockHoldingState = nodeState;
} else {
NodeEntry lockedEntry = wspManager.getHierarchyManager().getNodeEntry(lockNodeId);
try {
lockHoldingState = lockedEntry.getNodeState();
} catch (RepositoryException e) {
log.warn("Cannot build LockState");
throw new RepositoryException("Cannot build LockState", e);
}
}
if (lockHoldingState == null) {
return null;
} else {
return new LockState(lockHoldingState, lockInfo);
}
}
use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method retrieveLockInfo.
private LockInfo retrieveLockInfo(LockDiscovery lockDiscovery, SessionInfo sessionInfo, NodeId nodeId, NodeId parentId) throws RepositoryException {
checkSessionInfo(sessionInfo);
List<ActiveLock> activeLocks = lockDiscovery.getValue();
ActiveLock activeLock = null;
for (ActiveLock l : activeLocks) {
Scope sc = l.getScope();
if (l.getType() == Type.WRITE && (Scope.EXCLUSIVE.equals(sc) || sc == ItemResourceConstants.EXCLUSIVE_SESSION)) {
if (activeLock != null) {
throw new RepositoryException("Node " + saveGetIdString(nodeId, sessionInfo) + " contains multiple exclusive write locks.");
} else {
activeLock = l;
}
}
}
if (activeLock == null) {
log.debug("No lock present on node " + saveGetIdString(nodeId, sessionInfo));
return null;
}
NodeId holder = null;
String lockroot = activeLock.getLockroot();
if (activeLock.getLockroot() != null) {
holder = uriResolver.getNodeId(lockroot, sessionInfo);
}
if (activeLock.isDeep() && holder == null && parentId != null) {
// deep lock, parent known, but holder is not
LockInfo pLockInfo = getLockInfo(sessionInfo, parentId);
if (pLockInfo != null) {
return pLockInfo;
}
}
return new LockInfoImpl(activeLock, holder == null ? nodeId : holder, ((SessionInfoImpl) sessionInfo).getAllLockTokens());
}
use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method lock.
/**
* {@inheritDoc}
*/
public LockInfo lock(SessionInfo sessionInfo, final NodeId nodeId, final boolean deep, final boolean sessionScoped, final long timeoutHint, final String ownerHint) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
return (LockInfo) executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
Node n = getNode(nodeId, sInfo);
Lock lock;
javax.jcr.lock.LockManager lMgr = (sInfo.getSession().getWorkspace()).getLockManager();
lock = lMgr.lock(n.getPath(), deep, sessionScoped, timeoutHint, ownerHint);
return LockInfoImpl.createLockInfo(lock, idFactory);
}
}, sInfo);
}
use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method lock.
/**
* {@inheritDoc}
*/
public LockInfo lock(final SessionInfo sessionInfo, final NodeId nodeId, final boolean deep, final boolean sessionScoped) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
return (LockInfo) executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
Node n = getNode(nodeId, sInfo);
Lock lock = n.lock(deep, sessionScoped);
return LockInfoImpl.createLockInfo(lock, idFactory);
}
}, sInfo);
}
use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method lock.
@Override
public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped, long timeoutHint, String ownerHint) throws RepositoryException {
HttpLock request = null;
try {
checkSessionInfo(sessionInfo);
long davTimeout = (timeoutHint == Long.MAX_VALUE) ? INFINITE_TIMEOUT : timeoutHint * 1000;
String ownerInfo = (ownerHint == null) ? sessionInfo.getUserID() : ownerHint;
String uri = getItemUri(nodeId, sessionInfo);
Scope scope = (sessionScoped) ? ItemResourceConstants.EXCLUSIVE_SESSION : Scope.EXCLUSIVE;
request = new HttpLock(uri, new org.apache.jackrabbit.webdav.lock.LockInfo(scope, Type.WRITE, ownerInfo, davTimeout, deep));
HttpResponse response = execute(request, sessionInfo);
String lockToken = request.getLockToken(response);
((SessionInfoImpl) sessionInfo).addLockToken(lockToken, sessionScoped);
LockDiscovery disc = request.getResponseBodyAsLockDiscovery(response);
return retrieveLockInfo(disc, sessionInfo, nodeId, null);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations