Author: sergiykarpenko
Date: 2010-02-05 12:00:14 -0500 (Fri, 05 Feb 2010)
New Revision: 1707
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
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
Log:
EXOJCR-472: LockJDBCConnection isLockDataExist added
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
16:52:40 UTC (rev 1706)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05
17:00:14 UTC (rev 1707)
@@ -32,44 +32,17 @@
*/
public interface CacheableLockManager extends WorkspaceLockManager
{
-
- // Search constants
/**
- * The exact lock token.
- */
- public static final int SEARCH_EXECMATCH = 1;
-
- /**
- * Lock token of closed parent
- */
- public static final int SEARCH_CLOSEDPARENT = 2;
-
- /**
- * Lock token of closed child
- */
- public static final int SEARCH_CLOSEDCHILD = 4;
-
- /**
* Is lock live for node by nodeIdentifier.
*
* @param nodeIdentifier
*
* @return boolean
- * @throws LockException TODO
+ * @throws LockException
*/
boolean isLockLive(String nodeIdentifier) throws LockException;
/**
- * Search lock in storage. SearchType shows which locks should be returned.
- * See SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT, SEARCH_CLOSEDCHILD. SearchTypes may be
combined.
- *
- * @param node - base node to search locks
- * @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;
-
- /**
* Replace old lockData with new one. Node ID, token can't be replaced.
*
* @param newLockData
@@ -92,9 +65,33 @@
*/
String getLockTokenHash(String lockToken);
- LockData getExactNodeLock(NodeData node) throws RepositoryException;
+ /**
+ * Return lock holding node.
+ *
+ * @param node NodeData
+ * @return LockData for node or null;
+ * @throws RepositoryException
+ */
+ //LockData getExactNodeLock(NodeData node) throws RepositoryException;
+ /**
+ * Return Lock holding node or its parent.
+ *
+ * @param node - NodeData
+ * @return LockData for node or null;
+ * @throws RepositoryException
+ */
LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException;
+ /**
+ * Return Lock holding any nodes child.
+ *
+ * @param node - NodeData
+ * @return LockData for node or null;
+ * @throws RepositoryException
+ */
LockData getClosedChild(NodeData node) throws RepositoryException;
+
+ boolean lockExist(String nodeId) 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
16:52:40 UTC (rev 1706)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-02-05
17:00:14 UTC (rev 1707)
@@ -709,7 +709,10 @@
}
};
- private boolean lockExist(String nodeId)
+ /**
+ * {@inheritDoc}
+ */
+ public boolean lockExist(String nodeId)
{
try
{
@@ -723,10 +726,7 @@
}
/**
- * Calculates md5 hash of string.
- *
- * @param token
- * @return
+ * {@inheritDoc}
*/
public String getLockTokenHash(String token)
{
@@ -744,6 +744,9 @@
return hash;
}
+ /**
+ * {@inheritDoc}
+ */
public LockData getExactNodeOrCloseParentLock(NodeData node) throws
RepositoryException
{
if (node == null)
@@ -761,6 +764,9 @@
return retval;
}
+ /**
+ * {@inheritDoc}
+ */
public LockData getExactNodeLock(NodeData node) throws RepositoryException
{
LockData retval = null;
@@ -771,6 +777,9 @@
return retval;
}
+ /**
+ * {@inheritDoc}
+ */
public LockData getClosedChild(NodeData node) throws RepositoryException
{
LockData retval = null;
@@ -920,7 +929,6 @@
*/
public void closeSessionLockManager(String sessionID)
{
-
sessionLockManagers.remove(sessionID);
}
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
16:52:40 UTC (rev 1706)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-02-05
17:00:14 UTC (rev 1707)
@@ -177,8 +177,7 @@
*/
public boolean holdsLock(NodeData node) throws RepositoryException
{
- //TODO optimise it
- return lockManager.getExactNodeLock(node) != null;
+ return lockManager.lockExist(node.getIdentifier());//.getExactNodeLock(node) !=
null;
}
/**
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
16:52:40 UTC (rev 1706)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05
17:00:14 UTC (rev 1707)
@@ -746,7 +746,10 @@
}
}
- private boolean lockExist(String nodeId) throws RepositoryException
+ /**
+ * {@inheritDoc}
+ */
+ public boolean lockExist(String nodeId) throws RepositoryException
{
//if present in cache - then exists
if (cache.get(makeLockFqn(nodeId), LOCK_DATA) != null)
@@ -760,7 +763,7 @@
try
{
connection = this.lockJDBCContainer.openConnection();
- return connection.getLockData(nodeId) != null;
+ return connection.isLockDataExist(nodeId);
}
finally
{
@@ -863,6 +866,9 @@
// return retval;
// }
+ /**
+ * {@inheritDoc}
+ */
public LockData getExactNodeOrCloseParentLock(NodeData node) throws
RepositoryException
{
if (node == null)
@@ -880,16 +886,22 @@
return retval;
}
- public LockData getExactNodeLock(NodeData node) throws RepositoryException
- {
- LockData retval = null;
- if (node != null)
- {
- retval = getLockDataById(node.getIdentifier());
- }
- return retval;
- }
+ /**
+ * {@inheritDoc}
+ */
+ // public LockData getExactNodeLock(NodeData node) throws RepositoryException
+ // {
+ // LockData retval = null;
+ // if (node != null)
+ // {
+ // retval = getLockDataById(node.getIdentifier());
+ // }
+ // return retval;
+ // }
+ /**
+ * {@inheritDoc}
+ */
public LockData getClosedChild(NodeData node) throws RepositoryException
{
LockData retval = null;
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05
16:52:40 UTC (rev 1706)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05
17:00:14 UTC (rev 1707)
@@ -53,6 +53,8 @@
protected String GET_LOCK_DATA;
+ protected String IS_LOCK_DATA_EXIST;
+
// column names
protected static String COLUMN_WS_NAME = "WS_NAME";
@@ -81,6 +83,8 @@
private PreparedStatement getLockData;
+ private PreparedStatement isLockDataExist;
+
private Connection dbConnection;
private String wsName;
@@ -113,6 +117,9 @@
GET_LOCKED_NODES = "select NODE_ID from JCR_LOCKS where WS_NAME=?";
GET_LOCK_DATA = "select * from JCR_LOCKS where NODE_ID=? and WS_NAME=?";
+
+ IS_LOCK_DATA_EXIST = "select NODE_ID from JCR_LOCKS where NODE_ID=? and
WS_NAME=?";
+
}
/**
@@ -311,9 +318,44 @@
}
/**
- * Check if connection is alive and opened
+ * Check is LockData by node identifier exist.
+ *
+ * @param identifier
* @return
+ * @throws RepositoryException
*/
+ public boolean isLockDataExist(String identifier) throws RepositoryException
+ {
+ if (!isOpened())
+ {
+ throw new IllegalStateException("Connection is closed");
+ }
+ try
+ {
+ if (isLockDataExist == null)
+ {
+ isLockDataExist = dbConnection.prepareStatement(IS_LOCK_DATA_EXIST);
+ }
+ else
+ {
+ isLockDataExist.clearParameters();
+ }
+ isLockDataExist.setString(1, identifier);
+ isLockDataExist.setString(2, wsName);
+ // get result set
+ ResultSet result = getLockData.executeQuery();
+ return result.next();
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * Check if connection is alive and opened
+ * @return boolean
+ */
public boolean isOpened()
{
try