jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r803484 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock: AbstractLockInfo.java LockImpl.java LockInfo.java LockManagerImpl.java XALockImpl.java
Date Wed, 12 Aug 2009 12:52:05 GMT
Author: jukka
Date: Wed Aug 12 12:52:05 2009
New Revision: 803484

URL: http://svn.apache.org/viewvc?rev=803484&view=rev
Log:
JCR-1590: JSR 283: Locking

Streamline LockInfo code to avoid extra type casts.

Move the isLockHolder access check from NodeInfo.getLockToken to LockImpl.getLockToken where
it fits better.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.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/XALockImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java?rev=803484&r1=803483&r2=803484&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java
Wed Aug 12 12:52:05 2009
@@ -153,16 +153,6 @@
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public String getLockToken(Session session) {
-        if (isLockHolder(session)) {
-            return lockToken.toString();
-        }
-        return null;
-    }
-
-    /**
      * Return the lock token.
      *
      * @return lock token

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java?rev=803484&r1=803483&r2=803484&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
Wed Aug 12 12:52:05 2009
@@ -38,7 +38,7 @@
     /**
      * Node holding lock
      */
-    protected final Node node;
+    protected final NodeImpl node;
 
     /**
      * Create a new instance of this class.
@@ -46,7 +46,7 @@
      * @param info lock information
      * @param node node holding lock
      */
-    public LockImpl(LockInfo info, Node node) {
+    public LockImpl(LockInfo info, NodeImpl node) {
         this.info = info;
         this.node = node;
     }
@@ -78,12 +78,9 @@
      * {@inheritDoc}
      */
     public String getLockToken() {
-        if (info.isSessionScoped()) {
-            return null;
-        }
-        try {
-            return info.getLockToken(node.getSession());
-        } catch (RepositoryException e) {
+        if (!info.isSessionScoped() || info.isLockHolder(node.getSession())) {
+            return info.getLockToken();
+        } else {
             return null;
         }
     }
@@ -117,7 +114,7 @@
         // make sure the current session has sufficient privileges to refresh
         // the lock.
         SessionImpl s = (SessionImpl) node.getSession();
-        s.getAccessManager().checkPermission(((NodeImpl) node).getPrimaryPath(), Permission.LOCK_MNGMT);
+        s.getAccessManager().checkPermission(node.getPrimaryPath(), Permission.LOCK_MNGMT);
 
         // TODO: TOBEFIXED for 2.0
         // TODO  - add refresh if timeout is supported -> see #getSecondsRemaining
@@ -137,10 +134,7 @@
      * @see javax.jcr.lock.Lock#isLockOwningSession()
      */
     public boolean isLockOwningSession() {
-        try {
-            return info.isLockHolder(node.getSession());
-        } catch (RepositoryException e) {
-            return false;
-        }
+        return info.isLockHolder(node.getSession());
     }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java?rev=803484&r1=803483&r2=803484&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
Wed Aug 12 12:52:05 2009
@@ -54,14 +54,11 @@
     public boolean isLockHolder(Session session);
 
     /**
-     * Return the lock token as seen by the session passed as parameter. If
-     * this session is currently holding the lock, it will get the lock token
-     * itself, otherwise a <code>null</code> string.
+     * Return the lock token associated with this lock.
      *
-     * @param session The session asking for the lock token.
-     * @return lock token.
+     * @return lock token
      */
-    public String getLockToken(Session session);
+    public String getLockToken();
 
     /**
      * Return a flag indicating whether the lock is live

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=803484&r1=803483&r2=803484&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 Aug 12 12:52:05 2009
@@ -52,7 +52,6 @@
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.ItemNotFoundException;
-import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -390,7 +389,7 @@
             }
             checkUnlock(info, session);
 
-            getSessionLockManager(session).lockTokenRemoved(info.getLockToken(session));
+            getSessionLockManager(session).lockTokenRemoved(info.getLockToken());
 
             element.set(null);
             info.setLive(false);
@@ -492,7 +491,8 @@
             PathMap.Element<AbstractLockInfo> element = lockMap.map(path, false);
             AbstractLockInfo info = element.get();
             if (info != null && (element.hasPath(path) || info.deep)) {
-                Node lockHolder = (Node) session.getItemManager().getItem(info.getId());
+                NodeImpl lockHolder = (NodeImpl)
+                    session.getItemManager().getItem(info.getId());
                 return new LockImpl(info, lockHolder);
             } else {
                 throw new LockException("Node not locked: " + node);
@@ -516,9 +516,9 @@
         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);
+                NodeImpl holder = (NodeImpl)
+                    session.getItemManager().getItem(infos[i].getId());
+                locks[i] = new LockImpl(infos[i], holder);
             }
             return locks;
         } finally {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockImpl.java?rev=803484&r1=803483&r2=803484&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockImpl.java
Wed Aug 12 12:52:05 2009
@@ -18,7 +18,6 @@
 
 import org.apache.jackrabbit.core.NodeImpl;
 
-import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
 /**
@@ -41,7 +40,8 @@
      * @param info lock information
      * @param node node holding lock
      */
-    public XALockImpl(XALockManager lockMgr, AbstractLockInfo info, Node node) {
+    public XALockImpl(
+            XALockManager lockMgr, AbstractLockInfo info, NodeImpl node) {
         super(info, node);
 
         this.info = info;
@@ -56,7 +56,7 @@
     public boolean isLive() throws RepositoryException {
         if (info.mayChange()) {
             if (lockMgr.differentXAEnv(info)) {
-                return lockMgr.holdsLock((NodeImpl) node);
+                return lockMgr.holdsLock(node);
             }
         }
         return super.isLive();



Mime
View raw message