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

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 18 11:03:41 EST 2009


Author: pnedonosko
Date: 2009-11-18 11:03:40 -0500 (Wed, 18 Nov 2009)
New Revision: 753

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/jdbc/DBConstants.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
Log:
EXOJCR-248: get childs optimization

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-18 14:15:30 UTC (rev 752)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-11-18 16:03:40 UTC (rev 753)
@@ -299,10 +299,10 @@
                // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
                else if (name.size() == 3)
                {
-                  String childNodeName = name.getLastElementAsString();
+                  QPathEntry childNodeName = QPathEntry.parse(name.getLastElementAsString());
                   String parentId = (String)name.get(1);
 
-                  String nodeId = conn.getItemIdentifier(parentId, childNodeName);
+                  String nodeId = conn.getItemIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
                   if (nodeId != null)
                   {
                      attrs = new LinkedHashMap<Object, Object>();
@@ -402,10 +402,10 @@
                // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
                else if (name.size() == 3)
                {
-                  String childNodeName = name.getLastElementAsString();
+                  QPathEntry childNodeName = QPathEntry.parse(name.getLastElementAsString());
                   String parentId = (String)name.get(1);
 
-                  String nodeId = conn.getItemIdentifier(parentId, childNodeName);
+                  String nodeId = conn.getItemIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
                   if (nodeId != null)
                   {
                      exists = true;
@@ -488,14 +488,16 @@
          }
          else if (name.equals(JBossCacheStorage.NODES))
          {
-            // TODO return all Nodes in workspace
-            return new LinkedHashSet<String>();
-            
+            // TODO should never be called
+            LOG.warn("conn.getAllNodeIdentifiers()");
+            return conn.getAllNodeIdentifiers();
+
          }
          else if (name.equals(JBossCacheStorage.PROPS))
          {
-            // TODO return all Properties in workspace
-            return new LinkedHashSet<String>();
+            // TODO should never be called
+            LOG.warn("conn.getAllPropertyIdentifiers()");
+            return conn.getAllPropertyIdentifiers();
          }
          else if (name.equals(JBossCacheStorage.LOCKS))
          {

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java	2009-11-18 14:15:30 UTC (rev 752)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java	2009-11-18 16:03:40 UTC (rev 753)
@@ -151,6 +151,16 @@
     * FIND_ITEM_NAME.
     */
    protected String FIND_ITEM_NAME;
+   
+   /**
+    * FIND_ALL_NODES.
+    */
+   protected String FIND_ALL_NODES;
+   
+   /**
+    * FIND_ALL_PROPERTIES.
+    */
+   protected String FIND_ALL_PROPERTIES;
 
    /**
     * INSERT_NODE.

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2009-11-18 14:15:30 UTC (rev 752)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2009-11-18 16:03:40 UTC (rev 753)
@@ -2002,19 +2002,20 @@
    /**
     * Find Item ID in database.
     *
-    * @param parentId parent Node id
-    * @param name Item name
+    * @param parentId String, parent Node id
+    * @param name Item, name
+    * @param index int, path index (actual for nodes, 1 for properties)
     * @return String with ID
     * @throws RepositoryException if database error occurs
     * @throws IllegalStateException if connection closed
     */
-   public String getItemIdentifier(String parentId, String name) throws RepositoryException, IllegalStateException
+   public String getItemIdentifier(String parentId, String name, int index) throws RepositoryException, IllegalStateException
    {
       checkIfOpened();
 
       try
       {
-         ResultSet item = findItemIdentifier(getInternalId(parentId), name);
+         ResultSet item = findItemIdentifier(getInternalId(parentId), name, index);
          if (item.next())
          {
             return item.getString(COLUMN_ID);
@@ -2093,7 +2094,7 @@
     *
     * @param parentId parent Node id.
     * @return Set of String (id)
-    * @throws RepositoryException if error
+    * @throws RepositoryException if database error occurs
     * @throws IllegalStateException if connection closed
     */
    public Set<String> getChildNodeNames(String parentId) throws RepositoryException, IllegalStateException
@@ -2122,15 +2123,30 @@
       }
    }
 
+   /**
+    * Return all Properties in workspace.
+    * TODO check if it used, should not!
+    *
+    * @return Set of String (id)
+    * @throws RepositoryException if database error occurs
+    * @throws IllegalStateException if connection closed
+    */
    public Set<String> getAllPropertyIdentifiers() throws RepositoryException, IllegalStateException
    {
       checkIfOpened();
+
       try
       {
-         ResultSet node = findChildNodesByParentIdentifier(getInternalId("???"));
+         ResultSet node = findAllPropertyIdentifiers();
          Set<String> childrens = new LinkedHashSet<String>();
-         //while (node.next())
-         //childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE, parent.getACL()));
+         while (node.next())
+         {
+            String propId = node.getString(COLUMN_ID);
+            if (!childrens.add(propId))
+            {
+               throw new RepositoryException("FATAL Property id dublicated " + propId);
+            }
+         }
 
          return childrens;
       }
@@ -2140,15 +2156,30 @@
       }
    }
 
+   /**
+    * Return all Nodes in workspace.
+    * TODO check if it used, should not!
+    *
+    * @return Set of String (id)
+    * @throws RepositoryException if database error occurs
+    * @throws IllegalStateException if connection closed
+    */
    public Set<String> getAllNodeIdentifiers() throws RepositoryException, IllegalStateException
    {
       checkIfOpened();
+
       try
       {
-         ResultSet node = findChildNodesByParentIdentifier(getInternalId("???"));
+         ResultSet node = findAllNodeIdentifiers();
          Set<String> childrens = new LinkedHashSet<String>();
-         //while (node.next())
-         //childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE, parent.getACL()));
+         while (node.next())
+         {
+            String nodeId = node.getString(COLUMN_ID);
+            if (!childrens.add(nodeId))
+            {
+               throw new RepositoryException("FATAL Node id dublicated " + nodeId);
+            }
+         }
 
          return childrens;
       }
@@ -2209,8 +2240,12 @@
 
    protected abstract ResultSet findChildNodesNameByParentIdentifier(String parentCid) throws SQLException;
 
-   protected abstract ResultSet findItemIdentifier(String parentCid, String name) throws SQLException;
+   protected abstract ResultSet findItemIdentifier(String parentCid, String name, int index) throws SQLException;
 
    protected abstract ResultSet findItemName(String cid) throws SQLException;
+   
+   protected abstract ResultSet findAllPropertyIdentifiers() throws SQLException;
+   
+   protected abstract ResultSet findAllNodeIdentifiers() throws SQLException;
 
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java	2009-11-18 14:15:30 UTC (rev 752)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java	2009-11-18 16:03:40 UTC (rev 753)
@@ -87,6 +87,10 @@
    protected PreparedStatement findItemIdentifier;
 
    protected PreparedStatement findItemName;
+   
+   protected PreparedStatement findAllProperties;
+   
+   protected PreparedStatement findAllNodes;
 
    protected PreparedStatement insertNode;
 
@@ -194,13 +198,18 @@
 
       FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=?" + " order by N_ORDER_NUM";
 
-      FIND_NODES_NAME_BY_PARENTID = "select NAME from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=?" + " order by N_ORDER_NUM";
+      FIND_ALL_NODES = "select ID from JCR_MITEM where I_CLASS=1";
       
+      FIND_NODES_NAME_BY_PARENTID =
+         "select NAME from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=?" + " order by N_ORDER_NUM";
+
       FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?" + " order by ID";
 
       FIND_PROPERTIES_IDNAME_BY_PARENTID = "select ID, NAME from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?";
+      
+      FIND_ALL_PROPERTIES = "select ID from JCR_MITEM where I_CLASS=2";
 
-      FIND_ITEM_IDENTIFIER = "select ID from JCR_MITEM" + " where PARENT_ID=? and NAME=?";
+      FIND_ITEM_IDENTIFIER = "select ID from JCR_MITEM" + " where PARENT_ID=? and NAME=? and I_INDEX=?";
 
       FIND_ITEM_NAME = "select NAME from JCR_MITEM" + " where ID=?";
 
@@ -588,7 +597,7 @@
     * {@inheritDoc}
     */
    @Override
-   protected ResultSet findItemIdentifier(String parentCid, String name) throws SQLException
+   protected ResultSet findItemIdentifier(String parentCid, String name, int index) throws SQLException
    {
       if (findItemIdentifier == null)
       {
@@ -600,6 +609,7 @@
       }
       findItemIdentifier.setString(1, parentCid);
       findItemIdentifier.setString(2, name);
+      findItemIdentifier.setInt(3, index);
       return findItemIdentifier.executeQuery();
    }
 
@@ -607,7 +617,7 @@
     * {@inheritDoc}
     */
    @Override
-   protected ResultSet findItemName(String cid) throws SQLException
+   protected ResultSet findItemName(String id) throws SQLException
    {
       if (findItemName == null)
       {
@@ -617,7 +627,7 @@
       {
          findItemName.clearParameters();
       }
-      findItemName.setString(1, cid);
+      findItemName.setString(1, id);
       return findItemName.executeQuery();
    }
 
@@ -625,7 +635,7 @@
     * {@inheritDoc}
     */
    @Override
-   protected ResultSet findChildNodesNameByParentIdentifier(String parentIdentifier) throws SQLException
+   protected ResultSet findChildNodesNameByParentIdentifier(String parentId) throws SQLException
    {
       if (findNodesNameByParentId == null)
       {
@@ -635,7 +645,41 @@
       {
          findNodesNameByParentId.clearParameters();
       }
-      findNodesNameByParentId.setString(1, parentIdentifier);
+      findNodesNameByParentId.setString(1, parentId);
       return findNodesNameByParentId.executeQuery();
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findAllNodeIdentifiers() throws SQLException
+   {
+      if (findAllNodes == null)
+      {
+         findAllNodes = dbConnection.prepareStatement(FIND_ALL_NODES);
+      }
+      else
+      {
+         findAllNodes.clearParameters();
+      }
+      return findAllNodes.executeQuery();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findAllPropertyIdentifiers() throws SQLException
+   {
+      if (findAllProperties == null)
+      {
+         findAllProperties = dbConnection.prepareStatement(FIND_ALL_PROPERTIES);
+      }
+      else
+      {
+         findAllProperties.clearParameters();
+      }
+      return findAllProperties.executeQuery();
+   }
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java	2009-11-18 14:15:30 UTC (rev 752)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java	2009-11-18 16:03:40 UTC (rev 753)
@@ -85,6 +85,10 @@
 
    protected PreparedStatement findItemName;
 
+   protected PreparedStatement findAllProperties;
+
+   protected PreparedStatement findAllNodes;
+
    protected PreparedStatement insertItem;
 
    protected PreparedStatement insertNode;
@@ -202,15 +206,20 @@
          "select * from JCR_SITEM" + " where I_CLASS=1 and CONTAINER_NAME=? and PARENT_ID=?" + " order by N_ORDER_NUM";
 
       FIND_NODES_NAME_BY_PARENTID =
-         "select NAME from JCR_SITEM" + " where I_CLASS=1 and CONTAINER_NAME=? and PARENT_ID=?" + " order by N_ORDER_NUM";
+         "select NAME from JCR_SITEM" + " where I_CLASS=1 and CONTAINER_NAME=? and PARENT_ID=?"
+            + " order by N_ORDER_NUM";
 
+      FIND_ALL_NODES = "select ID from JCR_SITEM where I_CLASS=1 and CONTAINER_NAME=?";
+      
       FIND_PROPERTIES_BY_PARENTID =
          "select * from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=?" + " order by ID";
 
       FIND_PROPERTIES_IDNAME_BY_PARENTID =
          "select ID, NAME from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=?";
 
-      FIND_ITEM_IDENTIFIER = "select ID from JCR_SITEM" + " where CONTAINER_NAME=? and PARENT_ID=? and NAME=?";
+      FIND_ALL_PROPERTIES = "select ID from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME=?";
+      
+      FIND_ITEM_IDENTIFIER = "select ID from JCR_SITEM" + " where CONTAINER_NAME=? and PARENT_ID=? and NAME=? and I_INDEX=?";
 
       FIND_ITEM_NAME = "select NAME from JCR_SITEM" + " where ID=?";
 
@@ -601,7 +610,7 @@
     * {@inheritDoc}
     */
    @Override
-   protected ResultSet findItemIdentifier(String parentCid, String name) throws SQLException
+   protected ResultSet findItemIdentifier(String parentCid, String name, int index) throws SQLException
    {
       if (findItemIdentifier == null)
          findItemIdentifier = dbConnection.prepareStatement(FIND_ITEM_IDENTIFIER);
@@ -611,6 +620,7 @@
       findItemIdentifier.setString(1, containerName);
       findItemIdentifier.setString(2, parentCid);
       findItemIdentifier.setString(3, name);
+      findItemIdentifier.setInt(4, index);
       return findItemIdentifier.executeQuery();
    }
 
@@ -647,4 +657,40 @@
       findNodesNameByParentId.setString(2, parentCid);
       return findNodesNameByParentId.executeQuery();
    }
+   
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findAllNodeIdentifiers() throws SQLException
+   {
+      if (findAllNodes == null)
+      {
+         findAllNodes = dbConnection.prepareStatement(FIND_ALL_NODES);
+      }
+      else
+      {
+         findAllNodes.clearParameters();
+      }
+      findAllNodes.setString(1, containerName);
+      return findAllNodes.executeQuery();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findAllPropertyIdentifiers() throws SQLException
+   {
+      if (findAllProperties == null)
+      {
+         findAllProperties = dbConnection.prepareStatement(FIND_ALL_PROPERTIES);
+      }
+      else
+      {
+         findAllProperties.clearParameters();
+      }
+      findAllProperties.setString(1, containerName);
+      return findAllProperties.executeQuery();
+   }   
 }



More information about the exo-jcr-commits mailing list