[exo-jcr-commits] exo-jcr SVN: r370 - 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
Mon Oct 26 07:43:38 EDT 2009


Author: pnedonosko
Date: 2009-10-26 07:43:38 -0400 (Mon, 26 Oct 2009)
New Revision: 370

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

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-10-26 11:27:32 UTC (rev 369)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-10-26 11:43:38 UTC (rev 370)
@@ -63,7 +63,7 @@
    private final Node<Serializable, Object> treeRoot;
 
    private final Node<Serializable, Object> itemsRoot;
-   
+
    /**
     *  Start batching flag. 'true' if batching was started, 'false' if batching is not start. 
     */
@@ -79,7 +79,7 @@
    {
       this.cache = cache;
       this.itemsRoot = itemsRoot;
-      this.treeRoot = treeRoot;    
+      this.treeRoot = treeRoot;
    }
 
    private Fqn<String> makeNodeFqn(QPath nodePath)
@@ -225,6 +225,15 @@
    /**
     * {@inheritDoc}
     */
+   public List<PropertyData> listChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
+   {
+      // TODO it's same as getChild... now
+      return getChildPropertiesData(parent);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
    public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException, IllegalStateException
    {
       Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parentData.getQPath()));
@@ -232,14 +241,32 @@
       {
          throw new IllegalStateException("Get Item data error: parent not found " + parentData.getQPath().getAsString());
       }
-      
-      
-      String propertyId = (String) parentNode.get(name.getAsString(true));
-      if (propertyId != null) {
-         
-      } else {
-         
+
+      // TODO check performance of Node vs Property get
+
+      String itemName = name.getAsString(true);
+
+      String propertyId = (String)parentNode.get(itemName);
+      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(Fqn.fromString(itemName)); // TODO 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;
    }
 
@@ -248,8 +275,7 @@
     */
    public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
    {
-      // TODO Auto-generated method stub
-      return null;
+      return (ItemData)cache.get(makeIdFqn(identifier), ITEM_DATA);
    }
 
    /**
@@ -258,65 +284,107 @@
    public List<PropertyData> getReferencesData(String nodeIdentifier) throws RepositoryException,
       IllegalStateException, UnsupportedOperationException
    {
-      // TODO Auto-generated method stub
-      return null;
+      // TODO refs impl
+      return new ArrayList<PropertyData>();
    }
 
    /**
     * {@inheritDoc}
     */
-   public boolean isOpened()
+   public void rename(NodeData data) throws RepositoryException, UnsupportedOperationException,
+      InvalidItemStateException, IllegalStateException
    {
-      // TODO Auto-generated method stub
-      return false;
+      startBatch();
+      // TODO
    }
 
    /**
     * {@inheritDoc}
     */
-   public List<PropertyData> listChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
+   public void update(NodeData data) throws RepositoryException, UnsupportedOperationException,
+      InvalidItemStateException, IllegalStateException
    {
-      // TODO Auto-generated method stub
-      return null;
+      startBatch();
+
+      // TODO it's put anyway.. but with check?
+      Object prev = cache.put(makeNodeFqn(data.getQPath()), ITEM_ID, data.getIdentifier());
+      if (prev == null)
+      {
+         throw new IllegalStateException("Node was deleted (tree)");
+      }
+
+      prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+      if (prev == null)
+      {
+         throw new IllegalStateException("Node was deleted (items)");
+      }
    }
 
    /**
     * {@inheritDoc}
     */
-   public void rename(NodeData data) throws RepositoryException, UnsupportedOperationException,
+   public void update(PropertyData data) throws RepositoryException, UnsupportedOperationException,
       InvalidItemStateException, IllegalStateException
    {
       startBatch();
 
+      // TODO it's put anyway.. but with check?
+      Fqn<String> parentFqn = makeParentFqn(data.getQPath());
+      Object prev =
+         cache.put(parentFqn, data.getQPath().getEntries()[data.getQPath().getEntries().length - 1].getAsString(true),
+            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)");
+      }
    }
 
    /**
     * {@inheritDoc}
     */
-   public void rollback() throws IllegalStateException, RepositoryException
+   public void commit() throws IllegalStateException, RepositoryException
    {
-      // rollback batch
-      this.cache.endBatch(false);
+      // end batch
+      if (batchStarted)
+      {
+         this.cache.endBatch(true);
+         batchStarted = false;
+      }
+      else
+      {
+         // TODO
+      }
    }
 
    /**
     * {@inheritDoc}
     */
-   public void update(NodeData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
+   public void rollback() throws IllegalStateException, RepositoryException
    {
-      startBatch();
-
+      // rollback batch
+      if (batchStarted)
+      {
+         this.cache.endBatch(false);
+         batchStarted = false;
+      }
+      else
+      {
+         // TODO
+      }
    }
 
    /**
     * {@inheritDoc}
     */
-   public void update(PropertyData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
+   public boolean isOpened()
    {
-      startBatch();
-
+      return true;
    }
 
    /**
@@ -328,21 +396,15 @@
    }
 
    /**
-    * {@inheritDoc}
-    */
-   public void commit() throws IllegalStateException, RepositoryException
-   {
-      // end batch
-      this.cache.endBatch(true);
-   }
-   
-   /**
     *  Start batching.
     */
    private void startBatch()
    {
-     if (!batchStarted)
-        this.cache.startBatch();
+      if (!batchStarted)
+      {
+         batchStarted = true;
+         this.cache.startBatch();
+      }
    }
 
 }



More information about the exo-jcr-commits mailing list