[exo-jcr-commits] exo-jcr SVN: r817 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 24 03:44:16 EST 2009


Author: sergiykarpenko
Date: 2009-11-24 03:44:16 -0500 (Tue, 24 Nov 2009)
New Revision: 817

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
Log:
EXOJCR-246: JBossCacheStorageConnection references fixed

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-11-24 08:28:08 UTC (rev 816)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-11-24 08:44:16 UTC (rev 817)
@@ -214,37 +214,8 @@
       // REFERENCEs hadnling
       if (data.getType() == PropertyType.REFERENCE)
       {
-         Fqn propIdentifier = Fqn.fromElements(data.getIdentifier());
-
-         for (ValueData value : data.getValues())
-         {
-
-            String refNodeUUID;
-            try
-            {
-               refNodeUUID = ValueDataConvertor.readString(value);
-            }
-            catch (UnsupportedEncodingException e)
-            {
-               throw new RepositoryException(e);
-            }
-            catch (IOException e)
-            {
-               throw new RepositoryException(e);
-            }
-
-            Fqn<String> refNode = makeNodeFqn(refNodeUUID);
-
-            // add to $REFS map
-            Node<Serializable, Object> refParent = refsRoot.getChild(refNode);
-            if (refParent == null)
-            {
-               refParent = refsRoot.addChild(refNode);
-            }
-
-            refParent.addChild(propIdentifier);
-         }
-      }      
+         addReferences(data);
+      }
    }
 
    /**
@@ -344,6 +315,12 @@
          throw new RepositoryException("FATAL PropertyData already empty " + data.getQPath().getAsString());
       }
 
+      // REFERENCEs handling
+      if (prevData.getType() == PropertyType.REFERENCE)
+      {
+         removeReferences(prevData);
+      }
+
       // remove from parent's properties attributes
       // TODO validate does deleted
       if (parent.remove(data.getQPath().getName().getAsString()) == null)
@@ -357,69 +334,7 @@
       {
          LOG.warn("Property want not deleted " + data.getQPath().getAsString());
       }
-      
-      // REFERENCEs handling
-      if (prevData.getType() == PropertyType.REFERENCE)
-      {
-         // get values from cahce
 
-         Set<String> remNodes = new HashSet<String>();
-
-         for (ValueData value : prevData.getValues())
-         {
-            try
-            {
-               remNodes.add(ValueDataConvertor.readString(value));
-            }
-            catch (UnsupportedEncodingException e)
-            {
-               throw new RepositoryException(e);
-            }
-            catch (IOException e)
-            {
-               throw new RepositoryException(e);
-            }
-         }
-
-         for (String refNodeUUID : remNodes)
-         {
-            // remove property from referencedNode in $REFS map
-            Node<Serializable, Object> refParent = refsRoot.getChild(makeNodeFqn(refNodeUUID));
-
-            if (refParent != null)
-            {
-               if (refParent.hasChild(propUUID))
-               {
-                  // do we need remove node record also
-                  boolean removeParent = (refParent.getChildrenNames().size() == 1);
-
-                  if (!refParent.removeChild(propUUID))
-                  {
-                     throw new RepositoryException("FATAL Reference property was not removed from REFS table of node "
-                        + refNodeUUID);
-                  }
-
-                  if (removeParent)
-                  {
-                     if (!refsRoot.removeChild(makeNodeFqn(refNodeUUID)))
-                     {
-                        throw new RepositoryException("FATAL Node record was node removed from REFS table "
-                           + refNodeUUID);
-                     }
-                  }
-               }
-               else
-               {
-                  LOG.warn("Property reference " + data.getIdentifier() + " to node " + refNodeUUID
-                     + " was already removed.");
-               }
-            }
-            else
-            {
-               LOG.warn("Reference record of node " + refNodeUUID + " was already removed.");
-            }
-         }
-      }      
    }
 
    /**
@@ -1010,96 +925,14 @@
          throw new RepositoryException("FATAL Previous Property data is null. Parent " + data.getQPath().getAsString());
       }
 
-      // update data
-      prop.put(ITEM_DATA, data);
-
       // REFERENCEs handling
       if (prevData.getType() == PropertyType.REFERENCE || data.getType() == PropertyType.REFERENCE)
       {
-         // get Set of old values
-         Set<String> removeSet = new HashSet<String>();
-         if (prevData.getType() == PropertyType.REFERENCE)
-         {
-            for (ValueData value : prevData.getValues())
-            {
-               try
-               {
-                  removeSet.add(ValueDataConvertor.readString(value));
-               }
-               catch (UnsupportedEncodingException e)
-               {
-                  throw new RepositoryException(e);
-               }
-               catch (IOException e)
-               {
-                  throw new RepositoryException(e);
-               }
-            }
-         }
+         updateReferences(prevData, data);
+      }
 
-         // check new
-         Set<String> addSet = new HashSet<String>();
-         if (data.getType() == PropertyType.REFERENCE)
-         {
-            for (ValueData value : data.getValues())
-            {
-               try
-               {
-                  addSet.add(ValueDataConvertor.readString(value));
-               }
-               catch (UnsupportedEncodingException e)
-               {
-                  throw new RepositoryException(e);
-               }
-               catch (IOException e)
-               {
-                  throw new RepositoryException(e);
-               }
-            }
-         }
-
-         String[] added = new String[addSet.size()];
-         addSet.toArray(added);
-
-         for (String id : added)
-         {
-            if (removeSet.contains(id))
-            {
-               removeSet.remove(id);
-               addSet.remove(id);
-            }
-         }
-
-         // remove references to nodes
-         for (String id : removeSet)
-         {
-            Node<Serializable, Object> node = refsRoot.getChild(Fqn.fromElements(id));
-            if (!node.removeChild(propFqn))
-            {
-               throw new RepositoryException("FATAL Reference property was not removed from REFS table of node " + id);
-            }
-
-            // check node
-            if (node.getChildrenNames().size() == 0)
-            {
-               //TODO remove children
-               refsRoot.removeChild(Fqn.fromElements(id));
-            }
-         }
-
-         // add references to nodes
-         for (String id : addSet)
-         {
-            Fqn nodeFqn = Fqn.fromElements(id);
-            Node<Serializable, Object> node = refsRoot.getChild(nodeFqn);
-
-            if (node == null)
-            {
-               node = refsRoot.addChild(nodeFqn);
-            }
-            node.addChild(propFqn);
-         }
-      }
+      // update data
+      prop.put(ITEM_DATA, data);
    }
 
    /**
@@ -1177,11 +1010,182 @@
       }
    }
 
-   private void removePropertyReferenceToNode(String nodeId, Fqn propFqn)
+   private void removeReferences(PropertyData prevData) throws RepositoryException
    {
+      // get values from cahce
+      Set<String> remNodes = new HashSet<String>();
+      for (ValueData value : prevData.getValues())
+      {
+         try
+         {
+            remNodes.add(ValueDataConvertor.readString(value));
+         }
+         catch (UnsupportedEncodingException e)
+         {
+            throw new RepositoryException(e);
+         }
+         catch (IOException e)
+         {
+            throw new RepositoryException(e);
+         }
+      }
 
+      String propUUID = prevData.getIdentifier();
+      for (String refNodeUUID : remNodes)
+      {
+         removePropertyReferenceToNode(refNodeUUID, propUUID);
+      }
    }
 
+   private void addReferences(PropertyData data) throws RepositoryException
+   {
+      Fqn propIdentifier = Fqn.fromElements(data.getIdentifier());
+
+      for (ValueData value : data.getValues())
+      {
+
+         String refNodeUUID;
+         try
+         {
+            refNodeUUID = ValueDataConvertor.readString(value);
+         }
+         catch (UnsupportedEncodingException e)
+         {
+            throw new RepositoryException(e);
+         }
+         catch (IOException e)
+         {
+            throw new RepositoryException(e);
+         }
+
+         Fqn<String> refNode = makeNodeFqn(refNodeUUID);
+
+         // add to $REFS map
+         Node<Serializable, Object> refParent = refsRoot.getChild(refNode);
+         if (refParent == null)
+         {
+            refParent = refsRoot.addChild(refNode);
+         }
+
+         refParent.addChild(propIdentifier);
+      }
+   }
+
+   private void updateReferences(PropertyData prevData, PropertyData newData) throws RepositoryException
+   {
+      // get Set of old values
+      Set<String> removeSet = new HashSet<String>();
+      if (prevData.getType() == PropertyType.REFERENCE)
+      {
+         for (ValueData value : prevData.getValues())
+         {
+            try
+            {
+               removeSet.add(ValueDataConvertor.readString(value));
+            }
+            catch (UnsupportedEncodingException e)
+            {
+               throw new RepositoryException(e);
+            }
+            catch (IOException e)
+            {
+               throw new RepositoryException(e);
+            }
+         }
+      }
+
+      // check new
+      Set<String> addSet = new HashSet<String>();
+      if (newData.getType() == PropertyType.REFERENCE)
+      {
+         for (ValueData value : newData.getValues())
+         {
+            try
+            {
+               addSet.add(ValueDataConvertor.readString(value));
+            }
+            catch (UnsupportedEncodingException e)
+            {
+               throw new RepositoryException(e);
+            }
+            catch (IOException e)
+            {
+               throw new RepositoryException(e);
+            }
+         }
+      }
+
+      String[] added = new String[addSet.size()];
+      addSet.toArray(added);
+
+      for (String id : added)
+      {
+         if (removeSet.contains(id))
+         {
+            removeSet.remove(id);
+            addSet.remove(id);
+         }
+      }
+
+      // remove references to nodes
+      for (String id : removeSet)
+      {
+         removePropertyReferenceToNode(id, newData.getIdentifier());
+      }
+
+      Fqn propFqn = Fqn.fromElements(newData.getIdentifier());
+
+      // add references to nodes
+      for (String id : addSet)
+      {
+         Fqn nodeFqn = Fqn.fromElements(id);
+         Node<Serializable, Object> node = refsRoot.getChild(nodeFqn);
+
+         if (node == null)
+         {
+            node = refsRoot.addChild(nodeFqn);
+         }
+         node.addChild(propFqn);
+      }
+   }
+
+   private void removePropertyReferenceToNode(String nodeId, String propId) throws RepositoryException
+   {
+      // remove property from referencedNode in $REFS map
+      Node<Serializable, Object> refParent = refsRoot.getChild(makeNodeFqn(nodeId));
+
+      if (refParent != null)
+      {
+         if (refParent.hasChild(propId))
+         {
+            // do we need remove node record also
+            boolean removeParent = (refParent.getChildrenNames().size() == 1);
+
+            if (!refParent.removeChild(propId))
+            {
+               throw new RepositoryException("FATAL Reference property was not removed from REFS table of node "
+                  + nodeId);
+            }
+
+            if (removeParent)
+            {
+               if (!refsRoot.removeChild(makeNodeFqn(nodeId)))
+               {
+                  throw new RepositoryException("FATAL Node record was node removed from REFS table " + nodeId);
+               }
+            }
+         }
+         else
+         {
+            LOG.warn("Property reference " + propId + " to node " + nodeId + " was already removed.");
+         }
+      }
+      else
+      {
+         LOG.warn("Reference record of node " + nodeId + " was already removed.");
+      }
+   }
+
    /**
     * @see org.exoplatform.services.jcr.storage.WorkspaceStorageConnection#getLockData(java.lang.String)
     */



More information about the exo-jcr-commits mailing list