Author: sergiykarpenko
Date: 2010-02-05 11:16:16 -0500 (Fri, 05 Feb 2010)
New Revision: 1705
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.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
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
Log:
EXOJCR-472: CacheableLockManager.getLockData splitted to three methods
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05
15:22:40 UTC (rev 1704)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05
16:16:16 UTC (rev 1705)
@@ -19,6 +19,7 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.lock.WorkspaceLockManager;
+import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
/**
@@ -66,7 +67,7 @@
* @param searchType - combination of SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT,
SEARCH_CLOSEDCHILD search types
* @return LockData or null
*/
- public LockData getLockData(NodeData node, int searchType) throws LockException;
+ // public LockData getLockData(NodeData node, int searchType) throws LockException;
/**
* Replace old lockData with new one. Node ID, token can't be replaced.
@@ -90,4 +91,10 @@
* @return - hash string
*/
String getLockTokenHash(String lockToken);
+
+ LockData getExactNodeLock(NodeData node) throws RepositoryException;
+
+ LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException;
+
+ LockData getClosedChild(NodeData node) throws RepositoryException;
}
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-02-05
15:22:40 UTC (rev 1704)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-02-05
16:16:16 UTC (rev 1705)
@@ -744,63 +744,51 @@
return hash;
}
- /**
- * {@inheritDoc}
- */
- public LockData getLockData(NodeData data, int searchType)
+ public LockData getExactNodeOrCloseParentLock(NodeData node) throws
RepositoryException
{
- if (data == null)
+ if (node == null)
return null;
LockData retval = null;
- try
+ retval = getLockDataById(node.getIdentifier());
+ if (retval == null)
{
- if ((searchType & SEARCH_EXECMATCH) != 0)
+ NodeData parentData =
(NodeData)dataManager.getItemData(node.getParentIdentifier());
+ if (parentData != null)
{
- retval = getLockDataById(data.getIdentifier());
+ retval = getExactNodeOrCloseParentLock(parentData);
}
- if (retval == null && (searchType & SEARCH_CLOSEDPARENT) != 0)
- {
+ }
+ return retval;
+ }
- NodeData parentData =
(NodeData)dataManager.getItemData(data.getParentIdentifier());
- if (parentData != null)
- {
- retval = getLockDataById(parentData.getIdentifier());
- // parent not found try to fo upper
- if (retval == null)
- {
- retval = getLockData(parentData, SEARCH_CLOSEDPARENT);
- }
- }
- }
- if (retval == null && (searchType & SEARCH_CLOSEDCHILD) != 0)
- {
+ public LockData getExactNodeLock(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+ if (node != null)
+ {
+ retval = getLockDataById(node.getIdentifier());
+ }
+ return retval;
+ }
- List<NodeData> childData = dataManager.getChildNodesData(data);
- for (NodeData nodeData : childData)
- {
- retval = getLockDataById(nodeData.getIdentifier());
- if (retval != null)
- break;
- }
- if (retval == null)
- {
- // child not found try to find diper
- for (NodeData nodeData : childData)
- {
- retval = getLockData(nodeData, SEARCH_CLOSEDCHILD);
- if (retval != null)
- break;
- }
- }
- }
+ public LockData getClosedChild(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+
+ List<NodeData> childData = dataManager.getChildNodesData(node);
+ for (NodeData nodeData : childData)
+ {
+ retval = getLockDataById(nodeData.getIdentifier());
+ if (retval != null)
+ return retval;
}
- catch (RepositoryException e)
+ // child not found try to find dipper
+ for (NodeData nodeData : childData)
{
- //TODO
- log.error(e.getMessage(), e);
- return null;
+ retval = getClosedChild(nodeData);
+ if (retval != null)
+ return retval;
}
-
return retval;
}
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-02-05
15:22:40 UTC (rev 1704)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-02-05
16:16:16 UTC (rev 1705)
@@ -106,9 +106,8 @@
NodeData data = (NodeData)node.getData();
- LockData lData =
- lockManager
- .getLockData(data, CacheableLockManager.SEARCH_EXECMATCH |
CacheableLockManager.SEARCH_CLOSEDPARENT);
+ LockData lData = lockManager.getExactNodeOrCloseParentLock(data);
+ //.getLockData(data, CacheableLockManager.SEARCH_EXECMATCH |
CacheableLockManager.SEARCH_CLOSEDPARENT);
if (lData != null)
{
if (lData.getNodeIdentifier().equals(node.getIdentifier()))
@@ -121,7 +120,7 @@
}
}
- if (isDeep && lockManager.getLockData(data,
CacheableLockManager.SEARCH_CLOSEDCHILD) != null)
+ if (isDeep && lockManager.getClosedChild(data) != null)
{
throw new LockException("Some child node is locked.");
}
@@ -154,9 +153,7 @@
*/
public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
{
- LockData lData =
- lockManager.getLockData((NodeData)node.getData(),
CacheableLockManager.SEARCH_EXECMATCH
- | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ LockData lData =
lockManager.getExactNodeOrCloseParentLock((NodeData)node.getData());
if (lData == null ||
(!node.getInternalIdentifier().equals(lData.getNodeIdentifier()) &&
!lData.isDeep()))
{
@@ -180,7 +177,8 @@
*/
public boolean holdsLock(NodeData node) throws RepositoryException
{
- return lockManager.getLockData(node, CacheableLockManager.SEARCH_EXECMATCH) !=
null;
+ //TODO optimise it
+ return lockManager.getExactNodeLock(node) != null;
}
/**
@@ -188,9 +186,15 @@
*/
public boolean isLocked(NodeData node) throws LockException
{
- LockData lData =
- lockManager
- .getLockData(node, CacheableLockManager.SEARCH_EXECMATCH |
CacheableLockManager.SEARCH_CLOSEDPARENT);
+ 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()))
{
@@ -204,9 +208,8 @@
*/
public boolean isLockHolder(NodeImpl node) throws RepositoryException
{
- LockData lData =
- lockManager.getLockData((NodeData)node.getData(),
CacheableLockManager.SEARCH_EXECMATCH
- | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ //TODO optimise it
+ LockData lData =
lockManager.getExactNodeOrCloseParentLock((NodeData)node.getData());
return lData != null && isLockHolder(lData);
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05
15:22:40 UTC (rev 1704)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05
16:16:16 UTC (rev 1705)
@@ -808,58 +808,106 @@
/**
* {@inheritDoc}
*/
- public LockData getLockData(NodeData data, int searchType) throws LockException
+ // public LockData getLockData(NodeData data, int searchType) throws LockException
+ // {
+ // if (data == null)
+ // return null;
+ // LockData retval = null;
+ // try
+ // {
+ // if ((searchType & SEARCH_EXECMATCH) != 0)
+ // {
+ // retval = getLockDataById(data.getIdentifier());
+ // }
+ // if (retval == null && (searchType & SEARCH_CLOSEDPARENT) != 0)
+ // {
+ //
+ // NodeData parentData =
(NodeData)dataManager.getItemData(data.getParentIdentifier());
+ // if (parentData != null)
+ // {
+ // retval = getLockDataById(parentData.getIdentifier());
+ // // parent not found try to fo upper
+ // if (retval == null)
+ // {
+ // retval = getLockData(parentData, SEARCH_CLOSEDPARENT);
+ // }
+ // }
+ // }
+ // if (retval == null && (searchType & SEARCH_CLOSEDCHILD) != 0)
+ // {
+ //
+ // List<NodeData> childData = dataManager.getChildNodesData(data);
+ // for (NodeData nodeData : childData)
+ // {
+ // retval = getLockDataById(nodeData.getIdentifier());
+ // if (retval != null)
+ // break;
+ // }
+ // if (retval == null)
+ // {
+ // // child not found try to find diper
+ // for (NodeData nodeData : childData)
+ // {
+ // retval = getLockData(nodeData, SEARCH_CLOSEDCHILD);
+ // if (retval != null)
+ // break;
+ // }
+ // }
+ // }
+ // }
+ // catch (RepositoryException e)
+ // {
+ // throw new LockException(e.getMessage(), e);
+ // }
+ //
+ // return retval;
+ // }
+
+ public LockData getExactNodeOrCloseParentLock(NodeData node) throws
RepositoryException
{
- if (data == null)
+ if (node == null)
return null;
LockData retval = null;
- try
+ retval = getLockDataById(node.getIdentifier());
+ if (retval == null)
{
- if ((searchType & SEARCH_EXECMATCH) != 0)
+ NodeData parentData =
(NodeData)dataManager.getItemData(node.getParentIdentifier());
+ if (parentData != null)
{
- retval = getLockDataById(data.getIdentifier());
+ retval = getExactNodeOrCloseParentLock(parentData);
}
- if (retval == null && (searchType & SEARCH_CLOSEDPARENT) != 0)
- {
+ }
+ return retval;
+ }
- NodeData parentData =
(NodeData)dataManager.getItemData(data.getParentIdentifier());
- if (parentData != null)
- {
- retval = getLockDataById(parentData.getIdentifier());
- // parent not found try to fo upper
- if (retval == null)
- {
- retval = getLockData(parentData, SEARCH_CLOSEDPARENT);
- }
- }
- }
- if (retval == null && (searchType & SEARCH_CLOSEDCHILD) != 0)
- {
+ public LockData getExactNodeLock(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+ if (node != null)
+ {
+ retval = getLockDataById(node.getIdentifier());
+ }
+ return retval;
+ }
- List<NodeData> childData = dataManager.getChildNodesData(data);
- for (NodeData nodeData : childData)
- {
- retval = getLockDataById(nodeData.getIdentifier());
- if (retval != null)
- break;
- }
- if (retval == null)
- {
- // child not found try to find diper
- for (NodeData nodeData : childData)
- {
- retval = getLockData(nodeData, SEARCH_CLOSEDCHILD);
- if (retval != null)
- break;
- }
- }
- }
+ public LockData getClosedChild(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+
+ List<NodeData> childData = dataManager.getChildNodesData(node);
+ for (NodeData nodeData : childData)
+ {
+ retval = getLockDataById(nodeData.getIdentifier());
+ if (retval != null)
+ return retval;
}
- catch (RepositoryException e)
+ // child not found try to find dipper
+ for (NodeData nodeData : childData)
{
- throw new LockException(e.getMessage(), e);
+ retval = getClosedChild(nodeData);
+ if (retval != null)
+ return retval;
}
-
return retval;
}