[jbosscache-commits] JBoss Cache SVN: r7255 - core/trunk/src/main/java/org/jboss/cache/loader/jdbm.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Dec 5 19:03:37 EST 2008


Author: genman
Date: 2008-12-05 19:03:37 -0500 (Fri, 05 Dec 2008)
New Revision: 7255

Modified:
   core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java
Log:
JBCACHE-1447 - Removing nodes when iterating ("browsing") causes browsing to not work properly. Also, exposing some methods as package-protected for JBCACHE-1440

Modified: core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java	2008-12-05 14:41:23 UTC (rev 7254)
+++ core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java	2008-12-06 00:03:37 UTC (rev 7255)
@@ -40,6 +40,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -89,8 +90,8 @@
    private static final String NAME = "JdbmCacheLoader";
 
    private JdbmCacheLoaderConfig config;
-   private RecordManager recman;
-   private BTree tree;
+   RecordManager recman;
+   BTree tree;
 
    /*
     * Service implementation -- lifecycle methods.
@@ -112,7 +113,7 @@
          throws Exception
    {
 
-      log.trace("Starting JdbmCacheLoader instance.");
+      log.trace("Starting " + getClass().getSimpleName() + " instance.");
       checkNotOpen();
       checkNonNull(cache, "CacheSPI object is required");
 
@@ -236,12 +237,17 @@
       }
       else
       {
-         config = new JdbmCacheLoaderConfig(base);
+         config = createConfig(base);
       }
 
       if (trace) log.trace("Configuring cache loader with location = " + config.getLocation());
    }
 
+   JdbmCacheLoaderConfig createConfig(IndividualCacheLoaderConfig base)
+   {
+      return new JdbmCacheLoaderConfig(base);
+   }
+
    public IndividualCacheLoaderConfig getConfig()
    {
       return config;
@@ -281,7 +287,7 @@
     * transaction is not recommended.
     */
    public Set<?> getChildrenNames(Fqn name)
-         throws Exception
+         throws IOException
    {
 
       if (trace)
@@ -295,7 +301,7 @@
       }
    }
 
-   private Set<Object> getChildrenNames0(Fqn name) throws IOException
+   Set<Object> getChildrenNames0(Fqn name) throws IOException
    {
       TupleBrowser browser = tree.browse(name);
       Tuple t = new Tuple();
@@ -398,7 +404,7 @@
       return tree.find(name) != null;
    }
 
-   private void commit() throws Exception
+   void commit() throws IOException
    {
       recman.commit();
    }
@@ -420,7 +426,7 @@
       }
    }
 
-   private Object put0(Fqn name, Object key, Object value) throws Exception
+   Object put0(Fqn name, Object key, Object value) throws Exception
    {
       checkNonNull(name, "name");
       makeNode(name);
@@ -445,7 +451,7 @@
       commit();
    }
 
-   private void put0(Fqn name, Map<?, ?> values) throws Exception
+   void put0(Fqn name, Map<?, ?> values) throws Exception
    {
       if (trace)
       {
@@ -501,39 +507,43 @@
       erase0(name, true);
    }
 
-   private void erase0(Fqn name, boolean self)
+   void erase0(Fqn name, boolean self)
          throws IOException
    {
       if (trace)
       {
          log.trace("erase " + name + " self=" + self);
       }
+      List<Object> removeList = new ArrayList<Object>();
       synchronized (tree)
       {
          TupleBrowser browser = tree.browse(name);
          Tuple t = new Tuple();
-         if (browser.getNext(t) && self)
-         {
-            tree.remove(t.getKey());
-         }
-
+         boolean first = true;
          while (browser.getNext(t))
          {
+	        if (first && !self)
+	        {
+	           first = false;
+	           continue;
+	        }
             Fqn fqn = (Fqn) t.getKey();
-            if (!fqn.isChildOf(name))
+            if (!fqn.isChildOrEquals(name))
             {
                break;
             }
-            tree.remove(fqn);
+            removeList.add(fqn);
          }
       }
+      for (Object o : removeList)
+         tree.remove(o);
    }
 
    /**
     * Erase a FQN's key.
     * Does not commit.
     */
-   private Object eraseKey0(Fqn name, Object key)
+   Object eraseKey0(Fqn name, Object key)
          throws IOException
    {
       if (trace)
@@ -605,7 +615,7 @@
     * auto-commit in a transactional environment.
     */
    public void remove(Fqn name)
-         throws Exception
+         throws IOException
    {
       erase0(name);
       commit();
@@ -642,7 +652,7 @@
    /**
     * Throws an exception if the environment is not open.
     */
-   private void checkOpen()
+   void checkOpen()
    {
       if (tree == null)
       {
@@ -654,7 +664,7 @@
    /**
     * Throws an exception if the environment is not open.
     */
-   private void checkNotOpen()
+   protected void checkNotOpen()
    {
       if (tree != null)
       {
@@ -666,7 +676,7 @@
    /**
     * Throws an exception if the parameter is null.
     */
-   private void checkNonNull(Object param, String paramName)
+   protected void checkNonNull(Object param, String paramName)
    {
       if (param == null)
       {
@@ -707,6 +717,13 @@
       }
       log.debug("");
    }
+   
+   /**
+    * Returns the number of database record nodes.
+    */
+   public int size() {
+      return tree.size();
+   }
 
    @Override
    public String toString()




More information about the jbosscache-commits mailing list