[exo-jcr-commits] exo-jcr SVN: r480 - 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
Fri Nov 6 05:17:07 EST 2009


Author: pnedonosko
Date: 2009-11-06 05:17:07 -0500 (Fri, 06 Nov 2009)
New Revision: 480

Added:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Removed:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java
Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractWriteOnlyCacheLoader.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
   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/JBossCacheTreeStorageConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
Log:
EXOJCR-200: reorg for new storage arch

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractWriteOnlyCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractWriteOnlyCacheLoader.java	2009-11-06 10:06:18 UTC (rev 479)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractWriteOnlyCacheLoader.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -16,16 +16,16 @@
  */
 package org.exoplatform.services.jcr.impl.storage.jbosscache;
 
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.loader.AbstractCacheLoader;
+
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Modification;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-import org.jboss.cache.loader.AbstractCacheLoader;
-
 /**
  * Created by The eXo Platform SAS.
  * 

Deleted: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java	2009-11-06 10:06:18 UTC (rev 479)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -1,322 +0,0 @@
-/*
- * 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.
- */
-/*
- * 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 java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.datamodel.IllegalNameException;
-import org.exoplatform.services.jcr.datamodel.ItemData;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-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.storage.WorkspaceDataContainer;
-import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.loader.AbstractCacheLoader;
-
-/**
- * Created by The eXo Platform SAS.
- * 
- * <br/>Date: 31.10.2009
- *
- * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a> 
- * @version $Id$
- */
-public class ExoJCRCacheLoader extends AbstractCacheLoader
-{
-
-   private WorkspaceDataContainer dataContainer;
-
-   /**
-    * Init the loader DataContainer with given WorkspaceDataContainer instance.
-    *
-    * @param dataContainer WorkspaceDataContainer
-    */
-   @Inject
-   public void initDataContainer(WorkspaceDataContainer dataContainer) throws RepositoryConfigurationException
-   {
-      if (this.dataContainer != null)
-      {
-         throw new RepositoryConfigurationException("Cannot set WorkspaceDataContainer twice");
-      }
-
-      this.dataContainer = dataContainer;
-   }
-
-   protected QPathEntry[] makeNodePath(Fqn<String> nodeFqn) throws NumberFormatException, IllegalNameException
-   {
-      List<String> elements = nodeFqn.peekElements();
-      QPathEntry[] path = new QPathEntry[elements.size()];
-
-      for (int i = 0; i < elements.size(); i++)
-      {
-         path[i] = QPathEntry.parse(elements.get(i));
-      }
-
-      return path;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public Map<Object, Object> get(Fqn name) throws Exception
-   {
-
-      Map<Object, Object> attrs = new LinkedHashMap<Object, Object>();
-      if (name.size() > 1)
-      {
-         if (name.get(1).equals(JBossCacheStorage.TREE))
-         {
-            // return Node
-            if (name.size() > 3)
-            {
-               QPathEntry nodeName = QPathEntry.parse(name.getLastElementAsString());
-
-               // 1) all subtree will be cached
-               // 2) all subtree will be read from DB (with allprops) for only Ids.
-               // The effective way DON NOT use calls to cache and use special SQLs for Ids only read. 
-               String parentId = (String)cache.get(name.getParent(), JBossCacheStorage.ITEM_ID);
-
-               WorkspaceStorageConnection conn = dataContainer.openConnection();
-               try
-               {
-                  NodeData parent = (NodeData)conn.getItemData(parentId);
-
-                  ItemData item = conn.getItemData(parent, nodeName);
-
-                  // item Id
-                  attrs.put(JBossCacheStorage.ITEM_ID, item.getIdentifier());
-
-                  // if Node (Property cannot due to logic of StorageConnection) add props
-                  for (PropertyData prop : conn.getChildPropertiesData(parent))
-                  {
-                     attrs.put(prop.getQPath().getName().getAsString(), prop.getIdentifier());
-                  }
-               }
-               finally
-               {
-                  conn.close();
-               }
-            }
-            else
-            {
-               // root Node (/$TREE/[]:1)
-               attrs.put(JBossCacheStorage.ITEM_ID, Constants.ROOT_UUID);
-            }
-         }
-         else if (name.get(1).equals(JBossCacheStorage.ITEMS))
-         {
-            // we have all data on thrid level 
-            if (name.size() == 3)
-            {
-               // return Node or Property
-               String itemId = name.getLastElementAsString();
-
-               WorkspaceStorageConnection conn = dataContainer.openConnection();
-               try
-               {
-                  attrs.put(JBossCacheStorage.ITEM_DATA, conn.getItemData(itemId));
-               }
-               finally
-               {
-                  conn.close();
-               }
-            }
-         }
-      }
-      return attrs;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public boolean exists(Fqn name) throws Exception
-   {
-      // TODO do it with less cost
-      return get(name) != null;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public Set<?> getChildrenNames(Fqn fqn) throws Exception
-   {
-      // return child nodes names
-
-      Set<String> childs = new LinkedHashSet<String>();
-      if (fqn.size() > 2)
-      {
-         if (fqn.get(2).equals(JBossCacheStorage.TREE))
-         {
-            // return Node
-            if (fqn.size() > 3)
-            {
-               QPathEntry nodeName = QPathEntry.parse(fqn.getLastElementAsString());
-
-               // TODO non effective, in this way 1) all subtree will be cached
-               // 2) all subtree will be read from DB (with allprops) for only Ids.
-               // The effective way DON NOT use calls to cache and use special SQLs for Ids only read. 
-               String parentId = (String)cache.get(fqn.getParent(), JBossCacheStorage.ITEM_ID);
-
-               WorkspaceStorageConnection conn = dataContainer.openConnection();
-               try
-               {
-                  NodeData parent = (NodeData)conn.getItemData(parentId);
-
-                  NodeData node = (NodeData)conn.getItemData(parent, nodeName);
-
-                  // get child nodes by parent Id
-                  for (NodeData prop : conn.getChildNodesData(node))
-                  {
-                     childs
-                        .add(node.getQPath().getEntries()[node.getQPath().getEntries().length - 1].getAsString(true));
-                  }
-               }
-               finally
-               {
-                  conn.close();
-               }
-            }
-            else
-            {
-               // root Node (/$TREE/[]:1)
-               childs.add(Constants.ROOT_PATH.getEntries()[Constants.ROOT_PATH.getEntries().length - 1]
-                  .getAsString(true));
-            }
-         }
-         else if (fqn.get(2).equals(JBossCacheStorage.ITEMS))
-         {
-            // we have all data on thrid level 
-            if (fqn.size() == 3)
-            {
-               // return all Nodes and Properties Ids
-
-//               WorkspaceStorageConnection conn = dataContainer.openConnection();
-//               try
-//               {
-//                  for (String itemId : conn.getAllItemIdentifiers())
-//                  {
-//                     childs.add(itemId);
-//                  }
-//               }
-//               finally
-//               {
-//                  conn.close();
-//               }
-            }
-         }
-      }
-      else if (fqn.equals(Fqn.ROOT))
-      {
-         childs.add(JBossCacheStorage.TREE);
-         childs.add(JBossCacheStorage.ITEMS);
-      }
-      return childs;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public IndividualCacheLoaderConfig getConfig()
-   {
-      // TODO Auto-generated method stub
-      return null;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public Object put(Fqn name, Object key, Object value) throws Exception
-   {
-      // TODO Auto-generated method stub
-      return null;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void put(Fqn name, Map<Object, Object> attributes) throws Exception
-   {
-      // TODO Auto-generated method stub
-
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public Object remove(Fqn fqn, Object key) throws Exception
-   {
-      // TODO Auto-generated method stub
-      return null;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void remove(Fqn fqn) throws Exception
-   {
-      // TODO Auto-generated method stub
-
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void removeData(Fqn fqn) throws Exception
-   {
-      // TODO Auto-generated method stub
-
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void setConfig(IndividualCacheLoaderConfig config)
-   {
-      // TODO Auto-generated method stub
-
-   }
-
-}

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java	2009-11-06 10:06:18 UTC (rev 479)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -51,6 +51,7 @@
 public abstract class JBossCacheStorage
 {
 
+   @Deprecated
    public static final String TREE = "$TREE".intern();
 
    public static final String ITEMS = "$ITEMS".intern();
@@ -59,14 +60,24 @@
 
    public static final String ITEM_ID = "$id".intern();
 
+   @Deprecated
    protected final Fqn<String> treeRoot;
 
    protected final Fqn<String> itemsRoot;
 
+   @Deprecated
    protected JBossCacheStorage(Fqn<String> treeRoot, Fqn<String> itemsRoot)
    {
+      this.itemsRoot = itemsRoot;
+      
       this.treeRoot = treeRoot;
+   }
+   
+   protected JBossCacheStorage(Fqn<String> itemsRoot)
+   {
       this.itemsRoot = itemsRoot;
+      
+      this.treeRoot = null;
    }
 
    @Deprecated
@@ -97,13 +108,26 @@
 
       return Fqn.fromRelativeFqn(treeRoot, Fqn.fromElements(fqns));
    }
-
-   protected Fqn<String> makeTreeFqn(String parentId, QPathEntry itemName)
+ 
+   /**
+    * Make Child Node Fqn, i.e. /IDxxx/NAMExxx.
+    *
+    * @param parentId String 
+    * @param itemName QPathEntry
+    * @return Fqn
+    */
+   protected Fqn<String> makeChildNodeFqn(String parentId, QPathEntry itemName)
    {
-      return Fqn.fromRelativeFqn(treeRoot, Fqn.fromElements(parentId, itemName.getAsString(true)));
+      return Fqn.fromRelativeFqn(itemsRoot, Fqn.fromElements(parentId, itemName.getAsString(true)));
    }
 
-   protected Fqn<String> makeIdFqn(String itemId)
+   /**
+    * Make Item Fqn, i.e. /IDxxx.
+    *
+    * @param itemId String
+    * @return Fqn
+    */
+   protected Fqn<String> makeItemFqn(String itemId)
    {
       return Fqn.fromRelativeFqn(itemsRoot, Fqn.fromString(itemId));
    }

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-06 10:06:18 UTC (rev 479)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -69,14 +69,11 @@
     *
     * @param cache Cache<Serializable, Object>
     */
-   public JBossCacheStorageConnection(Cache<Serializable, Object> cache, Node<Serializable, Object> treeRoot,
-      Node<Serializable, Object> itemsRoot)
+   public JBossCacheStorageConnection(Cache<Serializable, Object> cache, Node<Serializable, Object> itemsRoot)
    {
-      super(treeRoot.getFqn(), itemsRoot.getFqn());
-      
+      super(itemsRoot.getFqn());
+
       this.cache = cache;
-      //this.itemsRoot = itemsRoot;
-      //this.treeRoot = treeRoot;
    }
 
    /**
@@ -86,8 +83,8 @@
       IllegalStateException
    {
       startBatch();
-      cache.put(makeNodeFqn(data.getQPath()), ITEM_ID, data.getIdentifier());
-      cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data); // treePrint(treeRoot);
+      //cache.put(makeNodeFqn(data.getQPath()), ITEM_ID, data.getIdentifier());
+      //cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data); // treePrint(treeRoot);
    }
 
    /**
@@ -97,11 +94,11 @@
       InvalidItemStateException, IllegalStateException
    {
       startBatch();
-      Fqn<String> parentFqn = makeParentFqn(data.getQPath());
+      //Fqn<String> parentFqn = makeParentFqn(data.getQPath());
 
       // add an attr to the parent node as key=PropertyName value=PropertyId
-      cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
-      cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+      //cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
+      //cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
    }
 
    /**
@@ -111,8 +108,8 @@
       InvalidItemStateException, IllegalStateException
    {
       startBatch();
-      cache.removeNode(makeNodeFqn(data.getQPath()));
-      cache.removeNode(makeIdFqn(data.getIdentifier()));
+      //cache.removeNode(makeNodeFqn(data.getQPath()));
+      //cache.removeNode(makeIdFqn(data.getIdentifier()));
    }
 
    /**
@@ -123,8 +120,8 @@
    {
       startBatch();
       // delete attr on parent by key=PropertyName
-      cache.remove(makeParentFqn(data.getQPath()), data.getQPath().getName().getAsString());
-      cache.removeNode(makeIdFqn(data.getIdentifier()));
+      //cache.remove(makeParentFqn(data.getQPath()), data.getQPath().getName().getAsString());
+      //cache.removeNode(makeIdFqn(data.getIdentifier()));
    }
 
    /**
@@ -133,29 +130,31 @@
    public List<NodeData> getChildNodesData(NodeData parent) throws RepositoryException, IllegalStateException
    {
       //Set<Object> childNames = cache.getChildrenNames(makeNodeFqn(parent.getQPath()));
-      Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
-      if (parentNode == null)
-      {
-         throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
-      }
-
-      Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
-
-      List<NodeData> childs = new ArrayList<NodeData>();
-      for (Node<Serializable, Object> child : childNodes)
-      {
-         String childId = (String)child.get(ITEM_ID);
-
-         // TODO NodeData or PropertyData? As ItemData check then and cast.
-         NodeData node = (NodeData)cache.get(makeIdFqn(childId), ITEM_DATA);
-         if (node == null)
-         {
-            throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
-         }
-         childs.add(node);
-      }
-
-      return childs;
+//      Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
+//      if (parentNode == null)
+//      {
+//         throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
+//      }
+//
+//      Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
+//
+//      List<NodeData> childs = new ArrayList<NodeData>();
+//      for (Node<Serializable, Object> child : childNodes)
+//      {
+//         String childId = (String)child.get(ITEM_ID);
+//
+//         // TODO NodeData or PropertyData? As ItemData check then and cast.
+//         NodeData node = (NodeData)cache.get(makeIdFqn(childId), ITEM_DATA);
+//         if (node == null)
+//         {
+//            throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
+//         }
+//         childs.add(node);
+//      }
+//
+//      return childs;
+      
+      return null;
    }
 
    private void treePrint(Node<Serializable, Object> node)
@@ -180,30 +179,32 @@
    public List<PropertyData> getChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
    {
       // TODO treeRoot.getChild(f) possible if f not a direct child??? 
-      Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
-      if (parentNode == null)
-      {
-         throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
-      }
-
-      List<PropertyData> childs = new ArrayList<PropertyData>();
-
-      for (Serializable key : parentNode.getKeys())
-      {
-         if (!key.equals(ITEM_ID))
-         {
-            String propId = (String)parentNode.get(key);
-            // TODO NodeData or PropertyData? As ItemData check then and cast.               
-            PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
-            if (property == null)
-            {
-               throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
-            }
-            childs.add(property);
-         }
-      }
-
-      return childs;
+//      Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
+//      if (parentNode == null)
+//      {
+//         throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
+//      }
+//
+//      List<PropertyData> childs = new ArrayList<PropertyData>();
+//
+//      for (Serializable key : parentNode.getKeys())
+//      {
+//         if (!key.equals(ITEM_ID))
+//         {
+//            String propId = (String)parentNode.get(key);
+//            // TODO NodeData or PropertyData? As ItemData check then and cast.               
+//            PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
+//            if (property == null)
+//            {
+//               throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
+//            }
+//            childs.add(property);
+//         }
+//      }
+//
+//      return childs;
+      
+      return null;
    }
 
    /**
@@ -220,34 +221,34 @@
     */
    public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException, IllegalStateException
    {
-      Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parentData.getQPath()));
-      if (parentNode == null)
-      {
-         throw new IllegalStateException("Get Item data error: parent not found " + parentData.getQPath().getAsString());
-      }
+//      Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parentData.getQPath()));
+//      if (parentNode == null)
+//      {
+//         throw new IllegalStateException("Get Item data error: parent not found " + parentData.getQPath().getAsString());
+//      }
+//
+//      // TODO check performance of Node vs Property get
+//
+//      String propertyId = (String)parentNode.get(name.getAsString());
+//      if (propertyId != null)
+//      {
+//         // it's Property Item
+//         return (PropertyData)cache.get(makeIdFqn(propertyId), ITEM_DATA);
+//      }
+//      else
+//      {
+//         // it's Node Item
+//         Node<Serializable, Object> node = parentNode.getChild(name.getAsString(true)); // TODO String not Fqn?
+//         if (node != null)
+//         {
+//            String nodeId = (String)node.get(ITEM_ID);
+//            if (nodeId != null)
+//            {
+//               return (NodeData)cache.get(makeIdFqn(nodeId), ITEM_DATA);
+//            }
+//         }
+//      }
 
-      // TODO check performance of Node vs Property get
-
-      String propertyId = (String)parentNode.get(name.getAsString());
-      if (propertyId != null)
-      {
-         // it's Property Item
-         return (PropertyData)cache.get(makeIdFqn(propertyId), ITEM_DATA);
-      }
-      else
-      {
-         // it's Node Item
-         Node<Serializable, Object> node = parentNode.getChild(name.getAsString(true)); // TODO String not Fqn?
-         if (node != null)
-         {
-            String nodeId = (String)node.get(ITEM_ID);
-            if (nodeId != null)
-            {
-               return (NodeData)cache.get(makeIdFqn(nodeId), ITEM_DATA);
-            }
-         }
-      }
-
       return null;
    }
 
@@ -256,7 +257,7 @@
     */
    public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
    {
-      return (ItemData)cache.get(makeIdFqn(identifier), ITEM_DATA);
+      return (ItemData)cache.get(makeItemFqn(identifier), ITEM_DATA);
    }
 
    /**
@@ -295,7 +296,7 @@
          throw new IllegalStateException("Node was deleted (tree)");
       }
 
-      prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+      prev = cache.put(makeItemFqn(data.getIdentifier()), ITEM_DATA, data);
       if (prev == null)
       {
          throw new IllegalStateException("Node was deleted (items)");
@@ -311,18 +312,18 @@
       startBatch();
 
       // TODO it's put anyway.. but with check?
-      Fqn<String> parentFqn = makeParentFqn(data.getQPath());
-      Object prev = cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
-      if (prev == null)
-      {
-         throw new IllegalStateException("Property was deleted (tree)");
-      }
-
-      prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
-      if (prev == null)
-      {
-         throw new IllegalStateException("Property was deleted (items)");
-      }
+//      Fqn<String> parentFqn = makeParentFqn(data.getQPath());
+//      Object prev = cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
+//      if (prev == null)
+//      {
+//         throw new IllegalStateException("Property was deleted (tree)");
+//      }
+//
+//      prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+//      if (prev == null)
+//      {
+//         throw new IllegalStateException("Property was deleted (items)");
+//      }
    }
 
    /**

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java	2009-11-06 10:06:18 UTC (rev 479)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -93,7 +93,7 @@
    {
       startBatch();
       cache.put(makeNodeFqn(data.getQPath()), ITEM_ID, data.getIdentifier());
-      cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data); // treePrint(treeRoot);
+      cache.put(makeItemFqn(data.getIdentifier()), ITEM_DATA, data); // treePrint(treeRoot);
    }
 
    /**
@@ -107,7 +107,7 @@
 
       // add an attr to the parent node as key=PropertyName value=PropertyId
       cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
-      cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+      cache.put(makeItemFqn(data.getIdentifier()), ITEM_DATA, data);
    }
 
    /**
@@ -118,7 +118,7 @@
    {
       startBatch();
       cache.removeNode(makeNodeFqn(data.getQPath()));
-      cache.removeNode(makeIdFqn(data.getIdentifier()));
+      cache.removeNode(makeItemFqn(data.getIdentifier()));
    }
 
    /**
@@ -130,7 +130,7 @@
       startBatch();
       // delete attr on parent by key=PropertyName
       cache.remove(makeParentFqn(data.getQPath()), data.getQPath().getName().getAsString());
-      cache.removeNode(makeIdFqn(data.getIdentifier()));
+      cache.removeNode(makeItemFqn(data.getIdentifier()));
    }
 
    /**
@@ -153,7 +153,7 @@
          String childId = (String)child.get(ITEM_ID);
 
          // TODO NodeData or PropertyData? As ItemData check then and cast.
-         NodeData node = (NodeData)cache.get(makeIdFqn(childId), ITEM_DATA);
+         NodeData node = (NodeData)cache.get(makeItemFqn(childId), ITEM_DATA);
          if (node == null)
          {
             throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
@@ -200,7 +200,7 @@
          {
             String propId = (String)parentNode.get(key);
             // TODO NodeData or PropertyData? As ItemData check then and cast.               
-            PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
+            PropertyData property = (PropertyData)cache.get(makeItemFqn(propId), ITEM_DATA);
             if (property == null)
             {
                throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
@@ -238,7 +238,7 @@
       if (propertyId != null)
       {
          // it's Property Item
-         return (PropertyData)cache.get(makeIdFqn(propertyId), ITEM_DATA);
+         return (PropertyData)cache.get(makeItemFqn(propertyId), ITEM_DATA);
       }
       else
       {
@@ -249,7 +249,7 @@
             String nodeId = (String)node.get(ITEM_ID);
             if (nodeId != null)
             {
-               return (NodeData)cache.get(makeIdFqn(nodeId), ITEM_DATA);
+               return (NodeData)cache.get(makeItemFqn(nodeId), ITEM_DATA);
             }
          }
       }
@@ -262,7 +262,7 @@
     */
    public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
    {
-      return (ItemData)cache.get(makeIdFqn(identifier), ITEM_DATA);
+      return (ItemData)cache.get(makeItemFqn(identifier), ITEM_DATA);
    }
 
    /**
@@ -301,7 +301,7 @@
          throw new IllegalStateException("Node was deleted (tree)");
       }
 
-      prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+      prev = cache.put(makeItemFqn(data.getIdentifier()), ITEM_DATA, data);
       if (prev == null)
       {
          throw new IllegalStateException("Node was deleted (items)");
@@ -324,7 +324,7 @@
          throw new IllegalStateException("Property was deleted (tree)");
       }
 
-      prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+      prev = cache.put(makeItemFqn(data.getIdentifier()), ITEM_DATA, data);
       if (prev == null)
       {
          throw new IllegalStateException("Property was deleted (items)");

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java	2009-11-06 10:06:18 UTC (rev 479)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -67,8 +67,6 @@
 
    private final Cache<Serializable, Object> cache;
 
-   private final Node<Serializable, Object> tree;
-
    private final Node<Serializable, Object> items;
 
    /**
@@ -113,7 +111,6 @@
       //Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
 
       // prepare cache structures
-      this.tree = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.TREE));
       this.items = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.ITEMS));
    }
 
@@ -146,7 +143,7 @@
     */
    public WorkspaceStorageConnection openConnection() throws RepositoryException
    {
-      return new JBossCacheStorageConnection(cache, tree, items);
+      return new JBossCacheStorageConnection(cache, items);
    }
 
    /**
@@ -154,7 +151,7 @@
     */
    public WorkspaceStorageConnection openConnection(boolean readOnly) throws RepositoryException
    {
-      return new JBossCacheStorageConnection(cache, tree, items);
+      return new JBossCacheStorageConnection(cache, items);
    }
 
    /**

Copied: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java (from rev 479, jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java)
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-11-06 10:17:07 UTC (rev 480)
@@ -0,0 +1,333 @@
+/*
+ * 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.
+ */
+/*
+ * 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 java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+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.storage.WorkspaceDataContainer;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.loader.AbstractCacheLoader;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 31.10.2009
+ *
+ * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a> 
+ * @version $Id$
+ */
+public class JDBCCacheLoader extends AbstractCacheLoader
+{
+
+   private WorkspaceDataContainer dataContainer;
+
+   /**
+    * Init the loader DataContainer with given WorkspaceDataContainer instance.
+    *
+    * @param dataContainer WorkspaceDataContainer
+    */
+   @Inject
+   public void initDataContainer(WorkspaceDataContainer dataContainer) throws RepositoryConfigurationException
+   {
+      if (this.dataContainer != null)
+      {
+         throw new RepositoryConfigurationException("Cannot set WorkspaceDataContainer twice");
+      }
+
+      this.dataContainer = dataContainer;
+   }
+   
+   
+   /**
+    * {@inheritDoc}
+    */
+   public void put(List<Modification> modifications) throws Exception
+   {
+     
+
+   }
+
+   protected QPathEntry[] makeNodePath(Fqn<String> nodeFqn) throws NumberFormatException, IllegalNameException
+   {
+      List<String> elements = nodeFqn.peekElements();
+      QPathEntry[] path = new QPathEntry[elements.size()];
+
+      for (int i = 0; i < elements.size(); i++)
+      {
+         path[i] = QPathEntry.parse(elements.get(i));
+      }
+
+      return path;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Map<Object, Object> get(Fqn name) throws Exception
+   {
+
+      Map<Object, Object> attrs = new LinkedHashMap<Object, Object>();
+      if (name.size() > 1)
+      {
+         if (name.get(1).equals(JBossCacheStorage.TREE))
+         {
+            // return Node
+            if (name.size() > 3)
+            {
+               QPathEntry nodeName = QPathEntry.parse(name.getLastElementAsString());
+
+               // 1) all subtree will be cached
+               // 2) all subtree will be read from DB (with allprops) for only Ids.
+               // The effective way DON NOT use calls to cache and use special SQLs for Ids only read. 
+               String parentId = (String)cache.get(name.getParent(), JBossCacheStorage.ITEM_ID);
+
+               WorkspaceStorageConnection conn = dataContainer.openConnection();
+               try
+               {
+                  NodeData parent = (NodeData)conn.getItemData(parentId);
+
+                  ItemData item = conn.getItemData(parent, nodeName);
+
+                  // item Id
+                  attrs.put(JBossCacheStorage.ITEM_ID, item.getIdentifier());
+
+                  // if Node (Property cannot due to logic of StorageConnection) add props
+                  for (PropertyData prop : conn.getChildPropertiesData(parent))
+                  {
+                     attrs.put(prop.getQPath().getName().getAsString(), prop.getIdentifier());
+                  }
+               }
+               finally
+               {
+                  conn.close();
+               }
+            }
+            else
+            {
+               // root Node (/$TREE/[]:1)
+               attrs.put(JBossCacheStorage.ITEM_ID, Constants.ROOT_UUID);
+            }
+         }
+         else if (name.get(1).equals(JBossCacheStorage.ITEMS))
+         {
+            // we have all data on thrid level 
+            if (name.size() == 3)
+            {
+               // return Node or Property
+               String itemId = name.getLastElementAsString();
+
+               WorkspaceStorageConnection conn = dataContainer.openConnection();
+               try
+               {
+                  attrs.put(JBossCacheStorage.ITEM_DATA, conn.getItemData(itemId));
+               }
+               finally
+               {
+                  conn.close();
+               }
+            }
+         }
+      }
+      return attrs;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean exists(Fqn name) throws Exception
+   {
+      // TODO do it with less cost
+      return get(name) != null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Set<?> getChildrenNames(Fqn fqn) throws Exception
+   {
+      // return child nodes names
+
+      Set<String> childs = new LinkedHashSet<String>();
+      if (fqn.size() > 2)
+      {
+         if (fqn.get(2).equals(JBossCacheStorage.TREE))
+         {
+            // return Node
+            if (fqn.size() > 3)
+            {
+               QPathEntry nodeName = QPathEntry.parse(fqn.getLastElementAsString());
+
+               // TODO non effective, in this way 1) all subtree will be cached
+               // 2) all subtree will be read from DB (with allprops) for only Ids.
+               // The effective way DON NOT use calls to cache and use special SQLs for Ids only read. 
+               String parentId = (String)cache.get(fqn.getParent(), JBossCacheStorage.ITEM_ID);
+
+               WorkspaceStorageConnection conn = dataContainer.openConnection();
+               try
+               {
+                  NodeData parent = (NodeData)conn.getItemData(parentId);
+
+                  NodeData node = (NodeData)conn.getItemData(parent, nodeName);
+
+                  // get child nodes by parent Id
+                  for (NodeData prop : conn.getChildNodesData(node))
+                  {
+                     childs
+                        .add(node.getQPath().getEntries()[node.getQPath().getEntries().length - 1].getAsString(true));
+                  }
+               }
+               finally
+               {
+                  conn.close();
+               }
+            }
+            else
+            {
+               // root Node (/$TREE/[]:1)
+               childs.add(Constants.ROOT_PATH.getEntries()[Constants.ROOT_PATH.getEntries().length - 1]
+                  .getAsString(true));
+            }
+         }
+         else if (fqn.get(2).equals(JBossCacheStorage.ITEMS))
+         {
+            // we have all data on thrid level 
+            if (fqn.size() == 3)
+            {
+               // return all Nodes and Properties Ids
+
+//               WorkspaceStorageConnection conn = dataContainer.openConnection();
+//               try
+//               {
+//                  for (String itemId : conn.getAllItemIdentifiers())
+//                  {
+//                     childs.add(itemId);
+//                  }
+//               }
+//               finally
+//               {
+//                  conn.close();
+//               }
+            }
+         }
+      }
+      else if (fqn.equals(Fqn.ROOT))
+      {
+         childs.add(JBossCacheStorage.TREE);
+         childs.add(JBossCacheStorage.ITEMS);
+      }
+      return childs;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public IndividualCacheLoaderConfig getConfig()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object put(Fqn name, Object key, Object value) throws Exception
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void put(Fqn name, Map<Object, Object> attributes) throws Exception
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object remove(Fqn fqn, Object key) throws Exception
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void remove(Fqn fqn) throws Exception
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void removeData(Fqn fqn) throws Exception
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setConfig(IndividualCacheLoaderConfig config)
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id



More information about the exo-jcr-commits mailing list