jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1230688 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/...
Date Thu, 12 Jan 2012 18:33:59 GMT
Author: angela
Date: Thu Jan 12 18:33:59 2012
New Revision: 1230688

URL: http://svn.apache.org/viewvc?rev=1230688&view=rev
Log:
JCR-3205 - Missing support for lock timeout and ownerHint in jcr-server

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=1230688&r1=1230687&r2=1230688&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
Thu Jan 12 18:33:59 2012
@@ -666,7 +666,15 @@ public class DefaultItemCollection exten
             }
             try {
                 boolean sessionScoped = EXCLUSIVE_SESSION.equals(reqLockInfo.getScope());
-                Lock jcrLock = ((Node)item).lock(reqLockInfo.isDeep(), sessionScoped);
+                long timeout = reqLockInfo.getTimeout();
+                if (timeout == LockInfo.INFINITE_TIMEOUT) {
+                    timeout = Long.MAX_VALUE;
+                } else {
+                    timeout = timeout/1000;
+                }
+                javax.jcr.lock.LockManager lockMgr = getRepositorySession().getWorkspace().getLockManager();
+                Lock jcrLock = lockMgr.lock((item).getPath(), reqLockInfo.isDeep(),
+                        sessionScoped, timeout, reqLockInfo.getOwner());
                 ActiveLock lock = new JcrActiveLock(jcrLock);
                  // add reference to DAVSession for this lock
                 getSession().addReference(lock.getToken());

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java?rev=1230688&r1=1230687&r2=1230688&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java
Thu Jan 12 18:33:59 2012
@@ -124,14 +124,21 @@ public class JcrActiveLock extends Abstr
     }
 
     /**
-     * Since jcr locks do not reveal the time left until they expire, {@link #INFINITE_TIMEOUT}
-     * is returned. A missing timeout causes problems with Microsoft clients.
+     * Calculates the milliseconds of the timeout from
+     * {@link javax.jcr.lock.Lock#getSecondsRemaining()}. If the timeout of
+     * jcr lock is undefined or infinite {@link #INFINITE_TIMEOUT} is
+     * returned. A missing timeout causes problems with Microsoft clients.
      *
      * @return Always returns {@link #INFINITE_TIMEOUT}
      * @see ActiveLock#getTimeout()
      */
     public long getTimeout() {
-        return INFINITE_TIMEOUT;
+        try {
+            long to = lock.getSecondsRemaining();
+            return (to == Long.MAX_VALUE) ? INFINITE_TIMEOUT : to*1000;
+        } catch (RepositoryException e) {
+            return INFINITE_TIMEOUT;
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java?rev=1230688&r1=1230687&r2=1230688&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
Thu Jan 12 18:33:59 2012
@@ -265,9 +265,11 @@ public abstract class AbstractLockTest e
         // only test if timeout hint was respected.
         long remaining = lock.getSecondsRemaining();
         if (remaining <= hint) {
-            try {
-                wait(remaining * 4000); // wait four time as long to be safe
-            } catch (InterruptedException ignore) {
+            if (remaining > 0) {
+                try {
+                    wait(remaining * 4000); // wait four time as long to be safe
+                } catch (InterruptedException ignore) {
+                }
             }
             long secs = lock.getSecondsRemaining();
             assertTrue(
@@ -286,6 +288,24 @@ public abstract class AbstractLockTest e
     }
 
     /**
+     * Test expiration of the lock
+     */
+    public synchronized void testOwnerHint()
+            throws RepositoryException, NotExecutableException {
+        lockedNode.unlock();
+
+        lock = lockMgr.lock(lockedNode.getPath(), isDeep(), isSessionScoped(), Long.MAX_VALUE,
"test");
+
+        String owner = lock.getLockOwner();
+        if (!"test".equals(lock.getLockOwner())) {
+            throw new NotExecutableException();
+        } else {
+            assertTrue(lockedNode.hasProperty(Property.JCR_LOCK_OWNER));
+            assertEquals("test", lockedNode.getProperty(Property.JCR_LOCK_OWNER).getString());
+        }
+    }
+
+    /**
      * Test if Lock is properly released.
      * 
      * @throws RepositoryException



Mime
View raw message