[exo-jcr-commits] exo-jcr SVN: r564 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 11 09:47:46 EST 2009


Author: tolusha
Date: 2009-11-11 09:47:46 -0500 (Wed, 11 Nov 2009)
New Revision: 564

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/TesterLockManagerImpl.java
   jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml
Log:
EXOJCR-205: small refactoring

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java	2009-11-11 14:43:09 UTC (rev 563)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java	2009-11-11 14:47:46 UTC (rev 564)
@@ -89,7 +89,7 @@
 
       for (Modification m : modifications)
       {
-         if (m.getFqn().hasElement(JBossCacheStorage.SESSION))
+         if (m.getFqn().get(0).equals(JBossCacheStorage.SESSION))
          {
             switch (m.getType())
             {
@@ -98,13 +98,14 @@
                case PUT_DATA :
                   break;
                case PUT_KEY_VALUE :
+                  // begin new changes log
                   if (m.getKey().equals(JBossCacheStorage.SESSION_ID))
                   {
                      sessionId = (String)m.getValue();
                   }
                   break;
                case REMOVE_DATA :
-                  // perform lock or unlock operation
+                  // end changes log
                   if (lockChanges.size() == 2)
                   {
                      if (lockChanges.get(0).getType() == ModificationType.PUT_KEY_VALUE
@@ -112,11 +113,10 @@
                      {
                         performLock(lockChanges, sessionId);
                      }
-                     else if (lockChanges.get(0).getType() == ModificationType.REMOVE_NODE
-                        && lockChanges.get(1).getType() == ModificationType.REMOVE_NODE)
+                     else if (lockChanges.get(0).getType() == ModificationType.REMOVE_KEY_VALUE
+                        && lockChanges.get(1).getType() == ModificationType.REMOVE_KEY_VALUE)
                      {
-                        PropertyData propertyData = (PropertyData)lockChanges.get(0).getValue();
-                        performUnLock(lockChanges, propertyData.getParentIdentifier(), sessionId);
+                        performUnLock(lockChanges, (String)lockChanges.get(0).getFqn().get(1), sessionId);
                      }
                      else
                      {
@@ -147,7 +147,7 @@
                   throw new CacheException("Unknown modification " + m.getType());
             }
          }
-         else if (m.getFqn().hasElement(JBossCacheStorage.PROPS))
+         else if (m.getFqn().get(0).equals(JBossCacheStorage.PROPS))
          {
             switch (m.getType())
             {
@@ -156,12 +156,11 @@
                case PUT_DATA :
                   break;
                case PUT_KEY_VALUE :
+                  // lock operation
                   if (m.getKey().equals(JBossCacheStorage.ITEM_DATA))
                   {
-                     PropertyData propertyData = (PropertyData)m.getValue();
-                     InternalQName propertyName = propertyData.getQPath().getName();
-
-                     if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
+                     InternalQName propName = ((PropertyData)m.getValue()).getQPath().getName();
+                     if (propName.equals(Constants.JCR_LOCKISDEEP) || propName.equals(Constants.JCR_LOCKOWNER))
                      {
                         lockChanges.add(m);
                      }
@@ -172,16 +171,6 @@
                case REMOVE_KEY_VALUE :
                   break;
                case REMOVE_NODE :
-                  if (m.getKey().equals(JBossCacheStorage.ITEM_DATA))
-                  {
-                     PropertyData propertyData = (PropertyData)m.getValue();
-                     InternalQName propertyName = propertyData.getQPath().getName();
-
-                     if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
-                     {
-                        lockChanges.add(m);
-                     }
-                  }
                   break;
                case MOVE :
                   break;
@@ -189,38 +178,56 @@
                   throw new CacheException("Unknown modification " + m.getType());
             }
          }
-         else if (m.getFqn().hasElement(JBossCacheStorage.NODES))
+         else if (m.getFqn().get(0).equals(JBossCacheStorage.NODES))
          {
-            int nodesPos = getElementPosition(m.getFqn(), JBossCacheStorage.NODES);
-            // this is a node and node is locked
-            String nodeIdentifier = (String)m.getFqn().get(nodesPos + 1);
-            if (m.getFqn().size() == nodesPos + 2)
+            switch (m.getType())
             {
-               if (lockManager.hasLockNode(nodeIdentifier))
-               {
-                  switch (m.getType())
+               case PUT_DATA_ERASE :
+                  break;
+               case PUT_DATA :
+                  if (m.getFqn().size() == 2)
                   {
-                     case PUT_DATA_ERASE :
-                        break;
-                     case PUT_DATA :
+                     String nodeIdentifier = (String)m.getFqn().get(1);
+                     if (lockManager.hasLockNode(nodeIdentifier))
+                     {
                         removedLock.remove(nodeIdentifier);
-                        break;
-                     case PUT_KEY_VALUE :
-                        break;
-                     case REMOVE_DATA :
-                        break;
-                     case REMOVE_KEY_VALUE :
-                        break;
-                     case REMOVE_NODE :
+                     }
+                  }
+                  break;
+               case PUT_KEY_VALUE :
+                  break;
+               case REMOVE_DATA :
+                  break;
+               case REMOVE_KEY_VALUE :
+                  // unLock operation
+                  if (m.getKey().equals(Constants.JCR_LOCKISDEEP.getAsString())
+                     || m.getKey().equals(Constants.JCR_LOCKOWNER.getAsString()))
+                  {
+                     lockChanges.add(m);
+                  }
+                  break;
+               case REMOVE_NODE :
+                  if (m.getFqn().size() == 2)
+                  {
+                     String nodeIdentifier = (String)m.getFqn().get(1);
+                     if (lockManager.hasLockNode(nodeIdentifier))
+                     {
                         removedLock.add(nodeIdentifier);
-                        break;
-                     case MOVE :
+                     }
+                  }
+                  break;
+               case MOVE :
+                  if (m.getFqn().size() == 2)
+                  {
+                     String nodeIdentifier = (String)m.getFqn().get(1);
+                     if (lockManager.hasLockNode(nodeIdentifier))
+                     {
                         removedLock.remove(nodeIdentifier);
-                        break;
-                     default :
-                        throw new CacheException("Unknown modification " + m.getType());
+                     }
                   }
-               }
+                  break;
+               default :
+                  throw new CacheException("Unknown modification " + m.getType());
             }
          }
       }
@@ -316,13 +323,4 @@
       return null;
    }
 
-   private int getElementPosition(Fqn<String> fqn, String element)
-   {
-      for (int i = 0; i < fqn.size(); i++)
-         if (fqn.get(i).equals(element))
-            return i;
-
-      return -1;
-   }
-
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/TesterLockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/TesterLockManagerImpl.java	2009-11-11 14:43:09 UTC (rev 563)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/TesterLockManagerImpl.java	2009-11-11 14:47:46 UTC (rev 564)
@@ -16,16 +16,12 @@
  */
 package org.exoplatform.services.jcr.impl.storage.jbosscache;
 
-import sun.security.util.PendingException;
-
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
 import org.exoplatform.services.jcr.impl.core.lock.LockData;
 import org.exoplatform.services.jcr.impl.core.lock.LockManagerImpl;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
 import org.jboss.cache.factories.annotations.NonVolatile;
 
-import java.util.Map;
-
 import javax.jcr.lock.LockException;
 
 /**
@@ -40,9 +36,9 @@
 public class TesterLockManagerImpl extends LockManagerImpl
 {
 
-   private String nodeIdentifier;
+   private String nodeIdentifier = null;
 
-   private String sessionId;
+   private String sessionId = null;
 
    public TesterLockManagerImpl(WorkspacePersistentDataManager dataManager, WorkspaceEntry config)
    {
@@ -59,6 +55,9 @@
     */
    public synchronized void internalLock(String nodeIdentifier) throws LockException
    {
+      if (this.nodeIdentifier != null)
+         throw new LockException("NodeIdentifier already exist!");
+
       this.nodeIdentifier = nodeIdentifier;
    }
 
@@ -67,6 +66,12 @@
    */
    public synchronized void internalUnLock(String nodeIdentifier, String sessionId) throws LockException
    {
+      if (this.nodeIdentifier != null)
+         throw new LockException("NodeIdentifier already exist!");
+
+      if (this.sessionId != null)
+         throw new LockException("SessionId already exist!");
+
       this.nodeIdentifier = nodeIdentifier;
       this.sessionId = sessionId;
    }

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml	2009-11-11 14:43:09 UTC (rev 563)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml	2009-11-11 14:47:46 UTC (rev 564)
@@ -65,6 +65,12 @@
         <properties>
         </properties>
       </loader>   
+      
+      <loader class="org.exoplatform.services.jcr.impl.storage.jbosscache.LockCacheLoader" 
+              async="false" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false">
+        <properties>
+        </properties>
+      </loader>   
    </loaders>
    
     <!-- Enable batching -->



More information about the exo-jcr-commits mailing list