[exo-jcr-commits] exo-jcr SVN: r550 - 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 10 10:42:05 EST 2009


Author: areshetnyak
Date: 2009-11-10 10:42:05 -0500 (Tue, 10 Nov 2009)
New Revision: 550

Added:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ModificationEx.java
Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Log:
EXOJCR-201 : The class ModificationEx was added. The JDBCCacheLoader was changed.

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-11-10 15:25:10 UTC (rev 549)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-11-10 15:42:05 UTC (rev 550)
@@ -16,24 +16,6 @@
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
 package org.exoplatform.services.jcr.impl.storage.jbosscache;
 
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -43,12 +25,14 @@
 import org.exoplatform.services.jcr.datamodel.PropertyData;
 import org.exoplatform.services.jcr.datamodel.QPathEntry;
 import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.storage.jbosscache.ModificationEx.JCROperaionType;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
 import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
 import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
 import org.jboss.cache.CacheException;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Modification;
+import org.jboss.cache.Modification.ModificationType;
 import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.factories.annotations.NonVolatile;
@@ -72,6 +56,8 @@
  */
 public class JDBCCacheLoader extends AbstractCacheLoader
 {
+   private IndividualCacheLoaderConfig config;
+   
    private WorkspaceDataContainer dataContainer;
 
    public JDBCCacheLoader() {
@@ -100,12 +86,17 @@
    {
      System.out.println(modifications);
      
+     // Prepare modifications list.
+     // Will be changed Modification to ModificationEx and set operation type (ADD or UPDATE). 
+     prepareModifications(modifications);
+     
      JDBCStorageConnection jdbcConnection = (JDBCStorageConnection)dataContainer.openConnection();
      
      try
      {
-        for (Modification m : modifications)
+        for (int i=0; i<modifications.size(); i++)
         {
+           ModificationEx m = (ModificationEx) modifications.get(i);  
            switch (m.getType())
            {
               case PUT_DATA:
@@ -116,7 +107,12 @@
                  break;
               case PUT_KEY_VALUE:
                  System.out.println(m);
-                 doAddOrUpdate(m, jdbcConnection);
+                 
+                 if (m.getOperaionType() == JCROperaionType.ADD)
+                    doAdd(m, jdbcConnection);
+                 else if (m.getOperaionType() == JCROperaionType.UPDATE)
+                    doUpdate(m, jdbcConnection);
+                 
                  break;
               case REMOVE_DATA:
                  System.out.println(m);
@@ -184,49 +180,99 @@
    }
    
    /**
-    * Performs ADD and UPDATE to NodeData and PropertyData.
+    * Performs ADD to NodeData and PropertyData.
     * @param modification
     * @param jdbcConnection
     * @throws IllegalStateException
     * @throws RepositoryException
     */
-   private void doAddOrUpdate(Modification modification, JDBCStorageConnection jdbcConnection)
+   private void doAdd(ModificationEx modification, JDBCStorageConnection jdbcConnection)
       throws IllegalStateException, RepositoryException
    {
       if (modification.getValue() instanceof NodeData)
       {
-         //add or update node data
+         //add node data
          NodeData nodeData = (NodeData)modification.getValue();
 
-         ItemData itemData = jdbcConnection.getItemData(nodeData.getIdentifier());
+         jdbcConnection.add(nodeData);
+      }
+      else if (modification.getValue() instanceof PropertyData)
+      {
+         //add property data
+         PropertyData propertyData = (PropertyData)modification.getValue();
 
-         if (itemData == null)
-         {
-            //add
-            jdbcConnection.add(nodeData);
-         }
-         else
-         {
-            //update
-            jdbcConnection.update(nodeData);
-         }
+         jdbcConnection.add(propertyData);
       }
+   }
+   
+   /**
+    * Performs UPDATE to NodeData and PropertyData.
+    * @param modification
+    * @param jdbcConnection
+    * @throws IllegalStateException
+    * @throws RepositoryException
+    */
+   private void doUpdate(ModificationEx modification, JDBCStorageConnection jdbcConnection)
+      throws IllegalStateException, RepositoryException
+   {
+      if (modification.getValue() instanceof NodeData)
+      {
+         //update node data
+         NodeData nodeData = (NodeData)modification.getValue();
+
+         jdbcConnection.update(nodeData);
+      }
       else if (modification.getValue() instanceof PropertyData)
       {
-         //add or update property data
+         //update property data
          PropertyData propertyData = (PropertyData)modification.getValue();
 
-         ItemData itemData = jdbcConnection.getItemData(propertyData.getIdentifier());
+         jdbcConnection.update(propertyData);
+      }
+   }
+   
+   /**
+    * Prepare list of modifications.
+    * 
+    * Will be checked the UPDATE or ADD.
+    * 
+    * @param modifications
+    * @throws RepositoryException
+    */
+   private void prepareModifications(List<Modification> modifications) throws RepositoryException
+   {
 
-         if (itemData == null)
+      JDBCStorageConnection jdbcConnection = (JDBCStorageConnection) dataContainer.openConnection();
+
+      for (int i = 0; i < modifications.size(); i++)
+      {
+         if (modifications.get(i).getType() == ModificationType.PUT_KEY_VALUE
+             &&
+             modifications.get(i).getValue() instanceof ItemData)
          {
-            //add
-            jdbcConnection.add(propertyData);
+            ItemData itemData = null;
+
+            //Check add or update node data
+            if (modifications.get(i).getValue() instanceof NodeData)
+            {
+               NodeData nodeData = (NodeData) modifications.get(i).getValue();
+               itemData = jdbcConnection.getItemData(nodeData.getIdentifier());
+            }
+            else if (modifications.get(i).getValue() instanceof PropertyData)
+            {
+               PropertyData propertyData = (PropertyData) modifications.get(i).getValue();
+               itemData = jdbcConnection.getItemData(propertyData.getIdentifier());
+            } else
+
+            // Set ModificationEx to list with type UPDATE or ADD.
+            if (itemData == null)
+               modifications.set(i, new ModificationEx(modifications.get(i), JCROperaionType.ADD));
+            else
+               modifications.set(i, new ModificationEx(modifications.get(i), JCROperaionType.UPDATE));
          }
          else
          {
-            //update
-            jdbcConnection.update(propertyData);
+            modifications.set(i, new ModificationEx(modifications.get(i)));
          }
       }
    }
@@ -407,8 +453,7 @@
     */
    public IndividualCacheLoaderConfig getConfig()
    {
-      // TODO Auto-generated method stub
-      return null;
+      return config;
    }
 
    /**
@@ -461,7 +506,7 @@
     */
    public void setConfig(IndividualCacheLoaderConfig config)
    {
-      // TODO Auto-generated method stub
+      this.config = config;
 
    }
 

Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ModificationEx.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ModificationEx.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ModificationEx.java	2009-11-10 15:42:05 UTC (rev 550)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.jboss.cache.Modification;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public class ModificationEx
+   extends Modification implements Externalizable
+{
+
+   private static final long serialVersionUID = 4362354437203996117L;
+
+   public static enum JCROperaionType
+   {
+      ADD,
+      UPDATE,
+      UNKNOWN
+   }
+   
+   /**
+    *  The type of JCR operation (update or add). 
+    */
+   private JCROperaionType operaionType = JCROperaionType.UNKNOWN;
+   
+   /**
+    *  Empty constructor to serialization.
+    */
+   public ModificationEx()
+   {
+   }
+   
+   /**
+    * The constructor with JCROperaionType.
+    * 
+    * @param modification
+    *          the original of modification.
+    * @param operaionType
+    *          the JCR operation type.
+    */
+   public ModificationEx(Modification modification, JCROperaionType operaionType) {
+     this.setType(modification.getType());
+     this.setFqn(modification.getFqn());
+     this.setFqn2(modification.getFqn2());
+     this.setValue(modification.getValue());
+     this.setOldValue(modification.getOldValue());
+     this.setKey(modification.getKey());
+     this.setData(modification.getData());
+     
+     this.operaionType = operaionType;
+   }
+   
+   /**
+    * The constructor without JCROperaionType.
+    * 
+    * @param modification
+    *          the original of modification.
+    */
+   public ModificationEx(Modification modification) {
+     this.setType(modification.getType());
+     this.setFqn(modification.getFqn());
+     this.setFqn2(modification.getFqn2());
+     this.setValue(modification.getValue());
+     this.setOldValue(modification.getOldValue());
+     this.setKey(modification.getKey());
+     this.setData(modification.getData());
+     
+     this.operaionType = JCROperaionType.UNKNOWN;
+   }
+   
+   /**
+    * Getter to property operaionType.
+    * 
+    * @return JCROperaionType
+    *           the operation type
+    */
+   public JCROperaionType getOperaionType() {
+      return operaionType;
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);
+      
+      out.writeObject(operaionType);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+
+      operaionType = (JCROperaionType) in.readObject();
+   }
+   
+   
+   /**
+    * {@inheritDoc}
+    */
+   public String toString()
+   {
+      return super.toString() + " : " + operaionType.toString();
+   }
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ModificationEx.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list