[exo-jcr-commits] exo-jcr SVN: r1290 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation: db and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 5 06:55:40 EST 2010


Author: nfilotto
Date: 2010-01-05 06:55:40 -0500 (Tue, 05 Jan 2010)
New Revision: 1290

Modified:
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-302: We now use a CQ for traverseQPath

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java	2010-01-05 11:37:19 UTC (rev 1289)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java	2010-01-05 11:55:40 UTC (rev 1290)
@@ -28,6 +28,7 @@
 import org.exoplatform.services.jcr.datamodel.NodeData;
 import org.exoplatform.services.jcr.datamodel.PropertyData;
 import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
 import org.exoplatform.services.jcr.datamodel.ValueData;
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.ByteArrayPersistedValueData;
@@ -84,6 +85,11 @@
    protected String FIND_REFERENCE_PROPERTIES;
 
    /**
+    * FIND_ITEM_QPATH_BY_ID_CQ.
+    */
+   protected String FIND_ITEM_QPATH_BY_ID_CQ;
+
+   /**
     * Class needed to store node details (property also) since result set is not sorted in valid way. 
     */
    private static class TempNodeData
@@ -631,160 +637,84 @@
       }
    }
 
-   //   protected PersistedNodeData loadNodeRecord(ResultSet item, QPath parentPath, AccessControlList pACL)
-   //      throws RepositoryException, SQLException, IOException
-   //   {
-   //
-   //      String cid = item.getString(COLUMN_ID);
-   //      String cname = item.getString(COLUMN_NAME);
-   //      int cversion = item.getInt(COLUMN_VERSION);
-   //      String cpid = item.getString(COLUMN_PARENTID);
-   //      int cindex = item.getInt(COLUMN_INDEX);
-   //      int cnordernumb = item.getInt(COLUMN_NORDERNUM);
-   //      AccessControlList parentACL = pACL;
-   //
-   //      try
-   //      {
-   //         InternalQName qname = InternalQName.parse(cname);
-   //
-   //         // TODO can't avoid QPath traverse
-   //         QPath qpath;
-   //         String parentCid;
-   //         if (parentPath != null)
-   //         {
-   //            // get by parent and name
-   //            qpath = QPath.makeChildPath(parentPath, qname, cindex);
-   //            parentCid = cpid;
-   //         }
-   //         else
-   //         {
-   //            // get by id
-   //            if (cpid.equals(Constants.ROOT_PARENT_UUID))
-   //            {
-   //               // root node
-   //               qpath = Constants.ROOT_PATH;
-   //               parentCid = null;
-   //            }
-   //            else
-   //            {
-   //               qpath = QPath.makeChildPath(traverseQPath(cpid), qname, cindex);
-   //               parentCid = cpid;
-   //            }
-   //         }
-   //
-   //         // preload properties
-   //
-   //         Map<String, List<byte[]>> properties = new LinkedHashMap<String, List<byte[]>>();
-   //
-   //         // PRIMARY
-   //         if (!item.next() || !item.getString(COLUMN_NAME).equals(Constants.JCR_PRIMARYTYPE.getAsString()))
-   //         {
-   //            throw new SQLException("Node finded but primaryType property not " + cid);
-   //         }
-   //
-   //         byte[] data = item.getBytes(COLUMN_VDATA);
-   //         InternalQName ptName = InternalQName.parse(new String((data != null ? data : new byte[]{})));
-   //
-   //         // MIXIN
-   //         MixinInfo mixins = null;
-   //         List<InternalQName> mts = null;
-   //         boolean owneable = false;
-   //         boolean privilegeable = false;
-   //         while (item.next() && item.getString(COLUMN_NAME).equals(Constants.JCR_MIXINTYPES.getAsString()))
-   //         {
-   //            mts = new ArrayList<InternalQName>();
-   //            byte[] mxnb = item.getBytes(COLUMN_VDATA);
-   //            if (mxnb != null)
-   //            {
-   //               InternalQName mxn = InternalQName.parse(new String(mxnb));
-   //               mts.add(mxn);
-   //
-   //               if (!privilegeable && Constants.EXO_PRIVILEGEABLE.equals(mxn))
-   //                  privilegeable = true;
-   //               else if (!owneable && Constants.EXO_OWNEABLE.equals(mxn))
-   //                  owneable = true;
-   //            } // else, if SQL NULL - skip it
-   //
-   //         }
-   //
-   //         mixins = new MixinInfo(mts, owneable, privilegeable);
-   //
-   //         try
-   //         {
-   //            // ACL
-   //            AccessControlList acl; // NO DEFAULT values!
-   //
-   //            if (mixins.hasOwneable())
-   //            {
-   //               // has own owner
-   //               if (mixins.hasPrivilegeable())
-   //               {
-   //                  // and permissions
-   //                  acl = new AccessControlList(readACLOwner(cid), readACLPermisions(cid));
-   //               }
-   //               else if (parentACL != null)
-   //               {
-   //                  // use permissions from existed parent
-   //                  acl =
-   //                     new AccessControlList(readACLOwner(cid), parentACL.hasPermissions() ? parentACL
-   //                        .getPermissionEntries() : null);
-   //               }
-   //               else
-   //               {
-   //                  // have to search nearest ancestor permissions in ACL manager
-   //                  // acl = new AccessControlList(readACLOwner(cid), traverseACLPermissions(cpid));
-   //                  acl = new AccessControlList(readACLOwner(cid), null);
-   //               }
-   //            }
-   //            else if (mixins.hasPrivilegeable())
-   //            {
-   //               // has own permissions
-   //               if (mixins.hasOwneable())
-   //               {
-   //                  // and owner
-   //                  acl = new AccessControlList(readACLOwner(cid), readACLPermisions(cid));
-   //               }
-   //               else if (parentACL != null)
-   //               {
-   //                  // use owner from existed parent
-   //                  acl = new AccessControlList(parentACL.getOwner(), readACLPermisions(cid));
-   //               }
-   //               else
-   //               {
-   //                  // have to search nearest ancestor owner in ACL manager
-   //                  // acl = new AccessControlList(traverseACLOwner(cpid), readACLPermisions(cid));
-   //                  acl = new AccessControlList(null, readACLPermisions(cid));
-   //               }
-   //            }
-   //            else
-   //            {
-   //               if (parentACL != null)
-   //                  // construct ACL from existed parent ACL
-   //                  acl =
-   //                     new AccessControlList(parentACL.getOwner(), parentACL.hasPermissions() ? parentACL
-   //                        .getPermissionEntries() : null);
-   //               else
-   //                  // have to search nearest ancestor owner and permissions in ACL manager
-   //                  // acl = traverseACL(cpid);
-   //                  acl = null;
-   //            }
-   //
-   //            return new PersistedNodeData(getIdentifier(cid), qpath, getIdentifier(parentCid), cversion, cnordernumb,
-   //               ptName, mixins.mixinNames(), acl);
-   //
-   //         }
-   //         catch (IllegalACLException e)
-   //         {
-   //            throw new RepositoryException("FATAL ERROR Node " + getIdentifier(cid) + " " + qpath.getAsString()
-   //               + " has wrong formed ACL. ", e);
-   //         }
-   //      }
-   //      catch (IllegalNameException e)
-   //      {
-   //         throw new RepositoryException(e);
-   //      }
-   //   }
+   /**
+    * {@inheritDoc} 
+    */
+   @Override
+   protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
+   {
+      String id = getIdentifier(cpid);
+      if (id.equals(Constants.ROOT_UUID))
+      {
+         return Constants.ROOT_PATH;
+      }
+      // get item by Identifier usecase
+      List<QPathEntry> qrpath = new ArrayList<QPathEntry>(); // reverted path
+      String caid = cpid; // container ancestor id
+      boolean isRoot = false;
+      do
+      {
+         ResultSet result = null;
+         try
+         {
+            result = findItemQPathByIdentifierCQ(caid);
+            if (!result.next())
+               throw new InvalidItemStateException("Parent not found, uuid: " + getIdentifier(caid));
 
+            QPathEntry qpe1 =
+               new QPathEntry(InternalQName.parse(result.getString(COLUMN_NAME)), result.getInt(COLUMN_INDEX));
+            boolean isChild = caid.equals(result.getString(COLUMN_ID));
+            caid = result.getString(COLUMN_PARENTID);
+            if (result.next())
+            {
+               QPathEntry qpe2 =
+                  new QPathEntry(InternalQName.parse(result.getString(COLUMN_NAME)), result.getInt(COLUMN_INDEX));
+               if (isChild)
+               {
+                  // The child is the first result then we have the parent
+                  qrpath.add(qpe1);
+                  qrpath.add(qpe2);
+                  // We need to take the value of the parent node
+                  caid = result.getString(COLUMN_PARENTID);
+               }
+               else
+               {
+                  // The parent is the first result then we have the child
+                  qrpath.add(qpe2);
+                  qrpath.add(qpe1);
+               }
+            }
+            else
+            {
+               qrpath.add(qpe1);
+            }
+         }
+         finally
+         {
+            result.close();
+         }
+         if (caid.equals(Constants.ROOT_PARENT_UUID) || (id = getIdentifier(caid)).equals(Constants.ROOT_UUID))
+         {
+            if (id.equals(Constants.ROOT_UUID))
+            {
+               qrpath.add(Constants.ROOT_PATH.getEntries()[0]);
+            }
+            isRoot = true;
+         }
+      }
+      while (!isRoot);
+
+      QPathEntry[] qentries = new QPathEntry[qrpath.size()];
+      int qi = 0;
+      for (int i = qrpath.size() - 1; i >= 0; i--)
+      {
+         qentries[qi++] = qrpath.get(i);
+      }
+      return new QPath(qentries);
+   }
+
+   protected abstract ResultSet findItemQPathByIdentifierCQ(String identifier) throws SQLException;
+
    protected abstract ResultSet findChildNodesByParentIdentifierCQ(String parentIdentifier) throws SQLException;
 
    protected abstract ResultSet findChildPropertiesByParentIdentifierCQ(String parentIdentifier) throws SQLException;

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2010-01-05 11:37:19 UTC (rev 1289)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2010-01-05 11:55:40 UTC (rev 1290)
@@ -90,6 +90,8 @@
 
    protected PreparedStatement findNodeMainPropertiesByParentIdentifierCQ;
 
+   protected PreparedStatement findItemQPathByIdentifierCQ;
+
    protected PreparedStatement insertNode;
 
    protected PreparedStatement insertProperty;
@@ -205,13 +207,18 @@
          "select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA"
             + " from (select * from JCR_MITEM where PARENT_ID=? and I_CLASS=1) I, JCR_MITEM P, JCR_MVALUE V"
             + " where (P.PARENT_ID=I.ID and P.I_CLASS=2 and (P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' or P.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes' or P.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner' or P.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions') and V.PROPERTY_ID=P.ID)"
-            + " order by I.N_ORDER_NUM, I.ID, PROP_NAME DESC, V.ORDER_NUM"; //I.N_ORDER_NUM
+            + " order by I.N_ORDER_NUM, I.ID, PROP_NAME DESC, V.ORDER_NUM";
 
       FIND_NODE_MAIN_PROPERTIES_BY_PARENTID_CQ =
          "select I.NAME, V.DATA"
             + " from JCR_MITEM I, JCR_MVALUE V"
             + " where I.I_CLASS=2 and I.PARENT_ID=? and (I.NAME='[http://www.jcp.org/jcr/1.0]primaryType' or I.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes' or I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner' or I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions') and I.ID=V.PROPERTY_ID order by V.ORDER_NUM";
 
+      FIND_ITEM_QPATH_BY_ID_CQ =
+         "select I.ID, I.PARENT_ID, I.NAME, I.I_INDEX"
+            + " from JCR_MITEM I, (SELECT ID, PARENT_ID from JCR_MITEM where ID=?) J"
+            + " where I.ID = J.ID or I.ID = J.PARENT_ID";
+
       FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=?";
 
       FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?" + " order by ID";
@@ -639,6 +646,18 @@
       return findNodeMainPropertiesByParentIdentifierCQ.executeQuery();
    }
 
+   @Override
+   protected ResultSet findItemQPathByIdentifierCQ(String identifier) throws SQLException
+   {
+      if (findItemQPathByIdentifierCQ == null)
+         findItemQPathByIdentifierCQ = dbConnection.prepareStatement(FIND_ITEM_QPATH_BY_ID_CQ);
+      else
+         findItemQPathByIdentifierCQ.clearParameters();
+
+      findItemQPathByIdentifierCQ.setString(1, identifier);
+      return findItemQPathByIdentifierCQ.executeQuery();
+   }
+
    /**
     * {@inheritDoc}
     */

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java	2010-01-05 11:37:19 UTC (rev 1289)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java	2010-01-05 11:55:40 UTC (rev 1290)
@@ -87,6 +87,8 @@
 
    protected PreparedStatement findNodeMainPropertiesByParentIdentifierCQ;
 
+   protected PreparedStatement findItemQPathByIdentifierCQ;
+
    protected PreparedStatement insertItem;
 
    protected PreparedStatement insertNode;
@@ -219,6 +221,11 @@
             + " from JCR_SITEM I, JCR_SVALUE V"
             + " where I.I_CLASS=2 and I.CONTAINER_NAME=? and I.PARENT_ID=? and (I.NAME='[http://www.jcp.org/jcr/1.0]primaryType' or I.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes' or I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner' or I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions') and I.ID=V.PROPERTY_ID order by V.ORDER_NUM";
 
+      FIND_ITEM_QPATH_BY_ID_CQ =
+         "select I.ID, I.PARENT_ID, I.NAME, I.I_INDEX"
+            + " from JCR_SITEM I, (SELECT ID, PARENT_ID from JCR_SITEM where ID=?) J"
+            + " where I.ID = J.ID or I.ID = J.PARENT_ID";
+
       FIND_NODES_COUNT_BY_PARENTID =
          "select count(ID) from JCR_SITEM" + " where I_CLASS=1 and CONTAINER_NAME=? and PARENT_ID=?";
 
@@ -657,6 +664,18 @@
    }
 
    @Override
+   protected ResultSet findItemQPathByIdentifierCQ(String identifier) throws SQLException
+   {
+      if (findItemQPathByIdentifierCQ == null)
+         findItemQPathByIdentifierCQ = dbConnection.prepareStatement(FIND_ITEM_QPATH_BY_ID_CQ);
+      else
+         findItemQPathByIdentifierCQ.clearParameters();
+
+      findItemQPathByIdentifierCQ.setString(1, identifier);
+      return findItemQPathByIdentifierCQ.executeQuery();
+   }
+
+   @Override
    protected ResultSet findReferencePropertiesCQ(String nodeIdentifier) throws SQLException
    {
       if (findReferencePropertiesCQ == null)



More information about the exo-jcr-commits mailing list