[exo-jcr-commits] exo-jcr SVN: r945 - 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
Tue Dec 8 08:32:33 EST 2009


Author: areshetnyak
Date: 2009-12-08 08:32:32 -0500 (Tue, 08 Dec 2009)
New Revision: 945

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Log:
EXOJCR-293 : The JDBCCacheLoader was changed. The open connection to DB on demand.

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-12-08 13:31:21 UTC (rev 944)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-12-08 13:32:32 UTC (rev 945)
@@ -305,26 +305,25 @@
       Fqn name = (fqn.size() > 1 ? IdTreeHelper.buildFqn(fqn) : fqn);
       Map<Object, Object> attrs;
 
-      JDBCStorageConnection conn = (JDBCStorageConnection)dataContainer.openConnection();
-      try
+      if (name.size() > 1)
       {
-
-         if (name.size() > 1)
+         if (name.get(0).equals(JBossCacheStorage.NODES))
          {
-            if (name.get(0).equals(JBossCacheStorage.NODES))
+            // /$NODES/<NODE_ID>
+            if (name.size() == 2)
             {
-               // /$NODES/<NODE_ID>
-               if (name.size() == 2)
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
                {
                   String nodeId = name.getLastElementAsString();
-                  NodeData nodeData = (NodeData)conn.getItemData(nodeId);
+                  NodeData nodeData = (NodeData) conn.getItemData(nodeId);
                   if (nodeData != null)
                   {
                      List<PropertyDataInfo> childProps = conn.getChildProperties(nodeId);
                      if (childProps.size() <= 0)
                      {
                         throw new JDBCCacheLoaderException("FATAL Empty attributes for Node " + nodeId + "  '" + name
-                           + "'");
+                                 + "'");
                      }
 
                      attrs = new LinkedHashMap<Object, Object>();
@@ -339,14 +338,22 @@
                      attrs = null;
                   }
                }
-               // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
-               else if (name.size() == 3)
+               finally
                {
+                  conn.close();
+               }
+            }
+            // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
+            else if (name.size() == 3)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
+               {
                   QPathEntry childNodeName = QPathEntry.parse(name.getLastElementAsString());
-                  String parentId = (String)name.get(1);
+                  String parentId = (String) name.get(1);
 
                   String nodeId =
-                     conn.getNodeIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
+                           conn.getNodeIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
                   if (nodeId != null)
                   {
                      attrs = new LinkedHashMap<Object, Object>();
@@ -357,19 +364,27 @@
                      attrs = null;
                   }
                }
-               else
+               finally
                {
-                  attrs = null;
-                  LOG.warn("Unexpected Fqn asked " + name);
+                  conn.close();
                }
             }
-            // /$PROPS/<PROPERTY_ID>
-            else if (name.get(0).equals(JBossCacheStorage.PROPS))
+            else
             {
-               if (name.size() == 2)
+               attrs = null;
+               LOG.warn("Unexpected Fqn asked " + name);
+            }
+         }
+         // /$PROPS/<PROPERTY_ID>
+         else if (name.get(0).equals(JBossCacheStorage.PROPS))
+         {
+            if (name.size() == 2)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
                {
                   String propertyId = name.getLastElementAsString();
-                  PropertyData propertyData = (PropertyData)conn.getItemData(propertyId);
+                  PropertyData propertyData = (PropertyData) conn.getItemData(propertyId);
                   if (propertyData != null)
                   {
                      attrs = new LinkedHashMap<Object, Object>();
@@ -380,18 +395,25 @@
                      attrs = null;
                   }
                }
-               else
+               finally
                {
-                  attrs = null;
-                  LOG.warn("Unexpected Fqn asked " + name);
+                  conn.close();
                }
             }
-            else if (name.get(0).equals(JBossCacheStorage.REFS))
+            else
             {
-               // get reference
-               if (name.size() == 3)
+               attrs = null;
+               LOG.warn("Unexpected Fqn asked " + name);
+            }
+         }
+         else if (name.get(0).equals(JBossCacheStorage.REFS))
+         {
+            // get reference
+            if (name.size() == 3)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
                {
-
                   // do we have such property reference
                   String nodeID = String.valueOf(name.get(1));
                   String propID = String.valueOf(name.get(2));
@@ -405,8 +427,16 @@
                      attrs = null;
                   }
                }
-               else if (name.size() == 2)
+               finally
                {
+                  conn.close();
+               }
+            }
+            else if (name.size() == 2)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
+               {
                   // do we have node with any reference
                   String nodeID = name.getLastElementAsString();
                   if (conn.getReferenceIdentifiers(nodeID).size() > 0)
@@ -418,39 +448,39 @@
                      attrs = null;
                   }
                }
-               else
+               finally
                {
-                  attrs = null;
-                  LOG.warn("Unexpected Fqn asked " + name);
+                  conn.close();
                }
-
             }
             else
             {
                attrs = null;
-               if (LOG.isDebugEnabled())
-               {
-                  LOG.warn("Unexpected Fqn asked " + name);
-               }
+               LOG.warn("Unexpected Fqn asked " + name);
             }
+
          }
-         else if (name.isRoot() || name.equals(Fqn.ROOT) || name.getLastElementAsString().equals("/")
-            || name.get(0).equals(JBossCacheStorage.PROPS) || name.get(0).equals(JBossCacheStorage.NODES)
-            || name.get(0).equals(JBossCacheStorage.LOCKS) || name.get(0).equals(JBossCacheStorage.REFS))
-         {
-            // roots, like NODES, PROPS etc               
-            attrs = new LinkedHashMap<Object, Object>();
-         }
          else
          {
-            LOG.warn("Unexpected Fqn asked " + name);
             attrs = null;
+            if (LOG.isDebugEnabled())
+            {
+               LOG.warn("Unexpected Fqn asked " + name);
+            }
          }
       }
-      finally
+      else if (name.isRoot() || name.equals(Fqn.ROOT) || name.getLastElementAsString().equals("/")
+               || name.get(0).equals(JBossCacheStorage.PROPS) || name.get(0).equals(JBossCacheStorage.NODES)
+               || name.get(0).equals(JBossCacheStorage.LOCKS) || name.get(0).equals(JBossCacheStorage.REFS))
       {
-         conn.close();
+         // roots, like NODES, PROPS etc               
+         attrs = new LinkedHashMap<Object, Object>();
       }
+      else
+      {
+         LOG.warn("Unexpected Fqn asked " + name);
+         attrs = null;
+      }
 
       return attrs;
    }
@@ -460,20 +490,19 @@
     */
    public boolean exists(Fqn fqn) throws Exception
    {
-      JDBCStorageConnection conn = (JDBCStorageConnection)dataContainer.openConnection();
-
       Fqn name = (fqn.size() > 1 ? IdTreeHelper.buildFqn(fqn) : fqn);
 
       boolean exists;
 
-      try
+      if (name.size() > 1)
       {
-         if (name.size() > 1)
+         if (name.get(0).equals(JBossCacheStorage.NODES))
          {
-            if (name.get(0).equals(JBossCacheStorage.NODES))
+            // /$NODES/<NODE_ID>
+            if (name.size() == 2)
             {
-               // /$NODES/<NODE_ID>
-               if (name.size() == 2)
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
                {
                   String nodeId = name.getLastElementAsString();
                   String nodeName = conn.getNodeName(nodeId);
@@ -487,14 +516,22 @@
                      exists = false;
                   }
                }
-               // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
-               else if (name.size() == 3)
+               finally
                {
+                  conn.close();
+               }
+            }
+            // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
+            else if (name.size() == 3)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
+               {
                   QPathEntry childNodeName = QPathEntry.parse(name.getLastElementAsString());
-                  String parentId = (String)name.get(1);
+                  String parentId = (String) name.get(1);
 
                   String nodeId =
-                     conn.getNodeIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
+                           conn.getNodeIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
                   if (nodeId != null)
                   {
                      exists = true;
@@ -504,16 +541,24 @@
                      exists = false;
                   }
                }
-               else
+               finally
                {
-                  exists = false;
-                  LOG.warn("Unexpected Fqn asked " + name);
+                  conn.close();
                }
             }
-            // /$PROPS/<PROPERTY_ID>
-            else if (name.get(0).equals(JBossCacheStorage.PROPS))
+            else
             {
-               if (name.size() == 2)
+               exists = false;
+               LOG.warn("Unexpected Fqn asked " + name);
+            }
+         }
+         // /$PROPS/<PROPERTY_ID>
+         else if (name.get(0).equals(JBossCacheStorage.PROPS))
+         {
+            if (name.size() == 2)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
                {
                   String propertyId = name.getLastElementAsString();
                   String propertyName = conn.getPropertyName(propertyId);
@@ -527,60 +572,76 @@
                      exists = false;
                   }
                }
-               else
+               finally
                {
-                  exists = false;
-                  LOG.warn("Unexpected Fqn asked " + name);
+                  conn.close();
                }
             }
-            else if (name.get(0).equals(JBossCacheStorage.REFS))
+            else
             {
-               // /$REFS/<NODE_ID>
-               if (name.size() == 2)
+               exists = false;
+               LOG.warn("Unexpected Fqn asked " + name);
+            }
+         }
+         else if (name.get(0).equals(JBossCacheStorage.REFS))
+         {
+            // /$REFS/<NODE_ID>
+            if (name.size() == 2)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
                {
                   String nodeId = name.getLastElementAsString();
                   exists = conn.getReferenceIdentifiers(nodeId).size() > 0;
                }
-               // /$REFS/<NODE_ID>/<REF_PROP_ID>
-               else if (name.size() == 3)
+               finally
                {
+                  conn.close();
+               }
+            }
+            // /$REFS/<NODE_ID>/<REF_PROP_ID>
+            else if (name.size() == 3)
+            {
+               JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+               try
+               {
                   String refPropertyId = name.getLastElementAsString();
-                  String nodeId = (String)name.get(1);
+                  String nodeId = (String) name.get(1);
 
                   exists = conn.hasReference(nodeId, refPropertyId);
                }
-               else
+               finally
                {
-                  exists = false;
-                  LOG.warn("Unexpected Fqn asked " + name);
+                  conn.close();
                }
             }
             else
             {
                exists = false;
-               if (LOG.isDebugEnabled())
-               {
-                  LOG.debug("Unexpected Fqn asked " + name);
-               }
+               LOG.warn("Unexpected Fqn asked " + name);
             }
          }
-         else if (name.isRoot() || name.equals(Fqn.ROOT) || name.getLastElementAsString().equals("/")
-            || name.get(0).equals(JBossCacheStorage.PROPS) || name.get(0).equals(JBossCacheStorage.NODES)
-            || name.get(0).equals(JBossCacheStorage.LOCKS) || name.get(0).equals(JBossCacheStorage.REFS))
-         {
-            // roots, like NODES, PROPS etc               
-            exists = true;
-         }
          else
          {
             exists = false;
-            LOG.warn("Unexpected Fqn asked " + name);
+            if (LOG.isDebugEnabled())
+            {
+               LOG.debug("Unexpected Fqn asked " + name);
+            }
          }
       }
-      finally
+      else if (name.isRoot() || name.equals(Fqn.ROOT) || name.getLastElementAsString().equals("/")
+               || name.get(0).equals(JBossCacheStorage.PROPS) || name.get(0).equals(JBossCacheStorage.NODES)
+               || name.get(0).equals(JBossCacheStorage.LOCKS) || name.get(0).equals(JBossCacheStorage.REFS))
       {
-         conn.close();
+         // roots, like NODES, PROPS etc               
+         exists = true;
       }
+      else
+      {
+         exists = false;
+         LOG.warn("Unexpected Fqn asked " + name);
+      }
 
       return exists;
    }
@@ -598,77 +659,84 @@
 
       Fqn name = (fqn.size() >= 2 ? IdTreeHelper.buildFqn(fqn) : fqn);
 
-      JDBCStorageConnection conn = (JDBCStorageConnection)dataContainer.openConnection();
-      try
+      // /$NODES/<NODE_ID>
+      if (name.size() == 2)
       {
-         // /$NODES/<NODE_ID>
-         if (name.size() == 2)
+         String nodeId = (String) name.get(1);
+         if (name.get(0).equals(JBossCacheStorage.NODES))
          {
-            String nodeId = (String)name.get(1);
-            if (name.get(0).equals(JBossCacheStorage.NODES))
+            JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+            try
             {
                return conn.getChildNodeNames(nodeId);
             }
-            else if (name.get(0).equals(JBossCacheStorage.REFS))
+            finally
             {
+               conn.close();
+            }
+         }
+         else if (name.get(0).equals(JBossCacheStorage.REFS))
+         {
+            JDBCStorageConnection conn = (JDBCStorageConnection) dataContainer.openConnection();
+            try
+            {
                List<String> references = conn.getReferenceIdentifiers(nodeId);
                Set<String> result = new LinkedHashSet<String>();
                result.addAll(references);
                return result;
             }
-            else
+            finally
             {
-               // TODO this a property on any unexpected part of cache throw Exception
-               return null;
+               conn.close();
             }
          }
-         else if (name.isRoot() || name.get(0).equals(Fqn.ROOT) || name.getLastElementAsString().equals("/"))
-         {
-            Set<String> childs = new LinkedHashSet<String>();
-            childs.add(JBossCacheStorage.NODES);
-            childs.add(JBossCacheStorage.PROPS);
-            childs.add(JBossCacheStorage.LOCKS);
-            childs.add(JBossCacheStorage.REFS);
-            return childs;
-         }
-         else if (name.size() > 2)
-         {
-            // seems it is fqn like /$NODES/nodeUUID/childname[/...] or /$REFS/nodeUUID/propUUUIS[/...]
-            // TODO  this is unexpected part of cache throw Exception
-            LOG.warn("This is unexpected FQN " + name);
-            return null;
-         }
-         else if (name.get(0).equals(JBossCacheStorage.NODES))
-         {
-            // TODO should never be called
-            LOG.warn("conn.getAllNodeIdentifiers()");
-            return null/*conn.getAllNodeIdentifiers()*/;
-         }
-         else if (name.get(0).equals(JBossCacheStorage.PROPS))
-         {
-            // TODO should never be called
-            LOG.warn("conn.getAllPropertyIdentifiers()");
-            return null/*conn.getAllPropertyIdentifiers()*/;
-         }
-         else if (name.get(0).equals(JBossCacheStorage.LOCKS))
-         {
-            // TODO return all Locks in workspace
-            return new LinkedHashSet<String>();
-         }
-         else if (name.get(0).equals(JBossCacheStorage.REFS))
-         {
-            return null/*conn.getAllRefencedNodeIdentifiers()*/;
-         }
          else
          {
+            // TODO this a property on any unexpected part of cache throw Exception
             return null;
          }
       }
-      finally
+      else if (name.isRoot() || name.get(0).equals(Fqn.ROOT) || name.getLastElementAsString().equals("/"))
       {
-         conn.close();
+         Set<String> childs = new LinkedHashSet<String>();
+         childs.add(JBossCacheStorage.NODES);
+         childs.add(JBossCacheStorage.PROPS);
+         childs.add(JBossCacheStorage.LOCKS);
+         childs.add(JBossCacheStorage.REFS);
+         return childs;
       }
-      //      return null;
+      else if (name.size() > 2)
+      {
+         // seems it is fqn like /$NODES/nodeUUID/childname[/...] or /$REFS/nodeUUID/propUUUIS[/...]
+         // TODO  this is unexpected part of cache throw Exception
+         LOG.warn("This is unexpected FQN " + name);
+         return null;
+      }
+      else if (name.get(0).equals(JBossCacheStorage.NODES))
+      {
+         // TODO should never be called
+         LOG.warn("conn.getAllNodeIdentifiers()");
+         return null/*conn.getAllNodeIdentifiers()*/;
+      }
+      else if (name.get(0).equals(JBossCacheStorage.PROPS))
+      {
+         // TODO should never be called
+         LOG.warn("conn.getAllPropertyIdentifiers()");
+         return null/*conn.getAllPropertyIdentifiers()*/;
+      }
+      else if (name.get(0).equals(JBossCacheStorage.LOCKS))
+      {
+         // TODO return all Locks in workspace
+         return new LinkedHashSet<String>();
+      }
+      else if (name.get(0).equals(JBossCacheStorage.REFS))
+      {
+         return null/*conn.getAllRefencedNodeIdentifiers()*/;
+      }
+      else
+      {
+         return null;
+      }
    }
 
    /**



More information about the exo-jcr-commits mailing list