jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r572978 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SessionImpl.java lock/LockManager.java lock/LockManagerImpl.java lock/XAEnvironment.java lock/XALockManager.java
Date Wed, 05 Sep 2007 15:54:41 GMT
Author: stefan
Date: Wed Sep  5 08:54:41 2007
New Revision: 572978

URL: http://svn.apache.org/viewvc?rev=572978&view=rev
Log:
JCR-1104: JSR 283 support (work in progress...)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=572978&r1=572977&r2=572978&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Wed Sep  5 08:54:41 2007
@@ -52,6 +52,7 @@
 import javax.jcr.Workspace;
 import javax.jcr.Property;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.Lock;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.observation.EventListener;
@@ -1539,6 +1540,28 @@
             return true;
         } catch (PathNotFoundException pnfe) {
             return false;
+        }
+    }
+
+    /**
+     * Returns all locks owned by this session.
+     *
+     * @return an array of <code>Lock</code>s
+     * @since JCR 2.0
+     */
+    public Lock[] getLocks() {
+        // check sanity of this session
+        //sanityCheck();
+        if (!alive) {
+            log.error("failed to retrieve locks: session has been closed");
+            return new Lock[0];
+        }
+
+        try {
+            return getLockManager().getLocks(this);
+        } catch (RepositoryException e) {
+            log.error("Lock manager not available.", e);
+            return new Lock[0];
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java?rev=572978&r1=572977&r2=572978&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
Wed Sep  5 08:54:41 2007
@@ -55,6 +55,15 @@
     Lock getLock(NodeImpl node) throws LockException, RepositoryException;
 
     /**
+     * Returns all locks owned by the specified session.
+     * @param session session
+     * @return an array of lock objects
+     * @throws RepositoryException if an error occurs
+     * @see SessionImpl#getLocks
+     */
+    Lock[] getLocks(SessionImpl session) throws RepositoryException;
+
+    /**
      * Removes the lock on a node given by its path.
      * @param node node
      * @throws LockException if this node is not locked or the session

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?rev=572978&r1=572977&r2=572978&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
Wed Sep  5 08:54:41 2007
@@ -364,6 +364,26 @@
     }
 
     /**
+     * Package-private low-level helper method returning all
+     * <code>AbstractLockInfo</code>s associated with the specified
+     * session.
+     * @param session session
+     * @return an array of <code>AbstractLockInfo</code>s
+     */
+    AbstractLockInfo[] getLockInfos(final SessionImpl session) {
+        final ArrayList infos = new ArrayList();
+        lockMap.traverse(new PathMap.ElementVisitor() {
+            public void elementVisited(PathMap.Element element) {
+                LockInfo info = (LockInfo) element.get();
+                if (info.isLive() && info.getLockHolder().equals(session)) {
+                    infos.add(info);
+                }
+            }
+        }, false);
+        return (AbstractLockInfo[]) infos.toArray(new AbstractLockInfo[infos.size()]);
+    }
+
+    /**
      * Return the most appropriate lock information for a node. This is either
      * the lock info for the node itself, if it is locked, or a lock info for one
      * of its parents, if that is deep locked.
@@ -428,6 +448,28 @@
             }
         } catch (ItemNotFoundException e) {
             throw new LockException("Node not locked: " + node.safeGetJCRPath());
+        } finally {
+            release();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Lock[] getLocks(SessionImpl session) throws RepositoryException {
+
+        acquire();
+
+        AbstractLockInfo infos[] = getLockInfos(session);
+
+        try {
+            Lock[] locks = new Lock[infos.length];
+            for (int i = 0; i < infos.length; i++) {
+                AbstractLockInfo info = infos[i];
+                Node holder = (Node) session.getItemManager().getItem(info.getId());
+                locks[i] = new LockImpl(info, holder);
+            }
+            return locks;
         } finally {
             release();
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java?rev=572978&r1=572977&r2=572978&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
Wed Sep  5 08:54:41 2007
@@ -25,6 +25,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.Lock;
 import javax.transaction.Status;
 import java.util.Map;
 import java.util.HashMap;
@@ -208,6 +209,33 @@
         }
         // ask parent
         return lockMgr.getLockInfo(id);
+    }
+
+    /**
+     * Returns all <code>AbstractLockInfo</code>s associated with the specified
+     * session.
+     * @param session session
+     * @return an array of <code>AbstractLockInfo</code>s
+     * @throws RepositoryException if an error occurs
+     */
+    public AbstractLockInfo[] getLockInfos(SessionImpl session)
+            throws RepositoryException {
+        ArrayList result = new ArrayList();
+
+        // get lock infos from global lock manager first
+        AbstractLockInfo[] infos = lockMgr.getLockInfos(session);
+        for (int i = 0; i < infos.length; i++) {
+            AbstractLockInfo info = infos[i];
+            // check negative set
+            if (!unlockedNodesMap.containsKey(info.getId())) {
+                result.add(info);
+            }
+        }
+
+        // add 'uncommitted' lock infos 
+        result.addAll(lockedNodesMap.values());
+
+        return (AbstractLockInfo[]) result.toArray(new AbstractLockInfo[result.size()]);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java?rev=572978&r1=572977&r2=572978&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
Wed Sep  5 08:54:41 2007
@@ -27,6 +27,7 @@
 import javax.jcr.Session;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
+import java.util.ArrayList;
 
 /**
  * Session-local lock manager that implements the semantical changes inside
@@ -91,6 +92,27 @@
         SessionImpl session = (SessionImpl) node.getSession();
         NodeImpl holder = (NodeImpl) session.getItemManager().getItem(info.getId());
         return new XALock(this, info, holder);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Lock[] getLocks(SessionImpl session) throws RepositoryException {
+        AbstractLockInfo[] infos;
+        if (isInXA()) {
+            infos = xaEnv.getLockInfos(session);
+        } else {
+            infos = lockMgr.getLockInfos(session);
+        }
+
+        XALock[] locks = new XALock[infos.length];
+
+        for (int i = 0; i < infos.length; i++) {
+            AbstractLockInfo info = infos[i];
+            NodeImpl holder = (NodeImpl) session.getItemManager().getItem(info.getId());
+            locks[i] = new XALock(this, info, holder);
+        }
+        return locks;
     }
 
     /**



Mime
View raw message