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

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 9 04:54:44 EST 2009


Author: pnedonosko
Date: 2009-11-09 04:54:44 -0500 (Mon, 09 Nov 2009)
New Revision: 502

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.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/JBossCacheWorkspaceDataContainer.java
   jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-200: get childs impl, data container lifecycle rework

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java	2009-11-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/NamespaceDataPersister.java	2009-11-09 09:54:44 UTC (rev 502)
@@ -402,7 +402,6 @@
          changesLog.add(new ItemState(exoNamespaces, ItemState.MIXIN_CHANGED, false, null));
       }
 
-      nsRoot = exoNamespaces;
       dataManager.save(new TransactionChangesLog(changesLog));
    }
 

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-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-11-09 09:54:44 UTC (rev 502)
@@ -27,12 +27,12 @@
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.RepositoryException;
@@ -183,32 +183,36 @@
     */
    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;
 
-      return null;
+      Node<Serializable, Object> parentNode = nodesRoot.getChild(makeNodeFqn(parent.getIdentifier()));
+      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.
+         Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(childId));
+         if (node == null)
+         {
+            throw new RepositoryException("Child node is null. Parent " + parent.getQPath().getAsString());
+         }
+         NodeData nodeData = (NodeData)node.get(ITEM_DATA);
+         if (nodeData == null)
+         {
+            // TODO should not occurs by contract
+            throw new RepositoryException("Child node data is null. Parent " + parent.getQPath().getAsString());
+         }
+         childs.add(nodeData);
+      }
+
+      return childs;
    }
 
    private void treePrint(Node<Serializable, Object> node)
@@ -232,33 +236,40 @@
     */
    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;
+      //TODO treeRoot.getChild(f) possible if f not a direct child??? 
+      Node<Serializable, Object> parentNode = nodesRoot.getChild(makeNodeFqn(parent.getIdentifier()));
+      if (parentNode == null)
+      {
+         throw new IllegalStateException("Get child Properties error: parent not found "
+            + parent.getQPath().getAsString());
+      }
 
-      return null;
+      List<PropertyData> childs = new ArrayList<PropertyData>();
+
+      for (Serializable key : parentNode.getKeys())
+      {
+         if (!key.equals(ITEM_ID))
+         {
+            String propId = (String)parentNode.get(key);
+
+            Node<Serializable, Object> prop = propsRoot.getChild(makePropFqn(propId));
+            if (prop == null)
+            {
+               throw new RepositoryException("Child property is null. Parent " + parent.getQPath().getAsString());
+            }
+
+            PropertyData propData = (PropertyData)prop.get(ITEM_DATA);
+            if (propData == null)
+            {
+               // TODO should not occurs by contract
+               throw new RepositoryException("Child property data is null. Parent " + parent.getQPath().getAsString());
+            }
+
+            childs.add(propData);
+         }
+      }
+
+      return childs;
    }
 
    /**
@@ -277,10 +288,21 @@
    {
 
       // try as Node 
-      Node<Serializable, Object> item = nodesRoot.getChild(makeChildNodeFqn(parentData.getIdentifier(), name));
-      if (item != null)
+      // TODO validate ParentNotFound for both Node and Property
+      Node<Serializable, Object> childNode = nodesRoot.getChild(makeChildNodeFqn(parentData.getIdentifier(), name));
+      if (childNode != null)
       {
-         return (NodeData)item.get(ITEM_DATA);
+         String nodeId = (String)childNode.get(ITEM_ID);
+         Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(nodeId));
+         Object itemData = node.get(ITEM_DATA);
+         if (itemData != null)
+         {
+            return (NodeData)itemData;
+         }
+         else
+         {
+            throw new RepositoryException("FATAL NodeData empty " + parentData.getQPath() + name.getAsString(true));
+         }
       }
       else
       {
@@ -295,6 +317,12 @@
                return (PropertyData)propsRoot.get(makePropFqn(propId));
             }
          }
+         else
+         {
+            // TODO validation of ParentNotFound for Property
+            throw new RepositoryException("Parent not found " + parentData.getIdentifier() + ", "
+               + parentData.getQPath().getAsString());
+         }
       }
 
       return null;
@@ -306,28 +334,37 @@
    public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
    {
 
-      Node<Serializable, Object> item = nodesRoot.getChild(makeNodeFqn(identifier));
-      if (item == null)
+      Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(identifier));
+      if (node != null)
       {
-         item = propsRoot.getChild(makePropFqn(identifier));
-      }
-
-      if (item != null)
-      {
-         Object itemData = item.get(ITEM_DATA);
+         Object itemData = node.get(ITEM_DATA);
          if (itemData != null)
          {
-            return (ItemData)itemData;
+            return (NodeData)itemData;
          }
          else
          {
-            throw new RepositoryException("FATAL ItemData empty " + item.getFqn());
+            throw new RepositoryException("FATAL NodeData empty " + identifier);
          }
       }
       else
       {
-         return null;
+         Node<Serializable, Object> prop = propsRoot.getChild(makePropFqn(identifier));
+         if (prop != null)
+         {
+            Object itemData = prop.get(ITEM_DATA);
+            if (itemData != null)
+            {
+               return (PropertyData)itemData;
+            }
+            else
+            {
+               throw new RepositoryException("FATAL PropertyData empty " + identifier);
+            }
+         }
       }
+
+      return null;
    }
 
    /**

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-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java	2009-11-09 09:54:44 UTC (rev 502)
@@ -67,15 +67,16 @@
 
    private final Cache<Serializable, Object> cache;
 
-   private final Node<Serializable, Object> nodes;
-   private final Node<Serializable, Object> properties;
+   private Node<Serializable, Object> nodes;
 
+   private Node<Serializable, Object> properties;
+
    /**
     * JBossWorkspaceDataContainer  constructor.
     *
     */
-   public JBossCacheWorkspaceDataContainer(WorkspaceEntry wsConfig,
-      RepositoryEntry repConfig, InitialContextInitializer contextInit, ValueStoragePluginProvider valueStorageProvider)
+   public JBossCacheWorkspaceDataContainer(WorkspaceEntry wsConfig, RepositoryEntry repConfig,
+      InitialContextInitializer contextInit, ValueStoragePluginProvider valueStorageProvider)
       throws RepositoryConfigurationException, NamingException, RepositoryException, IOException
    {
       this.repositoryName = repConfig.getName();
@@ -89,6 +90,10 @@
 
       // TODO hardcoded now
       this.persistentContainer = new JDBCWorkspaceDataContainer(wsConfig, repConfig, contextInit, valueStorageProvider);
+      if (this.persistentContainer instanceof Startable)
+      {
+         ((Startable)this.persistentContainer).start();
+      }
 
       // TODO configure CacheLoader here with this.persistentContainer
       //      for (IndividualCacheLoaderConfig loaderCfg : this.cache.getConfiguration().getCacheLoaderConfig()
@@ -99,7 +104,7 @@
       //            ((ExoJCRCacheLoader)loaderCfg.getCacheLoader()).initDataContainer(this.persistentContainer);
       //         }
       //      }
-      
+
       // inject JDBC DC via JBC ComponentRegistry 
       ((CacheSPI<Serializable, Object>)cache).getComponentRegistry().registerComponent(this.persistentContainer,
          WorkspaceDataContainer.class);
@@ -107,7 +112,8 @@
       // TODO check lifecycle, might be we have to create in start(), with jdbc start. 
       // initializes configuration state, the root node, etc.
       this.cache.create();
-
+      this.cache.start();
+      
       Node<Serializable, Object> cacheRoot = cache.getRoot();
       //Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
 
@@ -118,10 +124,20 @@
 
    public void start()
    {
-      if (persistentContainer instanceof Startable)
-      {
-         ((Startable)persistentContainer).start();
-      }
+      // TODO started on init, due to RepositoryContainer logic
+//      if (persistentContainer instanceof Startable)
+//      {
+//         ((Startable)persistentContainer).start();
+//      }
+//
+//      this.cache.start();
+//      
+//      Node<Serializable, Object> cacheRoot = cache.getRoot();
+//      //Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
+//
+//      // prepare cache structures
+//      this.nodes = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.NODES));
+//      this.properties = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.PROPS));
    }
 
    public void stop()
@@ -145,6 +161,12 @@
     */
    public WorkspaceStorageConnection openConnection() throws RepositoryException
    {
+      // TODO
+//      if (nodes == null || properties == null)
+//      {
+//         throw new RepositoryException("Container is not started");
+//      }
+
       return new JBossCacheStorageConnection(cache, nodes, properties);
    }
 
@@ -153,6 +175,12 @@
     */
    public WorkspaceStorageConnection openConnection(boolean readOnly) throws RepositoryException
    {
+      // TODO
+//      if (nodes == null || properties == null)
+//      {
+//         throw new RepositoryException("Container is not started");
+//      }
+      
       return new JBossCacheStorageConnection(cache, nodes, properties);
    }
 

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml	2009-11-09 09:44:25 UTC (rev 501)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jcr-config.xml	2009-11-09 09:54:44 UTC (rev 502)
@@ -32,7 +32,7 @@
                <!-- for system storage -->
                <container class="org.exoplatform.services.jcr.impl.storage.jbosscache.JBossCacheWorkspaceDataContainer">
                   <properties>
-                     <property name="jbosscache-configuration" value="conf/portal/exojcr-jboss-cache-conf.xml" />
+                     <property name="jbosscache-configuration" value="conf/standalone/test-jbosscache-config-jdbcloader.xml" />
                      <property name="source-name" value="jdbcjcr" />
                      <property name="dialect" value="hsqldb" />
                      <property name="multi-db" value="true" />



More information about the exo-jcr-commits mailing list