You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2005/11/14 15:15:36 UTC
svn commit: r344124 - in /incubator/jackrabbit/trunk/jackrabbit/src:
main/java/org/apache/jackrabbit/core/lock/LockImpl.java
main/java/org/apache/jackrabbit/core/lock/LockInfo.java
test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
Author: angela
Date: Mon Nov 14 06:13:39 2005
New Revision: 344124
URL: http://svn.apache.org/viewcvs?rev=344124&view=rev
Log:
JCR-226 Lock.refresh(): throws if lock is alive
JCR-225 LockInfo.logginOut(SessionImpl): javadoc does not correspond to executed code
Modified:
incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java?rev=344124&r1=344123&r2=344124&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java Mon Nov 14 06:13:39 2005
@@ -16,8 +16,6 @@
*/
package org.apache.jackrabbit.core.lock;
-import org.apache.jackrabbit.core.NodeImpl;
-
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.lock.Lock;
@@ -100,14 +98,16 @@
/**
* {@inheritDoc}
+ * @throws LockException if this <code>Session</code> is not the lock holder
+ * or if this <code>Lock</code> is not alive.
*/
public void refresh() throws LockException, RepositoryException {
- if (isLive()) {
- throw new LockException("Lock still alive.");
+ if (!isLive()) {
+ throw new LockException("Lock is not live any more.");
}
if (getLockToken() == null) {
throw new LockException("Session does not hold lock.");
}
- info.refresh((NodeImpl) node);
+ // since a lock has no expiration date no other action is required
}
}
Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java?rev=344124&r1=344123&r2=344124&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java Mon Nov 14 06:13:39 2005
@@ -16,14 +16,11 @@
*/
package org.apache.jackrabbit.core.lock;
-import org.apache.jackrabbit.core.NodeImpl;
import org.apache.jackrabbit.core.SessionImpl;
import org.apache.jackrabbit.core.SessionListener;
import org.apache.log4j.Logger;
-import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.lock.LockException;
/**
* Contains information about a lock and gets placed inside the child
@@ -156,19 +153,6 @@
return sessionScoped;
}
- /**
- * Refresh a lock. Will try to re-insert this lock info into the lock
- * manager's path map, provided the node is not already locked.
- *
- * @param node node to lock again
- * @throws LockException if the node is already locked
- * @throws RepositoryException if some other error occurs
- * @see javax.jcr.Node#refresh
- */
- public void refresh(NodeImpl node) throws LockException, RepositoryException {
- lockMgr.lock(node, this);
- }
-
//-------------------------------------------------------< SessionListener >
/**
@@ -178,7 +162,7 @@
* operations depending on the lock type.
* (1) If the lock was session-scoped, we unlock the node.
* (2) If the lock was open-scoped, we remove the lock token
- * from the session.
+ * from the session and set the lockHolder field to <code>null</code>.
*/
public void loggingOut(SessionImpl session) {
if (live) {
@@ -186,6 +170,7 @@
lockMgr.unlock(this);
} else {
if (session.equals(lockHolder)) {
+ session.removeLockToken(lockToken.toString());
lockHolder = null;
}
}
Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java?rev=344124&r1=344123&r2=344124&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java Mon Nov 14 06:13:39 2005
@@ -484,25 +484,44 @@
// assert: lock must be alive
assertTrue("lock must be alive", lock.isLive());
- // assert: refresh must fail, since lock is still alive
- try {
- lock.refresh();
- fail("refresh must fail, since lock is still alive");
- } catch (LockException e) {
- // expected
- }
+ // assert: refresh must succeed
+ lock.refresh();
// unlock node
n.unlock();
// assert: lock must not be alive
assertFalse("lock must not be alive", lock.isLive());
+ }
- // refresh
- lock.refresh();
+ /**
+ * Test refresh
+ */
+ public void testRefreshNotLive() throws Exception {
+ // create new node
+ Node n = testRootNode.addNode(nodeName1, testNodeType);
+ n.addMixin(mixLockable);
+ testRootNode.save();
+
+ // lock node and get lock token
+ Lock lock = n.lock(false, true);
+
+ // assert: lock must be alive
+ assertTrue("lock must be alive", lock.isLive());
+
+ // unlock node
+ n.unlock();
+
+ // assert: lock must not be alive
+ assertFalse("lock must not be alive", lock.isLive());
- // assert: lock must again be alive
- assertTrue("lock must again be alive", lock.isLive());
+ // refresh
+ try {
+ lock.refresh();
+ fail("Refresh on a lock that is not alive must fail");
+ } catch (LockException e) {
+ // success
+ }
}
/**