[exo-jcr-commits] exo-jcr SVN: r1465 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent: jbosscache and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 18 09:40:18 EST 2010


Author: skabashnyuk
Date: 2010-01-18 09:40:17 -0500 (Mon, 18 Jan 2010)
New Revision: 1465

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-391 : put in cache on get now is out of scope of transaction

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java	2010-01-18 14:24:35 UTC (rev 1464)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java	2010-01-18 14:40:17 UTC (rev 1465)
@@ -309,79 +309,6 @@
       }
    }
 
-   protected class CacheNodesInTransaction extends StorageTxIsolatedOperation
-   {
-      final List<NodeData> childs;
-
-      final NodeData parent;
-
-      CacheNodesInTransaction(NodeData parent, List<NodeData> childs)
-      {
-         this.parent = parent;
-         this.childs = childs;
-      }
-
-      @Override
-      protected void action() throws RepositoryException
-      {
-         cache.addChildNodes(parent, childs);
-      }
-   }
-
-   protected class CachePropertiesInTransaction extends StorageTxIsolatedOperation
-   {
-      final List<PropertyData> childs;
-
-      final NodeData parent;
-
-      CachePropertiesInTransaction(NodeData parent, List<PropertyData> childs)
-      {
-         this.parent = parent;
-         this.childs = childs;
-      }
-
-      @Override
-      protected void action() throws RepositoryException
-      {
-         cache.addChildProperties(parent, childs);
-      }
-   }
-
-   protected class CachePropertiesListInTransaction extends StorageTxIsolatedOperation
-   {
-      final List<PropertyData> childsList;
-
-      final NodeData parent;
-
-      CachePropertiesListInTransaction(NodeData parent, List<PropertyData> childsList)
-      {
-         this.parent = parent;
-         this.childsList = childsList;
-      }
-
-      @Override
-      protected void action() throws RepositoryException
-      {
-         cache.addChildPropertiesList(parent, childsList);
-      }
-   }
-
-   protected class CacheItemInTransaction extends StorageTxIsolatedOperation
-   {
-      final ItemData item;
-
-      CacheItemInTransaction(ItemData item)
-      {
-         this.item = item;
-      }
-
-      @Override
-      protected void action() throws RepositoryException
-      {
-         cache.put(item);
-      }
-   }
-
    /**
     * CacheableWorkspaceDataManager constructor.
     * 
@@ -644,48 +571,7 @@
 
             if (parentData != null)
             {
-               if (isTxAware())
                {
-                  new CacheNodesInTransaction(parentData, childNodes).perform();
-
-                  // TODO
-                  //                  try
-                  //                  {
-                  //                     if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
-                  //                     {
-                  //                        cache.addChildNodes(parentData, childNodes);
-                  //                     }
-                  //                     else
-                  //                     {
-                  //                        transactionManager.begin();
-                  //                        cache.beginTransaction();
-                  //                        cache.addChildNodes(parentData, childNodes);
-                  //                        cache.commitTransaction();
-                  //                        transactionManager.commit();
-                  //                     }
-                  //                  }
-                  //                  catch (RollbackException e)
-                  //                  {
-                  //                     // Indicate that the transaction has been rolled back rather than committed.
-                  //                     throw new RepositoryException(e);
-                  //                  }
-                  //                  catch (Exception e)
-                  //                  {
-                  //                     try
-                  //                     {
-                  //                        cache.rollbackTransaction();
-                  //                        transactionManager.rollback();
-                  //                     }
-                  //                     catch (Exception e1)
-                  //                     {
-                  //                        LOG.error("Rollback error ", e1);
-                  //                     }
-                  //
-                  //                     throw new RepositoryException(e);
-                  //                  }
-               }
-               else
-               {
                   cache.addChildNodes(parentData, childNodes);
                }
             }
@@ -742,48 +628,7 @@
 
             if (parentData != null)
             {
-               if (isTxAware())
                {
-                  new CachePropertiesInTransaction(parentData, childProperties).perform();
-
-                  // TODO
-                  //                  try
-                  //                  {
-                  //                     if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
-                  //                     {
-                  //                        cache.addChildProperties(parentData, childProperties);
-                  //                     }
-                  //                     else
-                  //                     {
-                  //                        transactionManager.begin();
-                  //                        cache.beginTransaction();
-                  //                        cache.addChildProperties(parentData, childProperties);
-                  //                        cache.commitTransaction();
-                  //                        transactionManager.commit();
-                  //                     }
-                  //                  }
-                  //                  catch (RollbackException e)
-                  //                  {
-                  //                     // Indicate that the transaction has been rolled back rather than committed.
-                  //                     throw new RepositoryException(e);
-                  //                  }
-                  //                  catch (Exception e)
-                  //                  {
-                  //                     try
-                  //                     {
-                  //                        cache.rollbackTransaction();
-                  //                        transactionManager.rollback();
-                  //                     }
-                  //                     catch (Exception e1)
-                  //                     {
-                  //                        LOG.error("Rollback error ", e1);
-                  //                     }
-                  //
-                  //                     throw new RepositoryException(e);
-                  //                  }
-               }
-               else
-               {
                   cache.addChildProperties(parentData, childProperties);
                }
             }
@@ -812,48 +657,7 @@
       ItemData data = super.getItemData(parentData, name);
       if (data != null && cache.isEnabled())
       {
-         if (isTxAware())
          {
-            new CacheItemInTransaction(data).perform();
-
-            // TODO
-            //            try
-            //            {
-            //               if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
-            //               {
-            //                  cache.put(data);
-            //               }
-            //               else
-            //               {
-            //                  transactionManager.begin();
-            //                  cache.beginTransaction();
-            //                  cache.put(data);
-            //                  cache.commitTransaction();
-            //                  transactionManager.commit();
-            //               }
-            //            }
-            //            catch (RollbackException e)
-            //            {
-            //               // Indicate that the transaction has been rolled back rather than committed.
-            //               throw new RepositoryException(e);
-            //            }
-            //            catch (Exception e)
-            //            {
-            //               try
-            //               {
-            //                  cache.rollbackTransaction();
-            //                  transactionManager.rollback();
-            //               }
-            //               catch (Exception e1)
-            //               {
-            //                  LOG.error("Rollback error ", e1);
-            //               }
-            //
-            //               throw new RepositoryException(e);
-            //            }
-         }
-         else
-         {
             cache.put(data);
          }
       }
@@ -872,48 +676,7 @@
       ItemData data = super.getItemData(identifier);
       if (data != null && cache.isEnabled())
       {
-         if (isTxAware())
          {
-            new CacheItemInTransaction(data).perform();
-
-            // TODO
-            //            try
-            //            {
-            //               if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
-            //               {
-            //                  cache.put(data);
-            //               }
-            //               else
-            //               {
-            //                  transactionManager.begin();
-            //                  cache.beginTransaction();
-            //                  cache.put(data);
-            //                  cache.commitTransaction();
-            //                  transactionManager.commit();
-            //               }
-            //            }
-            //            catch (RollbackException e)
-            //            {
-            //               // Indicate that the transaction has been rolled back rather than committed.
-            //               throw new RepositoryException(e);
-            //            }
-            //            catch (Exception e)
-            //            {
-            //               try
-            //               {
-            //                  cache.rollbackTransaction();
-            //                  transactionManager.rollback();
-            //               }
-            //               catch (Exception e1)
-            //               {
-            //                  LOG.error("Rollback error ", e1);
-            //               }
-            //
-            //               throw new RepositoryException(e);
-            //            }
-         }
-         else
-         {
             cache.put(data);
          }
       }
@@ -960,47 +723,7 @@
 
          if (parentData != null)
          {
-            if (isTxAware())
             {
-               new CachePropertiesListInTransaction(parentData, propertiesList).perform();
-
-               //               if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
-               //               {
-               //                  cache.addChildPropertiesList(parentData, propertiesList);
-               //               }
-               //               else
-               //               {
-               //                  try
-               //                  {
-               //                     transactionManager.begin();
-               //                     cache.beginTransaction();
-               //                     cache.addChildPropertiesList(parentData, propertiesList);
-               //                     cache.commitTransaction();
-               //                     transactionManager.commit();
-               //                  }
-               //                  catch (RollbackException e)
-               //                  {
-               //                     // Indicate that the transaction has been rolled back rather than committed.
-               //                     throw new RepositoryException(e);
-               //                  }
-               //                  catch (Exception e)
-               //                  {
-               //                     try
-               //                     {
-               //                        cache.rollbackTransaction();
-               //                        transactionManager.rollback();
-               //                     }
-               //                     catch (Exception e1)
-               //                     {
-               //                        LOG.error("Rollback error ", e1);
-               //                     }
-               //
-               //                     throw new RepositoryException(e);
-               //                  }
-               //               }
-            }
-            else
-            {
                cache.addChildPropertiesList(parentData, propertiesList);
             }
          }
@@ -1141,4 +864,4 @@
    //         conn.close();
    //      }
    //   }
-}
+}
\ No newline at end of file

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java	2010-01-18 14:24:35 UTC (rev 1464)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java	2010-01-18 14:40:17 UTC (rev 1465)
@@ -59,7 +59,7 @@
    private final Cache<Serializable, Object> parentCache;
 
    private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
-   
+
    private ThreadLocal<Boolean> local = new ThreadLocal<Boolean>();
 
    protected static final Log LOG =
@@ -76,11 +76,21 @@
     */
    public void beginTransaction()
    {
+
       changesList.set(new CompressedChangesBuffer());
       local.set(false);
    }
 
    /**
+    * 
+    * @return status of the cache transaction
+    */
+   public boolean isTransactionActive()
+   {
+      return changesList.get() != null;
+   }
+
+   /**
     * Sort changes and commit data to the cache.
     */
    public void commitTransaction()
@@ -134,9 +144,18 @@
     */
    public void setLocal(boolean local)
    {
+      //start local transaction
+      if (local && changesList.get() == null)
+      {
+         beginTransaction();
+      }
+      if (!local && this.local.get())
+      {
+
+      }
       this.local.set(local);
    }
-   
+
    /* (non-Javadoc)
     * @see org.jboss.cache.Cache#addCacheListener(java.lang.Object)
     */
@@ -402,7 +421,8 @@
    public void put(Fqn fqn, Map<? extends Serializable, ? extends Object> data)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new PutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new PutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
+         .get()));
    }
 
    /* (non-Javadoc)
@@ -411,7 +431,8 @@
    public Object put(Fqn fqn, Serializable key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+         local.get()));
 
       return parentCache.get(fqn, key);
    }
@@ -447,7 +468,8 @@
    public Object remove(Fqn fqn, Serializable key)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
+         .get()));
       return parentCache.get(fqn, key);
    }
 
@@ -557,7 +579,8 @@
    public void addToList(Fqn fqn, String key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+         local.get()));
    }
 
    /**
@@ -570,8 +593,8 @@
    public void removeFromList(Fqn fqn, String key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer
-         .add(new RemoveFromListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new RemoveFromListContainer(fqn, key, value, parentCache,
+         changesContainer.getHistoryIndex(), local.get()));
    }
 
    public static enum ChangesType {
@@ -593,7 +616,8 @@
 
       protected final boolean localMode;
 
-      public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex, boolean localMode)
+      public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
+         boolean localMode)
       {
          super();
          this.fqn = fqn;
@@ -646,7 +670,7 @@
       {
          cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
       }
-      
+
       public abstract void apply();
    }
 
@@ -787,7 +811,8 @@
    {
       private final Serializable key;
 
-      public RemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+      public RemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex,
+         boolean local)
       {
          super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
          this.key = key;

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-01-18 14:24:35 UTC (rev 1464)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-01-18 14:40:17 UTC (rev 1465)
@@ -352,8 +352,11 @@
     */
    public void put(ItemData item)
    {
+      boolean inTransaction = cache.isTransactionActive();
       try
       {
+         if (!inTransaction)
+            cache.beginTransaction();
          cache.setLocal(true);
          if (item.isNode())
          {
@@ -367,6 +370,8 @@
       finally
       {
          cache.setLocal(false);
+         if (!inTransaction)
+            cache.commitTransaction();
       }
    }
 
@@ -428,15 +433,18 @@
    */
    public void addChildNodes(NodeData parent, List<NodeData> childs)
    {
+      boolean inTransaction = cache.isTransactionActive();
       try
       {
+
+         if (!inTransaction)
+            cache.beginTransaction();
          cache.setLocal(true);
          // remove previous all (to be sure about consistency)
          cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
 
          if (childs.size() > 0)
          {
-            // add all new
             Set<Object> set = new HashSet<Object>();
             for (NodeData child : childs)
             {
@@ -454,6 +462,8 @@
       finally
       {
          cache.setLocal(false);
+         if (!inTransaction)
+            cache.commitTransaction();
       }
    }
 
@@ -462,8 +472,11 @@
     */
    public void addChildProperties(NodeData parent, List<PropertyData> childs)
    {
+      boolean inTransaction = cache.isTransactionActive();
       try
       {
+         if (!inTransaction)
+            cache.beginTransaction();
          cache.setLocal(true);
          // remove previous all (to be sure about consistency)
          cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
@@ -477,6 +490,7 @@
                set.add(child.getIdentifier());
             }
             cache.put(makeChildListFqn(childPropsList, parent.getIdentifier()), ITEM_LIST, set);
+
          }
          else
          {
@@ -486,6 +500,8 @@
       finally
       {
          cache.setLocal(false);
+         if (!inTransaction)
+            cache.commitTransaction();
       }
    }
 
@@ -494,15 +510,18 @@
     */
    public void addChildPropertiesList(NodeData parent, List<PropertyData> childProperties)
    {
-      try
-      {
-         cache.setLocal(true);
-         // TODO not implemented, will force read from DB
-      }
-      finally
-      {
-         cache.setLocal(false);
-      }
+      // TODO not implemented, will force read from DB
+      //      try
+      //      {
+      //         cache.beginTransaction();
+      //         cache.setLocal(true);
+      //         
+      //      }
+      //      finally
+      //      {
+      //         cache.setLocal(false);
+      //         cache.commitTransaction();
+      //      }
    }
 
    /**



More information about the exo-jcr-commits mailing list