You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/08/12 17:48:31 UTC
svn commit: r803566 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock:
LockImpl.java LockInfo.java LockManagerImpl.java XAEnvironment.java
Author: jukka
Date: Wed Aug 12 15:48:30 2009
New Revision: 803566
URL: http://svn.apache.org/viewvc?rev=803566&view=rev
Log:
JCR-1590: JSR 283: Locking
Create and use a LockInfo.throwLockException utility method for setting the failure node path in LockExceptions.
Modified:
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/XAEnvironment.java
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=803566&r1=803565&r2=803566&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 15:48:30 2009
@@ -106,12 +106,14 @@
*/
public void refresh() throws LockException, RepositoryException {
if (!isLive()) {
- throw new LockException(
- "Lock is not live any more.", null, node.getPath());
+ info.throwLockException(
+ "Lock is not live any more",
+ (SessionImpl) node.getSession());
}
if (!isLockOwningSession()) {
- throw new LockException(
- "Session does not hold lock.", null, node.getPath());
+ info.throwLockException(
+ "Session does not hold lock.",
+ (SessionImpl) node.getSession());
}
// make sure the current session has sufficient privileges to refresh
// the lock.
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=803566&r1=803565&r2=803566&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 15:48:30 2009
@@ -19,7 +19,9 @@
import org.apache.jackrabbit.core.SessionImpl;
import org.apache.jackrabbit.core.id.NodeId;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.lock.LockException;
/**
* Internal lock information.
@@ -198,6 +200,33 @@
}
/**
+ * Utility method that throws a {@link LockException} with the
+ * "failure node path" set to the path of the node that holds this lock.
+ * The given session is used to resolve the path of the lock holder node.
+ *
+ * @param message exception message
+ * @param session session that the user was using for the failing operation
+ * @throws LockException always thrown, unless another error occurs
+ * @throws RepositoryException if the path of this lock can not be resolved
+ */
+ public void throwLockException(String message, SessionImpl session)
+ throws LockException, RepositoryException {
+ String path;
+ try {
+ path = session.getJCRPath(
+ session.getHierarchyManager().getPath(id));
+ } catch (RepositoryException ignored) {
+ path = null;
+ }
+ if (path != null) {
+ throw new LockException(
+ message + " (lock held by node " + path + ")", null, path);
+ } else {
+ throw new LockException(message);
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
public String toString() {
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=803566&r1=803565&r2=803566&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 15:48:30 2009
@@ -322,20 +322,16 @@
LockInfo other = element.get();
if (other != null) {
if (element.hasPath(path)) {
- throw new LockException(
- "Node already locked: " + node, null,
- node.getPath());
+ other.throwLockException(
+ "Node already locked: " + node, session);
} else if (other.isDeep()) {
- throw new LockException(
- "Parent node has a deep lock: " + node, null,
- session.getJCRPath(getPath(session, other.getId())));
+ other.throwLockException(
+ "Parent node has a deep lock: " + node, session);
}
}
if (info.isDeep() && element.hasPath(path)
&& element.getChildrenCount() > 0) {
- throw new LockException(
- "Some child node is locked.", null,
- session.getJCRPath(getPath(session, other.getId())));
+ info.throwLockException("Some child node is locked", session);
}
// create lock token
@@ -697,8 +693,7 @@
} else {
String msg = "Cannot add lock token: lock already held by other session.";
log.warn(msg);
- throw new LockException(
- msg, null, session.getJCRPath(path));
+ info.throwLockException(msg, session);
}
}
}
@@ -733,8 +728,7 @@
} else {
String msg = "Cannot remove lock token: lock held by other session.";
log.warn(msg);
- throw new LockException(
- msg, null, session.getJCRPath(getPath(session, id)));
+ info.throwLockException(msg, session);
}
}
}
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=803566&r1=803565&r2=803566&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 Aug 12 15:48:30 2009
@@ -143,7 +143,7 @@
// verify node is not already locked.
if (isLocked(node)) {
- throw new LockException("Node locked.", null, node.getPath());
+ throw new LockException("Node locked.");
}
// create a new lock info for this node