Author: sergiykarpenko
Date: 2010-03-03 10:22:55 -0500 (Wed, 03 Mar 2010)
New Revision: 1988
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
Log:
EXOJCR-546: SessionLockManager - isLocked() and isLockHolder concatenated to
checkLocking(); this avoid double call of lockManager.getExactNodeOrCloseParentLock(node)
in CacheableSessionLockManager.
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -2165,7 +2165,7 @@
if (!session.getLockManager().holdsLock((NodeData)this.getData()))
throw new LockException("The node not locked " + getPath());
- if (!session.getLockManager().isLockHolder(this))
+ if (!session.getLockManager().isLockHolder(this.nodeData()))
throw new LockException("There are no permission to unlock the node "
+ getPath());
if (dataManager.hasPendingChanges(getInternalPath()))
@@ -2309,8 +2309,12 @@
boolean checkLocking() throws RepositoryException
{
- return (!isLocked() || session.getLockManager().isLockHolder(this) ||
session.getUserID().equals(
+ // return (!isLocked() || session.getLockManager().isLockHolder(this) ||
session.getUserID().equals(
+ // SystemIdentity.SYSTEM));
+
+ return (session.getLockManager().checkLocking(this.nodeData()) ||
session.getUserID().equals(
SystemIdentity.SYSTEM));
+
}
protected void doOrderBefore(QPath srcPath, QPath destPath) throws
RepositoryException
@@ -2537,7 +2541,7 @@
{
// locked, should be unlocked
- if (!session.getLockManager().isLockHolder(this))
+ if (!session.getLockManager().isLockHolder(this.nodeData()))
throw new LockException("There are no permission to unlock the node
" + getPath());
// remove mix:lockable properties (as the node is locked)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -19,7 +19,6 @@
package org.exoplatform.services.jcr.impl.core.lock;
import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import javax.jcr.RepositoryException;
@@ -41,20 +40,58 @@
}
/**
- * Check if the node locked (and lock peristed in internal storage).
+ * Check if the node locked (locks persisted in internal storage).
* @param node NodeData to check
* @return boolean, <code>true</code> if the node is locked,
<code>false</code> otherwise
* @throws LockException
*/
protected abstract boolean isLockedPersisted(NodeData node) throws LockException;
- protected abstract boolean isPersitedLockHolder(NodeImpl node) throws
RepositoryException;
+ protected abstract boolean isPersistedLockHolder(NodeData node) throws
RepositoryException;
/**
+ * Checks the node, is it accessible according to possible locks. If node is locked
and current
+ * session is not lockHolder <code> false</code> will be returned.
+ *
+ * @param data - node that must be checked
+ * @return true - if lock not exist or current session is LockOwner; false - in other
case;
+ * @throws LockException - if lock engine exception happens
+ */
+ protected abstract boolean checkPersistedLocks(NodeData node) throws LockException;
+
+ /**
* {@inheritDoc}
*/
- public boolean isLockHolder(NodeImpl node) throws RepositoryException
+ public boolean checkLocking(NodeData data) throws LockException
{
+ //check is new and find close persisted parent
+
+ while (transientManager.isNew(data.getIdentifier()))
+ {
+ // The node is new, so we will check directly its parent instead
+ try
+ {
+ data = (NodeData)transientManager.getItemData(data.getParentIdentifier());
+ if (data == null)
+ {
+ // The node is the root node and is new, so we consider it as unlocked
+ return true;
+ }
+ }
+ catch (RepositoryException e)
+ {
+ throw new LockException(e);
+ }
+ }
+
+ return checkPersistedLocks(data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isLockHolder(NodeData node) throws RepositoryException
+ {
//check is parent node also new
if (transientManager.isNew(node.getIdentifier()) &&
transientManager.isNew(node.getParentIdentifier()))
{
@@ -62,7 +99,7 @@
}
else
{
- return isPersitedLockHolder(node);
+ return isPersistedLockHolder(node);
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -255,10 +255,10 @@
return true;
}
- public boolean isLockHolder(NodeImpl node) throws RepositoryException
+ public boolean isLockHolder(NodeData node, String sessionId)// throws
RepositoryException
{
- LockData lData = getLockData((NodeData)node.getData(), SEARCH_EXECMATCH |
SEARCH_CLOSEDPARENT);
- return lData != null && lData.isLockHolder(node.getSession().getId());
+ LockData lData = getLockData(node, SEARCH_EXECMATCH | SEARCH_CLOSEDPARENT);
+ return lData != null && lData.isLockHolder(sessionId);
}
public synchronized void onCloseSession(ExtendedSession session)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -114,7 +114,7 @@
* @return if the specified session holds a lock on the given node; otherwise returns
* <code>false</code>
*/
- boolean isLockHolder(NodeImpl node) throws RepositoryException;
+ boolean isLockHolder(NodeData node) throws RepositoryException;
/**
* Invoked by a session to inform that a lock token has been removed.
@@ -126,4 +126,13 @@
*/
void removeLockToken(String lt);
+ /**
+ * Checks this node, is it accessible according to possible locks. If node is locked
and current
+ * session is not lockHolder <code> false</code> will be returned.
+ *
+ * @param data - node that must be checked
+ * @return true - if lock not exist or current session is LockOwner; false - in other
case;
+ * @throws LockException - if lock engine exception happens
+ */
+ boolean checkLocking(NodeData data) throws LockException;
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -94,9 +94,9 @@
/**
* {@inheritDoc}
*/
- protected boolean isPersitedLockHolder(NodeImpl node) throws RepositoryException
+ protected boolean isPersistedLockHolder(NodeData node)// throws RepositoryException
{
- return lockManager.isLockHolder(node);
+ return lockManager.isLockHolder(node, sessionId);
}
/**
@@ -123,4 +123,11 @@
lockManager.onCloseSession(session);
}
+ /**
+ * {@inheritDoc}
+ */
+ protected boolean checkPersistedLocks(NodeData node) throws LockException
+ {
+ return (!isLockedPersisted(node) || isPersistedLockHolder(node));
+ }
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -114,7 +114,7 @@
public static final String JBOSSCACHE_JDBC_CL_NODE_COLUMN =
"jbosscache-cl-cache.jdbc.node.type";
public static final String JBOSSCACHE_JDBC_CL_FQN_COLUMN =
"jbosscache-cl-cache.jdbc.fqn.type";
-
+
public static final String JBOSSCACHE_JDBC_CL_AUTO = "auto";
/**
@@ -362,12 +362,14 @@
// if parameter is missing in configuration, then
getParameterValue(JBOSSCACHE_JDBC_CL_NODE_COLUMN, JBOSSCACHE_JDBC_CL_AUTO)
// will return JBOSSCACHE_JDBC_CL_AUTO. If parameter is present in configuration
and equals to "auto", then it should be replaced
// with correct value for given database
- if (parameterEntry.getParameterValue(JBOSSCACHE_JDBC_CL_NODE_COLUMN,
JBOSSCACHE_JDBC_CL_AUTO).equalsIgnoreCase(JBOSSCACHE_JDBC_CL_AUTO))
+ if (parameterEntry.getParameterValue(JBOSSCACHE_JDBC_CL_NODE_COLUMN,
JBOSSCACHE_JDBC_CL_AUTO)
+ .equalsIgnoreCase(JBOSSCACHE_JDBC_CL_AUTO))
{
parameterEntry.putParameterValue(JBOSSCACHE_JDBC_CL_NODE_COLUMN, blobType);
}
- if (parameterEntry.getParameterValue(JBOSSCACHE_JDBC_CL_FQN_COLUMN,
JBOSSCACHE_JDBC_CL_AUTO).equalsIgnoreCase(JBOSSCACHE_JDBC_CL_AUTO))
+ if (parameterEntry.getParameterValue(JBOSSCACHE_JDBC_CL_FQN_COLUMN,
JBOSSCACHE_JDBC_CL_AUTO).equalsIgnoreCase(
+ JBOSSCACHE_JDBC_CL_AUTO))
{
parameterEntry.putParameterValue(JBOSSCACHE_JDBC_CL_FQN_COLUMN, charType);
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-03-03
15:05:06 UTC (rev 1987)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-03-03
15:22:55 UTC (rev 1988)
@@ -16,7 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
-import org.exoplatform.services.jcr.access.SystemIdentity;
import org.exoplatform.services.jcr.core.ExtendedSession;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
@@ -110,7 +109,6 @@
NodeData data = (NodeData)node.getData();
LockData lData = lockManager.getExactNodeOrCloseParentLock(data);
- //.getLockData(data, CacheableLockManager.SEARCH_EXECMATCH |
CacheableLockManager.SEARCH_CLOSEDPARENT);
if (lData != null)
{
if (lData.getNodeIdentifier().equals(node.getIdentifier()))
@@ -208,11 +206,9 @@
/**
* {@inheritDoc}
*/
- protected boolean isPersitedLockHolder(NodeImpl node) throws RepositoryException
+ protected boolean isPersistedLockHolder(NodeData node) throws RepositoryException
{
- //TODO optimise it
- LockData lData =
lockManager.getExactNodeOrCloseParentLock((NodeData)node.getData());
-
+ LockData lData = lockManager.getExactNodeOrCloseParentLock(node);
return lData != null && isLockHolder(lData);
}
@@ -286,7 +282,7 @@
*/
private boolean isLockHolder(LockData lockData)
{
- return (SystemIdentity.SYSTEM.equals(sessionID) ||
tokens.containsValue(lockData.getTokenHash()));
+ return tokens.containsValue(lockData.getTokenHash());
}
/**
@@ -366,7 +362,11 @@
*/
public void notifyLockRemoved(String nodeIdentifier)
{
- lockedNodes.remove(nodeIdentifier);
+ LockData removedLockData = lockedNodes.remove(nodeIdentifier);
+ //TODO do we really need remove lock token for removed lockData
+ // also remember, tokens that added on another sessions will not be removed
+ String token = getLockToken(removedLockData.getTokenHash());
+ tokens.remove(token);
}
/**
@@ -380,4 +380,28 @@
lockManager.refreshLockData(newLockData);
}
+ /**
+ * {@inheritDoc}
+ */
+ protected boolean checkPersistedLocks(NodeData node) throws LockException
+ {
+ LockData lData = null;
+ try
+ {
+ lData = lockManager.getExactNodeOrCloseParentLock(node);
+ }
+ catch (RepositoryException e)
+ {
+ throw new LockException(e.getMessage(), e);
+ }
+
+ if (lData == null || (!node.getIdentifier().equals(lData.getNodeIdentifier())
&& !lData.isDeep()))
+ {
+ return true;
+ }
+
+ // lock exist, so lets check is current session is LockHolder
+ return isLockHolder(lData);
+ }
+
}