Search in sources :

Example 11 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class TxLockManagerImpl method getLock.

/**
     * @param lockToken
     * @param resource
     * @return
     */
private ActiveLock getLock(String lockToken, Scope scope, DavResource resource) {
    if (!(resource instanceof TransactionResource)) {
        log.warn("TransactionResource expected");
        return null;
    }
    ActiveLock lock = null;
    Transaction tx = null;
    TransactionMap m = map;
    // check if main-map contains that txId
    if (m.containsKey(lockToken)) {
        tx = m.get(lockToken);
    } else {
        // look through all the nested tx-maps (i.e. global txs) for the given txId
        Iterator<Transaction> it = m.values().iterator();
        while (it.hasNext() && tx == null) {
            Transaction txMap = it.next();
            if (!txMap.isLocal()) {
                m = (TransactionMap) txMap;
                if (m.containsKey(lockToken)) {
                    tx = ((TransactionMap) txMap).get(lockToken);
                }
            }
        }
    }
    if (tx != null) {
        if (tx.getLock().isExpired()) {
            removeExpired(tx, m, (TransactionResource) resource);
        } else if (tx.appliesToResource(resource) && (scope == null || tx.getLock().getScope().equals(scope))) {
            lock = tx.getLock();
        }
    }
    return lock;
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) TxActiveLock(org.apache.jackrabbit.webdav.transaction.TxActiveLock) TransactionResource(org.apache.jackrabbit.webdav.transaction.TransactionResource)

Example 12 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class AbstractResource method getLocks.

/**
     * @see DavResource#getLocks()
     * todo improve....
     */
@Override
public ActiveLock[] getLocks() {
    List<ActiveLock> locks = new ArrayList<ActiveLock>();
    // tx locks
    ActiveLock l = getLock(TransactionConstants.TRANSACTION, TransactionConstants.LOCAL);
    if (l != null) {
        locks.add(l);
    }
    l = getLock(TransactionConstants.TRANSACTION, TransactionConstants.GLOBAL);
    if (l != null) {
        locks.add(l);
    }
    // write lock (either exclusive or session-scoped).
    l = getLock(Type.WRITE, Scope.EXCLUSIVE);
    if (l != null) {
        locks.add(l);
    } else {
        l = getLock(Type.WRITE, ItemResourceConstants.EXCLUSIVE_SESSION);
        if (l != null) {
            locks.add(l);
        }
    }
    return locks.toArray(new ActiveLock[locks.size()]);
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) ArrayList(java.util.ArrayList)

Aggregations

ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)12 RepositoryException (javax.jcr.RepositoryException)6 DavException (org.apache.jackrabbit.webdav.DavException)6 JcrActiveLock (org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)6 Lock (javax.jcr.lock.Lock)4 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 TxActiveLock (org.apache.jackrabbit.webdav.transaction.TxActiveLock)3 ArrayList (java.util.ArrayList)2 Node (javax.jcr.Node)2 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)2 DeleteContextImpl (org.apache.jackrabbit.server.io.DeleteContextImpl)1 DeleteManager (org.apache.jackrabbit.server.io.DeleteManager)1 LockInfo (org.apache.jackrabbit.spi.LockInfo)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1 Scope (org.apache.jackrabbit.webdav.lock.Scope)1 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)1 TransactionResource (org.apache.jackrabbit.webdav.transaction.TransactionResource)1