[exo-jcr-commits] exo-jcr SVN: r1702 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/core/lock and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Feb 5 10:00:41 EST 2010


Author: sergiykarpenko
Date: 2010-02-05 10:00:41 -0500 (Fri, 05 Feb 2010)
New Revision: 1702

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/LockJDBCConnection.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java
Log:
EXOJCR-472: CacheableLockManager - exceptions throwing updated

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 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java	2010-02-05 15:00:41 UTC (rev 1702)
@@ -137,11 +137,6 @@
     */
    private LockRemover lockRemover;
 
-   /**
-    * The current Transaction Manager
-    */
-   private TransactionManager tm;
-
    private Cache<Serializable, Object> cache;
 
    private LockJDBCContainer lockJDBCContainer;
@@ -231,7 +226,7 @@
       // make cache
       if (config.getLockManager() != null)
       {
-         this.tm = transactionManager;
+
          String dataSourceName = config.getLockManager().getParameterValue(DATA_SOURCE);
          lockJDBCContainer = new LockJDBCContainer(dataSourceName, config.getName());
 
@@ -273,15 +268,34 @@
    public int getNumLocks()
    {
       int lockNum = -1;
+      LockJDBCConnection connection = null;
       try
       {
-         LockJDBCConnection connection = this.lockJDBCContainer.openConnection();
+         connection = this.lockJDBCContainer.openConnection();
          lockNum = connection.getLockedNodes().size();
       }
-      catch (LockException e)
+      catch (RepositoryException e)
       {
          // skip
       }
+      finally
+      {
+         if (connection != null)
+         {
+            try
+            {
+               connection.close();
+            }
+            catch (IllegalStateException e)
+            {
+               // do nothing
+            }
+            catch (RepositoryException e)
+            {
+               // do nothing 
+            }
+         }
+      }
       return lockNum;
    }
 
@@ -303,7 +317,14 @@
     */
    public boolean isLockLive(String nodeId) throws LockException
    {
-      return this.lockExist(nodeId);
+      try
+      {
+         return this.lockExist(nodeId);
+      }
+      catch (RepositoryException e)
+      {
+         throw new LockException(e.getMessage(), e);
+      }
    }
 
    /**
@@ -415,7 +436,7 @@
          {
             log.error(e.getLocalizedMessage(), e);
          }
-         catch (LockException e)
+         catch (RepositoryException e)
          {
             log.error(e.getLocalizedMessage(), e);
          }
@@ -471,15 +492,22 @@
 
       public void apply() throws LockException
       {
-         // invoke internalLock in LOCK operation
-         if (type == ExtendedEvent.LOCK)
+         try
          {
-            internalLock(sessionId, identifier);
+            // invoke internalLock in LOCK operation
+            if (type == ExtendedEvent.LOCK)
+            {
+               internalLock(sessionId, identifier);
+            }
+            // invoke internalUnLock in UNLOCK operation
+            else if (type == ExtendedEvent.UNLOCK)
+            {
+               internalUnLock(sessionId, identifier);
+            }
          }
-         // invoke internalUnLock in UNLOCK operation
-         else if (type == ExtendedEvent.UNLOCK)
+         catch (RepositoryException e)
          {
-            internalUnLock(sessionId, identifier);
+            throw new LockException(e.getMessage(), e);
          }
       }
 
@@ -499,7 +527,6 @@
     */
    public void refreshLockData(LockData newLockData) throws LockException
    {
-      // TODO
       // Write to DB
       LockJDBCConnection connection = null;
       try
@@ -541,7 +568,6 @@
     */
    public synchronized void removeExpired()
    {
-      // TODO
       final List<String> removeLockList = new ArrayList<String>();
       try
       {
@@ -561,8 +587,9 @@
             removeLock(rLock);
          }
       }
-      catch (LockException e)
+      catch (RepositoryException e)
       {
+         // Used from LockRemover thread, so no exception must be thrown.
          log.error("Exception removing expired locks", e);
       }
    }
@@ -589,10 +616,10 @@
    }
 
    /**
-    * Copy <code>PropertyData prop<code> to new TransientItemData
+    * Copy <code>PropertyData prop<code> to new TransientItemData.
     * 
-    * @param prop
-    * @return
+    * @param prop - PropertyData
+    * @return TransientItemData
     * @throws RepositoryException
     */
    private TransientItemData copyItemData(PropertyData prop) throws RepositoryException
@@ -616,14 +643,13 @@
     * @param nodeIdentifier
     * @throws LockException
     */
-   private synchronized void internalLock(String sessionId, String nodeIdentifier) throws LockException
+   private synchronized void internalLock(String sessionId, String nodeIdentifier) throws RepositoryException
    {
       CacheableSessionLockManager sessionLockManager = sessionLockManagers.get(sessionId);
       if (sessionLockManager != null && sessionLockManager.cotainsPendingLock(nodeIdentifier))
       {
          LockData lockData = sessionLockManager.getPendingLock(nodeIdentifier);
 
-         //TODO
          // add to DB for first
          LockJDBCConnection connection = null;
          try
@@ -635,15 +661,11 @@
 
             // if any SQL exception, that nothing should be placed to cache
             Fqn<String> lockPath = makeLockFqn(lockData.getNodeIdentifier());
-            Node<Serializable, Object> node = cache.getRoot().addChild(lockPath);
+
             cache.put(lockPath, LOCK_DATA, lockData);
 
             sessionLockManager.notifyLockPersisted(nodeIdentifier);
          }
-         catch (RepositoryException e)
-         {
-            throw new LockException(e);
-         }
          finally
          {
             if (connection != null)
@@ -677,13 +699,12 @@
     * @param nodeIdentifier
     * @throws LockException
     */
-   private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
+   private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws RepositoryException
    {
       LockData lData = getLockDataById(nodeIdentifier);
 
       if (lData != null)
       {
-         //TODO
          LockJDBCConnection connection = null;
          try
          {
@@ -725,9 +746,8 @@
       }
    }
 
-   private boolean lockExist(String nodeId) throws LockException
+   private boolean lockExist(String nodeId) throws RepositoryException
    {
-      //TODO
       //if present in cache - then exists
       if (cache.get(makeLockFqn(nodeId), LOCK_DATA) != null)
       {
@@ -788,7 +808,7 @@
    /**
     * {@inheritDoc}
     */
-   public LockData getLockData(NodeData data, int searchType)
+   public LockData getLockData(NodeData data, int searchType) throws LockException
    {
       if (data == null)
          return null;
@@ -837,17 +857,14 @@
       }
       catch (RepositoryException e)
       {
-         //TODO 
-         log.error(e.getMessage(), e);
-         return null;
+         throw new LockException(e.getMessage(), e);
       }
 
       return retval;
    }
 
-   protected LockData getLockDataById(String nodeId) throws LockException
+   protected LockData getLockDataById(String nodeId) throws RepositoryException
    {
-      //TODO
       LockData lData = (LockData)cache.get(makeLockFqn(nodeId), LOCK_DATA);
 
       if (lData != null)
@@ -883,11 +900,8 @@
       }
    }
 
-   protected synchronized List<LockData> getLockList() throws LockException
+   protected synchronized List<LockData> getLockList() throws RepositoryException
    {
-
-      //TODO
-
       LockJDBCConnection connection = null;
       try
       {
@@ -905,7 +919,6 @@
             {
                locksData.add(connection.getLockData(nodeId));
             }
-
          }
          return locksData;
       }
@@ -919,13 +932,11 @@
             }
             catch (IllegalStateException e)
             {
-               // TODO Auto-generated catch block
-               e.printStackTrace();
+               log.error(e.getMessage(), e);
             }
             catch (RepositoryException e)
             {
-               // TODO Auto-generated catch block
-               e.printStackTrace();
+               log.error(e.getMessage(), e);
             }
          }
       }

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 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java	2010-02-05 15:00:41 UTC (rev 1702)
@@ -28,7 +28,6 @@
 import java.util.Set;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.lock.LockException;
 
 /**
  * Created by The eXo Platform SAS.
@@ -121,9 +120,9 @@
     * 
     * @param data
     * @return
-    * @throws LockException
+    * @throws RepositoryException
     */
-   public int addLockData(LockData data) throws LockException
+   public int addLockData(LockData data) throws RepositoryException
    {
       if (!isOpened())
       {
@@ -152,7 +151,7 @@
       }
       catch (SQLException e)
       {
-         throw new LockException(e);
+         throw new RepositoryException(e);
       }
    }
 
@@ -161,9 +160,9 @@
     * 
     * @param nodeID
     * @return
-    * @throws LockException
+    * @throws RepositoryException
     */
-   public int removeLockData(String nodeID) throws LockException
+   public int removeLockData(String nodeID) throws RepositoryException
    {
       if (!isOpened())
       {
@@ -187,7 +186,7 @@
       }
       catch (SQLException e)
       {
-         throw new LockException(e);
+         throw new RepositoryException(e);
       }
    }
 
@@ -196,9 +195,9 @@
     * 
     * @param data
     * @return
-    * @throws LockException
+    * @throws RepositoryException
     */
-   public int refreshLockData(LockData data) throws LockException
+   public int refreshLockData(LockData data) throws RepositoryException
    {
       if (!isOpened())
       {
@@ -224,7 +223,7 @@
       }
       catch (SQLException e)
       {
-         throw new LockException(e);
+         throw new RepositoryException(e);
       }
    }
 
@@ -232,9 +231,9 @@
     * Returns the set of locked nodes identifiers
     * 
     * @return
-    * @throws LockException
+    * @throws RepositoryException
     */
-   public Set<String> getLockedNodes() throws LockException
+   public Set<String> getLockedNodes() throws RepositoryException
    {
       if (!isOpened())
       {
@@ -264,7 +263,7 @@
       }
       catch (SQLException e)
       {
-         throw new LockException(e);
+         throw new RepositoryException(e);
       }
    }
 
@@ -272,11 +271,11 @@
     * Returns LockData for given node identifier from database
     * or null if not exists
     * 
-    * @param identifier
-    * @return
-    * @throws LockException
+    * @param identifier - locked node identifier
+    * @return LockData
+    * @throws RepositoryException
     */
-   public LockData getLockData(String identifier) throws LockException
+   public LockData getLockData(String identifier) throws RepositoryException
    {
       if (!isOpened())
       {
@@ -307,7 +306,7 @@
       }
       catch (SQLException e)
       {
-         throw new LockException(e);
+         throw new RepositoryException(e);
       }
    }
 
@@ -338,7 +337,6 @@
    {
       if (isOpened())
       {
-
          try
          {
             dbConnection.close();

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java	2010-02-05 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java	2010-02-05 15:00:41 UTC (rev 1702)
@@ -94,7 +94,7 @@
 
    }
 
-   public LockJDBCConnection openConnection() throws LockException
+   public LockJDBCConnection openConnection() throws RepositoryException
    {
       try
       {
@@ -102,7 +102,7 @@
       }
       catch (SQLException e)
       {
-         throw new LockException(e);
+         throw new RepositoryException(e);
       }
    }
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java	2010-02-05 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java	2010-02-05 15:00:41 UTC (rev 1702)
@@ -26,7 +26,6 @@
 import java.util.Set;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.lock.LockException;
 
 /**
  * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
@@ -202,7 +201,7 @@
          connection.addLockData(new LockData("identifier", "hash", false, false, "owner", 100));
          fail("exception expected!");
       }
-      catch (LockException e)
+      catch (RepositoryException e)
       {
          // it's ok
       }



More information about the exo-jcr-commits mailing list