[jbosscache-commits] JBoss Cache SVN: r4441 - core/trunk/src/main/java/org/jboss/cache/interceptors.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Sat Aug 25 23:18:53 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-08-25 23:18:52 -0400 (Sat, 25 Aug 2007)
New Revision: 4441

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
Log:
[JBCACHE-1172] If method needs all data map entries, load if !Node.isDataLoaded()

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java	2007-08-26 03:05:01 UTC (rev 4440)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java	2007-08-26 03:18:52 UTC (rev 4441)
@@ -70,8 +70,8 @@
       GlobalTransaction gtx;
       boolean recursive = false;// do we also load children?
       boolean bypassLoadingData = false;
+      boolean allKeys = false; // is method a getter asking for all data keys?
 
-
       if ((gtx = ctx.getGlobalTransaction()) != null)
       {
          entry = txTable.get(gtx);
@@ -119,12 +119,17 @@
          case MethodDeclarations.getNodeMethodLocal_id:
          case MethodDeclarations.getChildrenNamesMethodLocal_id:
             bypassLoadingData = true;
-         case MethodDeclarations.getKeysMethodLocal_id:
          case MethodDeclarations.releaseAllLocksMethodLocal_id:
          case MethodDeclarations.printMethodLocal_id:
             fqn = (Fqn) args[0];
             acquireLock = true;
             break;
+         case MethodDeclarations.getKeysMethodLocal_id:
+         case MethodDeclarations.getDataMapMethodLocal_id:
+            allKeys = true;
+            fqn = (Fqn) args[0];
+            acquireLock = true;
+            break;
          case MethodDeclarations.rollbackMethod_id:
             // clean up nodesCreated map
             cleanupNodesCreated(entry);
@@ -152,20 +157,20 @@
       {
          if (fqn2 != null)
          {
-            loadIfNeeded(ctx, fqn2, key, initNode, acquireLock, m, entry, false, m.getMethodId() == MethodDeclarations.moveMethodLocal_id, bypassLoadingData);
+            loadIfNeeded(ctx, fqn2, key, allKeys, initNode, acquireLock, m, entry, false, m.getMethodId() == MethodDeclarations.moveMethodLocal_id, bypassLoadingData);
          }
-         loadIfNeeded(ctx, fqn, key, initNode, acquireLock, m, entry, recursive, m.getMethodId() == MethodDeclarations.moveMethodLocal_id, bypassLoadingData);
+         loadIfNeeded(ctx, fqn, key, allKeys, initNode, acquireLock, m, entry, recursive, m.getMethodId() == MethodDeclarations.moveMethodLocal_id, bypassLoadingData);
       }
 
       return super.invoke(ctx);
    }
 
 
-   private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean initNode, boolean acquireLock, MethodCall m, TransactionEntry entry, boolean recursive, boolean isMove, boolean bypassLoadingData) throws Throwable
+   private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean allKeys, boolean initNode, boolean acquireLock, MethodCall m, TransactionEntry entry, boolean recursive, boolean isMove, boolean bypassLoadingData) throws Throwable
    {
       NodeSPI n = cache.peek(fqn, true);
 
-      boolean mustLoad = mustLoad(n, key);
+      boolean mustLoad = mustLoad(n, key, allKeys);
       if (log.isTraceEnabled())
       {
          log.trace("load element " + fqn + " mustLoad=" + mustLoad);
@@ -287,24 +292,28 @@
       node.setChildrenLoaded(true);
    }
 
-   private boolean mustLoad(NodeSPI n, Object key)
+   private boolean mustLoad(NodeSPI n, Object key, boolean allKeys)
    {
       if (n == null)
       {
          log.trace("must load, node null");
          return true;
       }
-      // if we are not looking for a specific key don't bother loading!
-      if (key == null)
+      // JBCACHE-1172 Skip single-key optimization if request needs all keys
+      if (!allKeys)
       {
-         log.trace("don't load, key requested is null");
-         return false;
+         // if we are not looking for a specific key don't bother loading!
+         if (key == null)
+         {
+            log.trace("don't load, key requested is null");
+            return false;
+         }
+         if (n.getKeysDirect().contains(key))
+         {
+            log.trace("don't load, already have necessary key in memory");
+            return false;
+         }
       }
-      if (n.getKeysDirect().contains(key))
-      {
-         log.trace("don't load, already have necessary key in memory");
-         return false;
-      }
       if (!n.isDataLoaded())
       {
          log.trace("must Load, uninitialized");




More information about the jbosscache-commits mailing list