directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1164667 [2/6] - in /directory/apacheds/branches/one-sub-level-index-removal: ./ all/ core-annotations/ core-annotations/src/test/java/org/apache/directory/server/core/factory/ core-api/ core-api/src/main/java/org/apache/directory/server/co...
Date Fri, 02 Sep 2011 18:31:02 GMT
Modified: directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java Fri Sep  2 18:30:57 2011
@@ -47,6 +47,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.parsers.NormalizerDescription;
 import org.apache.directory.shared.ldap.model.schema.parsers.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.model.schema.registries.SchemaLoader;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -95,17 +96,17 @@ public class SchemaSubentryManager
     
     static 
     {
-        VALID_OU_VALUES.add( SchemaConstants.NORMALIZERS_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.COMPARATORS_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.SYNTAX_CHECKERS_AT.toLowerCase() );
-        VALID_OU_VALUES.add( "syntaxes".toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.MATCHING_RULES_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.MATCHING_RULE_USE_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.ATTRIBUTE_TYPES_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.OBJECT_CLASSES_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.NAME_FORMS_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.DIT_CONTENT_RULES_AT.toLowerCase() );
-        VALID_OU_VALUES.add( SchemaConstants.DIT_STRUCTURE_RULES_AT.toLowerCase() );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.NORMALIZERS_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.COMPARATORS_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.SYNTAX_CHECKERS_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( "syntaxes" ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.MATCHING_RULES_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.MATCHING_RULE_USE_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.ATTRIBUTE_TYPES_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.OBJECT_CLASSES_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.NAME_FORMS_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.DIT_CONTENT_RULES_AT ) );
+        VALID_OU_VALUES.add( Strings.toLowerCase( SchemaConstants.DIT_STRUCTURE_RULES_AT ) );
     }
 
 

Modified: directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Fri Sep  2 18:30:57 2011
@@ -245,13 +245,22 @@ public class SubentryInterceptor extends
 
                     subentryCache.addSubentry( subentryDn, newSubentry );
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
     }
 
@@ -371,11 +380,23 @@ public class SubentryInterceptor extends
                     nexus.modify( new ModifyOperationContext( session, candidateDn, modifications ) );
                 }
             }
+            subentries.close();
         }
         catch ( Exception e )
         {
             throw new LdapOtherException( e.getMessage(), e );
         }
+        finally
+        {
+            try
+            {
+                subentries.close();
+            }
+            catch ( Exception e )
+            {
+                LOG.error( I18n.err( I18n.ERR_168 ), e );
+            }
+        }
     }
 
 
@@ -1085,11 +1106,24 @@ public class SubentryInterceptor extends
                             getOperationalModsForRemove( dn, candidate ) ) );
                     }
                 }
+                
+                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationErrorException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
 
             // search for all selected entries by the new SS and add references to subentry
             subentry = subentryCache.getSubentry( dn );
@@ -1115,11 +1149,23 @@ public class SubentryInterceptor extends
                             getOperationalModsForAdd( candidate, operationalAttributes ) ) );
                     }
                 }
+                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationErrorException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
@@ -1228,13 +1274,22 @@ public class SubentryInterceptor extends
                             oldDn, newName, subentry, candidate ) ) );
                     }
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
@@ -1319,13 +1374,22 @@ public class SubentryInterceptor extends
                             oldDn, newName, subentry, candidate ) ) );
                     }
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
@@ -1400,13 +1464,22 @@ public class SubentryInterceptor extends
                             oldDn, newName, subentry, candidate ) ) );
                     }
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {

Modified: directory/apacheds/branches/one-sub-level-index-removal/core/src/test/java/org/apache/directory/server/core/authz/support/DummyOidRegistry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/core/src/test/java/org/apache/directory/server/core/authz/support/DummyOidRegistry.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/core/src/test/java/org/apache/directory/server/core/authz/support/DummyOidRegistry.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/core/src/test/java/org/apache/directory/server/core/authz/support/DummyOidRegistry.java Fri Sep  2 18:30:57 2011
@@ -27,6 +27,7 @@ import java.util.Map;
 
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.schema.registries.OidRegistry;
+import org.bouncycastle.util.Strings;
 
 
 /**
@@ -39,7 +40,7 @@ class DummyOidRegistry extends OidRegist
 {
     public String getOid( String name ) throws LdapException
     {
-        return name.toLowerCase();
+        return Strings.toLowerCase( name );
     }
 
 

Propchange: directory/apacheds/branches/one-sub-level-index-removal/http-integration/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -3,5 +3,5 @@
 /directory/apacheds/branches/apacheds-dnfactory-experiment/http-integration:980138-980935
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/http-integration:1040956-1043765
 /directory/apacheds/branches/milestones/http-integration:1072812-1075328
-/directory/apacheds/trunk/http-integration:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/http-integration:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/http-integration:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/i18n/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -3,5 +3,5 @@
 /directory/apacheds/branches/apacheds-dnfactory-experiment/i18n:980138-980935
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/i18n:1040956-1043765
 /directory/apacheds/branches/milestones/i18n:1072812-1075328
-/directory/apacheds/trunk/i18n:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/i18n:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/i18n:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/installers/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,6 +1,6 @@
 /directory/apacheds/branches/apacheds-config/installers:1023442-1029077
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/installers:1040956-1043765
 /directory/apacheds/branches/milestones/installers:1072812-1075328
-/directory/apacheds/trunk/installers:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/installers:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/installers/branches/installers-schema/apacheds:806631-896441
 /directory/studio/trunk/installers:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/installers-maven-plugin/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,6 +1,6 @@
 /directory/apacheds/branches/apacheds-config/installers-maven-plugin:1023442-1029077
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/installers-maven-plugin:1040956-1043765
 /directory/apacheds/branches/milestones/installers-maven-plugin:1072812-1075328
-/directory/apacheds/trunk/installers-maven-plugin:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/installers-maven-plugin:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/daemon/branches/daemon-schema/plugin:806630-896441
 /directory/studio/trunk/installers-maven-plugin:1067786-1067997

Modified: directory/apacheds/branches/one-sub-level-index-removal/installers-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/installers-maven-plugin/pom.xml?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/installers-maven-plugin/pom.xml (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/installers-maven-plugin/pom.xml Fri Sep  2 18:30:57 2011
@@ -24,7 +24,7 @@
   <parent>
     <groupId>org.apache.directory.server</groupId>
     <artifactId>apacheds-parent</artifactId>
-    <version>2.0.0-M2-SNAPSHOT</version>
+    <version>2.0.0-M3-SNAPSHOT</version>
   </parent>
   
   <artifactId>apacheds-installers-maven-plugin</artifactId>

Modified: directory/apacheds/branches/one-sub-level-index-removal/installers/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/installers/pom.xml?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/installers/pom.xml (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/installers/pom.xml Fri Sep  2 18:30:57 2011
@@ -22,7 +22,7 @@
   <parent>
     <groupId>org.apache.directory.server</groupId>
     <artifactId>apacheds-parent</artifactId>
-    <version>2.0.0-M2-SNAPSHOT</version>
+    <version>2.0.0-M3-SNAPSHOT</version>
   </parent>
   
   <artifactId>apacheds-installers</artifactId>

Propchange: directory/apacheds/branches/one-sub-level-index-removal/interceptor-kerberos/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -3,5 +3,5 @@
 /directory/apacheds/branches/apacheds-dnfactory-experiment/interceptor-kerberos:980138-980935
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/interceptor-kerberos:1040956-1043765
 /directory/apacheds/branches/milestones/interceptor-kerberos:1072812-1075328
-/directory/apacheds/trunk/interceptor-kerberos:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/interceptor-kerberos:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/interceptor-kerberos:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/jdbm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,7 +1,8 @@
 /directory/apacheds/branches/apacheds-codec-merge/jdbm:982369-987590
 /directory/apacheds/branches/apacheds-config/jdbm:1023442-1029077
 /directory/apacheds/branches/apacheds-dnfactory-experiment/jdbm:980138-980935
+/directory/apacheds/branches/apacheds-jdbm/jdbm:1160768-1164076
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/jdbm:1040956-1043765
 /directory/apacheds/branches/milestones/jdbm:1072812-1075328
-/directory/apacheds/trunk/jdbm:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/jdbm:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/jdbm:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,7 +1,8 @@
 /directory/apacheds/branches/apacheds-codec-merge/jdbm-partition:982369-987590
 /directory/apacheds/branches/apacheds-config/jdbm-partition:1023442-1029077
 /directory/apacheds/branches/apacheds-dnfactory-experiment/jdbm-partition:980138-980935
+/directory/apacheds/branches/apacheds-jdbm/jdbm-partition:1160768-1164080
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/jdbm-partition:1040956-1043765
 /directory/apacheds/branches/milestones/jdbm-partition:1072812-1075328
-/directory/apacheds/trunk/jdbm-partition:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/jdbm-partition:1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/jdbm-partition:1067786-1067997

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java Fri Sep  2 18:30:57 2011
@@ -106,7 +106,7 @@ public class DupsContainerCursor<K,V> ex
     public void beforeKey( K key ) throws Exception
     {
         checkNotClosed( "beforeKey()" );
-        
+        this.closeBrowser( browser );
         browser = ((BTree<K,V>)table.getBTree()).browse( key );
         forwardDirection = null;
         clearValue();
@@ -121,6 +121,7 @@ public class DupsContainerCursor<K,V> ex
     {
         checkNotClosed( "afterKey()" );
 
+        this.closeBrowser( browser );
         browser = ((BTree<K,V>)table.getBTree()).browse( key );
         forwardDirection = null;
 
@@ -203,7 +204,7 @@ public class DupsContainerCursor<K,V> ex
     public void beforeFirst() throws Exception
     {
         checkNotClosed( "beforeFirst()" );
-        
+        this.closeBrowser( browser );
         browser = table.getBTree().browse();
         forwardDirection = null;
         clearValue();
@@ -217,7 +218,7 @@ public class DupsContainerCursor<K,V> ex
     public void afterLast() throws Exception
     {
         checkNotClosed( "afterLast()" );
-        
+        this.closeBrowser( browser );
         browser = table.getBTree().browse( null );
         forwardDirection = null;
         clearValue();
@@ -367,4 +368,33 @@ public class DupsContainerCursor<K,V> ex
 
         throw new InvalidCursorPositionException();
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws Exception
+    {
+        super.close();
+        this.closeBrowser( browser );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        super.close( cause );
+        this.closeBrowser( browser );
+    }
+    
+    private void closeBrowser(TupleBrowser browser)
+    {
+        if ( browser != null )
+        {
+            browser.close();
+        }
+    }
 }

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java Fri Sep  2 18:30:57 2011
@@ -456,4 +456,26 @@ class DupsCursor<K,V> extends AbstractTu
 
         return returnedTuple;
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws Exception
+    {
+        super.close();
+        containerCursor.close();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        super.close( cause );
+        containerCursor.close( cause );
+    }
 }

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java Fri Sep  2 18:30:57 2011
@@ -26,9 +26,8 @@ import java.io.IOException;
 import java.net.URI;
 
 import jdbm.RecordManager;
-import jdbm.helper.MRU;
 import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
+import jdbm.recman.SnapshotRecordManager;
 
 import org.apache.directory.server.core.partition.impl.btree.IndexCursorAdaptor;
 import org.apache.directory.server.core.partition.impl.btree.LongComparator;
@@ -176,7 +175,7 @@ public class JdbmIndex<K, O> extends Abs
 
         BaseRecordManager base = new BaseRecordManager( path );
         base.disableTransactions();
-        this.recMan = new CacheRecordManager( base, new MRU( DEFAULT_INDEX_CACHE_SIZE ) );
+        this.recMan = new SnapshotRecordManager( base, DEFAULT_INDEX_CACHE_SIZE );
 
         try
         {

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java Fri Sep  2 18:30:57 2011
@@ -27,9 +27,8 @@ import java.util.Arrays;
 import java.util.List;
 
 import jdbm.RecordManager;
-import jdbm.helper.MRU;
 import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
+import jdbm.recman.SnapshotRecordManager;
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.partition.Partition;
@@ -141,7 +140,7 @@ public class JdbmPartition extends Abstr
             }
     
             // Now, create the entry cache for this partition
-            recMan = new CacheRecordManager( baseRecordManager, new MRU( cacheSize ) );
+            recMan = new SnapshotRecordManager( baseRecordManager, cacheSize );
     
             // Create the master table (the table containing all the entries)
             master = new JdbmMasterTable<Entry>( recMan, schemaManager );

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java Fri Sep  2 18:30:57 2011
@@ -27,9 +27,8 @@ import java.io.IOException;
 
 import javax.naming.NamingException;
 
-import jdbm.helper.MRU;
 import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
+import jdbm.recman.SnapshotRecordManager;
 
 import org.apache.directory.server.core.partition.impl.btree.LongComparator;
 import org.apache.directory.server.i18n.I18n;
@@ -95,7 +94,7 @@ public class JdbmRdnIndex<E> extends Jdb
         //System.out.println( "IDX Created index " + path );
         BaseRecordManager base = new BaseRecordManager( path );
         base.disableTransactions();
-        this.recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
+        this.recMan = new SnapshotRecordManager( base, cacheSize );
 
         try
         {

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java Fri Sep  2 18:30:57 2011
@@ -312,7 +312,7 @@ public class JdbmTable<K,V> extends Abst
         if ( ! allowsDuplicates )
         {
             return ( V ) bt.find( key );
-        }                         
+        }
 
         
         DupsContainer<V> values = getDupsContainer( ( byte[] ) bt.find( key ) );
@@ -332,7 +332,9 @@ public class JdbmTable<K,V> extends Abst
         BTree tree = getBTree( values.getBTreeRedirect() );
 
         jdbm.helper.Tuple tuple = new jdbm.helper.Tuple();
-        tree.browse().getNext( tuple );
+        TupleBrowser<K,V> browser = tree.browse();
+        browser.getNext( tuple );
+        this.closeBrowser( browser );
         //noinspection unchecked
         
         return ( V ) tuple.getKey();
@@ -468,8 +470,11 @@ public class JdbmTable<K,V> extends Abst
             
             if ( browser.getPrevious( tuple ) )
             {
+                this.closeBrowser( browser );
                 return true;
             }
+            
+            this.closeBrowser( browser );
         }
 
         return false;
@@ -563,6 +568,7 @@ public class JdbmTable<K,V> extends Abst
                 {
                     return;
                 }
+                
                 if ( set.size() > numDupLimit )
                 {
                     BTree tree = convertToBTree( set );
@@ -629,6 +635,7 @@ public class JdbmTable<K,V> extends Abst
                 {
                     LOG.debug( "<--- Remove NULL key " + name );
                 }
+                
                 return;
             }
     
@@ -670,6 +677,7 @@ public class JdbmTable<K,V> extends Abst
                     {
                         bt.insert( key, (V)marshaller.serialize( set ), true );
                     }
+                    
                     count--;
 
                     if ( LOG.isDebugEnabled() )
@@ -771,6 +779,7 @@ public class JdbmTable<K,V> extends Abst
 
                 recMan.delete( tree.getRecordId() );
                 duplicateBtrees.remove( tree.getRecordId() );
+                
                 return;
             }
             else
@@ -838,6 +847,7 @@ public class JdbmTable<K,V> extends Abst
         }
 
         ArrayTree<V> set = marshaller.deserialize( serialized );
+        
         return new KeyTupleArrayCursor<K,V>( set, key );
     }
 
@@ -863,6 +873,7 @@ public class JdbmTable<K,V> extends Abst
         }
 
         byte[] serialized = ( byte[] ) raw;
+        
         if ( BTreeRedirectMarshaller.isRedirect( serialized ) )
         {
             BTree tree = getBTree( BTreeRedirectMarshaller.INSTANCE.deserialize( serialized ) );
@@ -927,6 +938,7 @@ public class JdbmTable<K,V> extends Abst
         }                         
 
         DupsContainer<V> values = getDupsContainer( ( byte[] ) bt.find( key ) );
+        
         if ( values.isBTreeRedirect() )
         {
             return true;
@@ -973,6 +985,7 @@ public class JdbmTable<K,V> extends Abst
         BTree<K, V> tree = new BTree<K, V>().load( recMan, redirect.getRecId() );
         ((SerializableComparator<K>)tree.getComparator()).setSchemaManager( schemaManager );
         duplicateBtrees.put( redirect.getRecId(), tree );
+        
         return tree;
     }
 
@@ -983,34 +996,43 @@ public class JdbmTable<K,V> extends Abst
         jdbm.helper.Tuple tuple = new jdbm.helper.Tuple();
         
         TupleBrowser browser = tree.browse( key );
-        if ( isGreaterThan )
-        {
-            return browser.getNext( tuple );
-        }
-        else
+        
+        try
         {
-            if ( browser.getPrevious( tuple ) )
-            {
-                return true;
+            if ( isGreaterThan )
+            { 
+                return browser.getNext( tuple );
             }
             else
             {
-                /*
-                 * getPrevious() above fails which means the browser has is
-                 * before the first Tuple of the btree.  A call to getNext()
-                 * should work every time.
-                 */
-                browser.getNext( tuple );
-
-                /*
-                 * Since the browser is positioned now on the Tuple with the
-                 * smallest key we just need to check if it equals this key
-                 * which is the only chance for returning true.
-                 */
-                V firstKey = ( V ) tuple.getKey();
-                return valueComparator.compare( key, firstKey ) == 0;
+                if ( browser.getPrevious( tuple ) )
+                {
+                    return true;
+                }
+                else
+                {
+                    /*
+                     * getPrevious() above fails which means the browser has is
+                     * before the first Tuple of the btree.  A call to getNext()
+                     * should work every time.
+                     */
+                    browser.getNext( tuple );
+    
+                    /*
+                     * Since the browser is positioned now on the Tuple with the
+                     * smallest key we just need to check if it equals this key
+                     * which is the only chance for returning true.
+                     */
+                    V firstKey = ( V ) tuple.getKey();
+                    
+                    return valueComparator.compare( key, firstKey ) == 0;
+                }
             }
         }
+        finally
+        {
+            this.closeBrowser( browser );
+        }
     }
 
 
@@ -1026,6 +1048,8 @@ public class JdbmTable<K,V> extends Abst
             avlTree.insert( ( V ) tuple.getKey() );
         }
 
+        this.closeBrowser( browser );
+        
         return avlTree;
     }
     
@@ -1053,4 +1077,12 @@ public class JdbmTable<K,V> extends Abst
         
         return bTree;
     }
+    
+    private void closeBrowser(TupleBrowser<K,V> browser)
+    {
+        if ( browser != null )
+        {
+            browser.close();
+        }
+    }
 }

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java Fri Sep  2 18:30:57 2011
@@ -76,6 +76,7 @@ public class KeyBTreeCursor<E> extends A
     public void before( E element ) throws Exception
     {
         checkNotClosed( "before()" );
+        this.closeBrowser( browser );
         browser = btree.browse( element );
         clearValue();
     }
@@ -84,6 +85,7 @@ public class KeyBTreeCursor<E> extends A
     @SuppressWarnings("unchecked")
     public void after( E element ) throws Exception
     {
+        this.closeBrowser( browser );
         browser = btree.browse( element );
 
         /*
@@ -125,6 +127,7 @@ public class KeyBTreeCursor<E> extends A
     public void beforeFirst() throws Exception
     {
         checkNotClosed( "beforeFirst()" );
+        this.closeBrowser( browser );
         browser = btree.browse();
         clearValue();
     }
@@ -133,6 +136,7 @@ public class KeyBTreeCursor<E> extends A
     public void afterLast() throws Exception
     {
         checkNotClosed( "afterLast()" );
+        this.closeBrowser( browser );
         browser = btree.browse( null );
     }
 
@@ -154,6 +158,7 @@ public class KeyBTreeCursor<E> extends A
     public boolean previous() throws Exception
     {
         checkNotClosed( "previous()" );
+        
         if ( browser == null )
         {
             browser = btree.browse( null );
@@ -174,6 +179,7 @@ public class KeyBTreeCursor<E> extends A
     public boolean next() throws Exception
     {
         checkNotClosed( "next()" );
+        
         if ( browser == null )
         {
             browser = btree.browse();
@@ -186,6 +192,7 @@ public class KeyBTreeCursor<E> extends A
         else
         {
             clearValue();
+            
             return false;
         }
     }
@@ -195,6 +202,7 @@ public class KeyBTreeCursor<E> extends A
     public E get() throws Exception
     {
         checkNotClosed( "get()" );
+        
         if ( valueAvailable )
         {
             return ( E ) tuple.getKey();
@@ -202,4 +210,34 @@ public class KeyBTreeCursor<E> extends A
 
         throw new InvalidCursorPositionException();
     }
+ 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws Exception
+    {
+        super.close();
+        this.closeBrowser( browser );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        super.close( cause );
+        this.closeBrowser( browser );
+    }
+    
+    
+    private void closeBrowser(TupleBrowser browser)
+    {
+        if ( browser != null )
+        {
+            browser.close();
+        }
+    }
 }

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java Fri Sep  2 18:30:57 2011
@@ -108,7 +108,7 @@ public class KeyTupleBTreeCursor<K,V> ex
         {
             throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
         }
-
+        this.closeBrowser( browser );
         browser = btree.browse( value );
         clearValue();
     }
@@ -125,6 +125,7 @@ public class KeyTupleBTreeCursor<K,V> ex
             throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
         }
 
+        this.closeBrowser( browser );
         browser = btree.browse( value );
 
         /*
@@ -152,6 +153,7 @@ public class KeyTupleBTreeCursor<K,V> ex
                  */
                 if ( !browser.getPrevious( valueTuple ) )
                 {
+                    this.closeBrowser( browser );
                     browser = btree.browse( this.key );
                 }
 
@@ -176,6 +178,7 @@ public class KeyTupleBTreeCursor<K,V> ex
     public void before( Tuple<K,V> element ) throws Exception
     {
         checkNotClosed( "before()" );
+        this.closeBrowser( browser );
         browser = btree.browse( element.getValue() );
         clearValue();
     }
@@ -196,6 +199,7 @@ public class KeyTupleBTreeCursor<K,V> ex
     public void beforeFirst() throws Exception
     {
         checkNotClosed( "beforeFirst()" );
+        this.closeBrowser( browser );
         browser = btree.browse();
         clearValue();
     }
@@ -207,6 +211,7 @@ public class KeyTupleBTreeCursor<K,V> ex
     public void afterLast() throws Exception
     {
         checkNotClosed( "afterLast()" );
+        this.closeBrowser( browser );
         browser = btree.browse( null );
     }
 
@@ -308,4 +313,34 @@ public class KeyTupleBTreeCursor<K,V> ex
 
         throw new InvalidCursorPositionException();
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws Exception
+    {
+        super.close();
+        this.closeBrowser( browser );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        super.close( cause );
+        this.closeBrowser( browser );
+    }
+
+    
+    private void closeBrowser(TupleBrowser browser)
+    {
+        if ( browser != null )
+        {
+            browser.close();
+        }
+    }
 }

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java Fri Sep  2 18:30:57 2011
@@ -78,6 +78,7 @@ class NoDupsCursor<K,V> extends Abstract
     public void beforeKey( K key ) throws Exception
     {
         checkNotClosed( "beforeKey()" );
+        this.closeBrowser( browser );
         browser = table.getBTree().browse( key );
         clearValue();
     }
@@ -86,6 +87,7 @@ class NoDupsCursor<K,V> extends Abstract
     @SuppressWarnings("unchecked")
     public void afterKey( K key ) throws Exception
     {
+        this.closeBrowser( browser );
         browser = table.getBTree().browse( key );
 
         /*
@@ -147,6 +149,7 @@ class NoDupsCursor<K,V> extends Abstract
     public void beforeFirst() throws Exception
     {
         checkNotClosed( "beforeFirst()" );
+        this.closeBrowser( browser );
         browser = table.getBTree().browse();
         clearValue();
     }
@@ -155,6 +158,7 @@ class NoDupsCursor<K,V> extends Abstract
     public void afterLast() throws Exception
     {
         checkNotClosed( "afterLast()" );
+        this.closeBrowser( browser );
         browser = table.getBTree().browse( null );
         clearValue();
     }
@@ -242,4 +246,33 @@ class NoDupsCursor<K,V> extends Abstract
 
         throw new InvalidCursorPositionException();
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws Exception
+    {
+        super.close();
+        this.closeBrowser( browser );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        super.close( cause );
+        this.closeBrowser( browser );
+    }
+    
+    private void closeBrowser(TupleBrowser browser)
+    {
+        if ( browser != null )
+        {
+            browser.close();
+        }
+    }
 }

Propchange: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,11 +1,12 @@
 /directory/apacheds/branches/apacheds-codec-merge/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:982369-987590
 /directory/apacheds/branches/apacheds-config/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:1023442-1029077
 /directory/apacheds/branches/apacheds-dnfactory-experiment/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:980138-980935
+/directory/apacheds/branches/apacheds-jdbm/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:1160768-1164080
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:1040956-1043765
 /directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:749790-764110
 /directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:806623-810034
 /directory/apacheds/branches/apacheds-subtree/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:965203-965686
 /directory/apacheds/branches/milestones/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:1072812-1075328
 /directory/apacheds/branches/xdbm-refactoring/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:945827-946347
-/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:498338-580500,806623-894866*,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:498338-580500,806623-894866*,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,11 +1,12 @@
 /directory/apacheds/branches/apacheds-codec-merge/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:982369-987590
 /directory/apacheds/branches/apacheds-config/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:1023442-1029077
 /directory/apacheds/branches/apacheds-dnfactory-experiment/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:980138-980935
+/directory/apacheds/branches/apacheds-jdbm/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:1160768-1164080
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:1040956-1043765
 /directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:749790-764110
 /directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:809853-810034
 /directory/apacheds/branches/apacheds-subtree/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:965203-965686
 /directory/apacheds/branches/milestones/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:1072812-1075328
 /directory/apacheds/branches/xdbm-refactoring/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:945827-946347
-/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:498338-580500,806623-894866,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:498338-580500,806623-894866,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,11 +1,12 @@
 /directory/apacheds/branches/apacheds-codec-merge/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:982369-987590
 /directory/apacheds/branches/apacheds-config/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:1023442-1029077
 /directory/apacheds/branches/apacheds-dnfactory-experiment/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:980138-980935
+/directory/apacheds/branches/apacheds-jdbm/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:1160768-1164080
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:1040956-1043765
 /directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:749790-764110
 /directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:806623-810034
 /directory/apacheds/branches/apacheds-subtree/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:965203-965686
 /directory/apacheds/branches/milestones/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:1072812-1075328
 /directory/apacheds/branches/xdbm-refactoring/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:945827-946347
-/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:498338-580500,806623-894866*,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:498338-580500,806623-894866*,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema:1067786-1067997

Propchange: directory/apacheds/branches/one-sub-level-index-removal/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  2 18:30:57 2011
@@ -1,11 +1,12 @@
 /directory/apacheds/branches/apacheds-codec-merge/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:982369-987590
 /directory/apacheds/branches/apacheds-config/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:1023442-1029077
 /directory/apacheds/branches/apacheds-dnfactory-experiment/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:980138-980935
+/directory/apacheds/branches/apacheds-jdbm/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:1160768-1164080
 /directory/apacheds/branches/apacheds-kerberos-codec-2.0/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:1040956-1043765
 /directory/apacheds/branches/apacheds-replication/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:749790-764110
 /directory/apacheds/branches/apacheds-schema/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:806623-810034
 /directory/apacheds/branches/apacheds-subtree/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:965203-965686
 /directory/apacheds/branches/milestones/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:1072812-1075328
 /directory/apacheds/branches/xdbm-refactoring/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:945827-946347
-/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:498338-580500,806623-894866,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1161268
+/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:498338-580500,806623-894866,1066126-1067785,1068026-1072718,1072800-1075329,1158399-1164660
 /directory/studio/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java:1067786-1067997

Modified: directory/apacheds/branches/one-sub-level-index-removal/jdbm/src/main/java/jdbm/btree/BPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/jdbm/src/main/java/jdbm/btree/BPage.java?rev=1164667&r1=1164666&r2=1164667&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/jdbm/src/main/java/jdbm/btree/BPage.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/jdbm/src/main/java/jdbm/btree/BPage.java Fri Sep  2 18:30:57 2011
@@ -47,17 +47,19 @@
 package jdbm.btree;
 
 
-import jdbm.helper.Serializer;
-import jdbm.helper.Tuple;
-import jdbm.helper.TupleBrowser;
-
-import java.io.IOException;
-import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.ObjectInput;
-import java.io.ObjectOutput;
 import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import jdbm.helper.ActionContext;
+import jdbm.helper.Serializer;
+import jdbm.helper.Tuple;
+import jdbm.helper.TupleBrowser;
 
 import org.apache.directory.server.i18n.I18n;
 
@@ -80,7 +82,7 @@ import org.apache.directory.server.i18n.
  * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
  */
 public class BPage<K, V> implements Serializer
-{
+{ 
     private static final boolean DEBUG = false;
 
     /** Version id for serialization. */
@@ -112,6 +114,8 @@ public class BPage<K, V> implements Seri
 
     /** Next leaf BPage (only if this BPage is a leaf) */
     protected long next;
+    
+    public static AtomicInteger outstandingBrowsers = new AtomicInteger(0);
 
 
     /**
@@ -127,7 +131,7 @@ public class BPage<K, V> implements Seri
      * Root page overflow constructor
      */
     @SuppressWarnings("unchecked")
-    BPage( BTree btree, BPage<K, V> root, BPage<K, V> overflow ) throws IOException
+    BPage( BTree<K, V> btree, BPage<K, V> root, BPage<K, V> overflow ) throws IOException
     {
         this.btree = btree;
 
@@ -151,7 +155,7 @@ public class BPage<K, V> implements Seri
      * Root page (first insert) constructor.
      */
     @SuppressWarnings("unchecked") // Cannot create an array of generic objects
-    BPage( BTree btree, K key, V value ) throws IOException
+    BPage( BTree<K,V> btree, K key, V value ) throws IOException
     {
         this.btree = btree;
 
@@ -164,7 +168,7 @@ public class BPage<K, V> implements Seri
         keys[btree.pageSize - 1] = null; // I am the root BPage for now
 
         values = (V[])new Object[btree.pageSize];
-        values[btree.pageSize - 2] = value;
+        values[btree.pageSize - 2] = btree.copyValue( value );
         values[btree.pageSize - 1] = null; // I am the root BPage for now
 
         recordId = btree.recordManager.insert( this, this );
@@ -197,6 +201,33 @@ public class BPage<K, V> implements Seri
 
         recordId = btree.recordManager.insert( this, this );
     }
+    
+    @SuppressWarnings("unchecked") // Cannot create an array of generic objects
+    BPage<K,V> copyOnWrite()
+    {
+        BPage<K, V> newPage = new BPage<K,V>();
+        
+        newPage.btree = this.btree;
+        newPage.isLeaf = this.isLeaf;
+        
+        newPage.first = this.first;
+        newPage.previous = this.previous;
+        newPage.next = this.next;
+        
+        newPage.keys = (K[])new Object[btree.pageSize];
+        newPage.values = (V[])new Object[btree.pageSize];
+        newPage.children = new long[btree.pageSize];
+        
+        newPage.recordId = this.recordId;
+        
+        if ( this.children != null )
+            this.copyChildren( this, 0, newPage, 0, btree.pageSize ); // this copies keys as well
+        
+        if (this.values != null ) 
+            this.copyEntries( this, 0, newPage, 0, btree.pageSize ); // this copies keys as well
+        
+        return newPage;
+    }
 
 
     /**
@@ -259,10 +290,11 @@ public class BPage<K, V> implements Seri
      *
      * @param height Height of the current BPage (zero is leaf page)
      * @param key The key
+     * @param context action context in case of action capable record manager
      * @return TupleBrowser positionned just before the given key, or before
      *                      next greater key if key isn't found.
      */
-    TupleBrowser<K, V> find( int height, K key ) throws IOException
+    TupleBrowser<K, V> find( int height, K key, ActionContext context) throws IOException
     {
         int index = this.findChildren( key );
         
@@ -285,26 +317,26 @@ public class BPage<K, V> implements Seri
             }
         }
 
-        return new Browser( child, index );
+        return new Browser( child, index, context);
     }
 
 
     /**
      * Find first entry and return a browser positioned before it.
-     *
+     *@param context Action Context in case of 
      * @return TupleBrowser positionned just before the first entry.
      */
-    TupleBrowser<K, V> findFirst() throws IOException
+    TupleBrowser<K, V> findFirst( ActionContext context ) throws IOException
     {
         if ( isLeaf )
         {
-            return new Browser( this, first );
+            return new Browser( this, first, context );
         }
         else
         {
             BPage<K, V> child = childBPage( first );
             
-            return child.findFirst();
+            return child.findFirst( context );
         }
     }
 
@@ -337,9 +369,13 @@ public class BPage<K, V> implements Seri
 
         height -= 1;
         
+        BPage<K,V> pageNewCopy = null;
+        
         if ( height == 0 )
         {
+            pageNewCopy = btree.copyOnWrite( this );
             result = new InsertResult<K, V>();
+            result.pageNewCopy = pageNewCopy;
 
             // inserting on a leaf BPage
             overflow = -1;
@@ -365,8 +401,8 @@ public class BPage<K, V> implements Seri
                 
                 if ( replace )
                 {
-                    values[index] = value;
-                    btree.recordManager.update( recordId, this, this );
+                    pageNewCopy.values[index] = value;
+                    btree.recordManager.update( recordId, pageNewCopy, this );
                 }
                 
                 // return the existing key
@@ -378,6 +414,12 @@ public class BPage<K, V> implements Seri
             // non-leaf BPage
             BPage<K, V> child = childBPage( index );
             result = child.insert( height, key, value, replace );
+            
+            if( result.pageNewCopy != null)
+            {
+                child = result.pageNewCopy;
+                result.pageNewCopy = null;
+            }
 
             if ( result.existing != null )
             {
@@ -393,6 +435,9 @@ public class BPage<K, V> implements Seri
 
             // there was an overflow, we need to insert the overflow page
             // on this BPage
+            pageNewCopy = btree.copyOnWrite( this );
+            result.pageNewCopy = pageNewCopy;
+            
             if ( DEBUG )
             {
                 System.out.println( "BPage.insert() Overflow page: " + result.overflow.recordId );
@@ -402,7 +447,7 @@ public class BPage<K, V> implements Seri
             overflow = result.overflow.recordId;
 
             // update child's largest key
-            keys[index] = child.getLargestKey();
+            pageNewCopy.keys[index] = child.getLargestKey();
 
             // clean result so we can reuse it
             result.overflow = null;
@@ -410,24 +455,25 @@ public class BPage<K, V> implements Seri
 
         // if we get here, we need to insert a new entry on the BPage
         // before children[ index ]
-        if ( !isFull() )
-        {
+        if ( !pageNewCopy.isFull() )
+        {            
             if ( height == 0 )
             {
-                insertEntry( this, index - 1, key, value );
+                insertEntry( pageNewCopy, index - 1, key, value );
             }
             else
             {
-                insertChild( this, index - 1, key, overflow );
+                insertChild( pageNewCopy, index - 1, key, overflow );
             }
             
-            btree.recordManager.update( recordId, this, this );
+            btree.recordManager.update( recordId, pageNewCopy, this );
+            
             return result;
         }
 
         // page is full, we must divide the page
         int half = btree.pageSize >> 1;
-        BPage<K, V> newPage = new BPage<K, V>( btree, isLeaf );
+        BPage<K, V> newPage = new BPage<K, V>( btree, pageNewCopy.isLeaf );
         
         if ( index < half )
         {
@@ -441,15 +487,15 @@ public class BPage<K, V> implements Seri
             
             if ( height == 0 )
             {
-                copyEntries( this, 0, newPage, half, index );
+                copyEntries( pageNewCopy, 0, newPage, half, index );
                 setEntry( newPage, half + index, key, value );
-                copyEntries( this, index, newPage, half + index + 1, half - index - 1 );
+                copyEntries( pageNewCopy, index, newPage, half + index + 1, half - index - 1 );
             }
             else
             {
-                copyChildren( this, 0, newPage, half, index );
+                copyChildren( pageNewCopy, 0, newPage, half, index );
                 setChild( newPage, half + index, key, overflow );
-                copyChildren( this, index, newPage, half + index + 1, half - index - 1 );
+                copyChildren( pageNewCopy, index, newPage, half + index + 1, half - index - 1 );
             }
         }
         else
@@ -463,50 +509,51 @@ public class BPage<K, V> implements Seri
             
             if ( height == 0 )
             {
-                copyEntries( this, 0, newPage, half, half );
-                copyEntries( this, half, this, half - 1, index - half );
-                setEntry( this, index - 1, key, value );
+                copyEntries( pageNewCopy, 0, newPage, half, half );
+                copyEntries( pageNewCopy, half, pageNewCopy, half - 1, index - half );
+                setEntry( pageNewCopy, index - 1, key, value );
             }
             else
             {
-                copyChildren( this, 0, newPage, half, half );
-                copyChildren( this, half, this, half - 1, index - half );
-                setChild( this, index - 1, key, overflow );
+                copyChildren( pageNewCopy, 0, newPage, half, half );
+                copyChildren( pageNewCopy, half, pageNewCopy, half - 1, index - half );
+                setChild( pageNewCopy, index - 1, key, overflow );
             }
         }
 
-        first = half - 1;
+        pageNewCopy.first = half - 1;
 
         // nullify lower half of entries
-        for ( int i = 0; i < first; i++ )
+        for ( int i = 0; i < pageNewCopy.first; i++ )
         {
             if ( height == 0 )
             {
-                setEntry( this, i, null, null );
+                setEntry( pageNewCopy, i, null, null );
             }
             else
             {
-                setChild( this, i, null, -1 );
+                setChild( pageNewCopy, i, null, -1 );
             }
         }
 
-        if ( isLeaf )
+        if ( pageNewCopy.isLeaf )
         {
             // link newly created BPage
-            newPage.previous = previous;
-            newPage.next = recordId;
+            newPage.previous = pageNewCopy.previous;
+            newPage.next = pageNewCopy.recordId;
             
-            if ( previous != 0 )
+            if ( pageNewCopy.previous != 0 )
             {
-                BPage<K, V> previousBPage = loadBPage( previous );
+                BPage<K, V> previousBPage = loadBPage( pageNewCopy.previous );
+                previousBPage = btree.copyOnWrite( previousBPage );
                 previousBPage.next = newPage.recordId;
-                btree.recordManager.update( previous, previousBPage, this );
+                btree.recordManager.update( pageNewCopy.previous, previousBPage, this );
             }
             
-            previous = newPage.recordId;
+            pageNewCopy.previous = newPage.recordId;
         }
 
-        btree.recordManager.update( recordId, this, this );
+        btree.recordManager.update( recordId, pageNewCopy, this );
         btree.recordManager.update( newPage.recordId, newPage, this );
 
         result.overflow = newPage;
@@ -521,9 +568,9 @@ public class BPage<K, V> implements Seri
      * @param key Removal key
      * @return Remove result object
      */
-    RemoveResult<V> remove( int height, K key ) throws IOException
+    RemoveResult<K, V> remove( int height, K key ) throws IOException
     {
-        RemoveResult<V> result;
+        RemoveResult<K, V> result;
 
         int half = btree.pageSize / 2;
         int index = findChildren( key );
@@ -536,6 +583,8 @@ public class BPage<K, V> implements Seri
 
         height -= 1;
         
+        BPage<K,V> pageNewCopy = btree.copyOnWrite( this );
+        
         if ( height == 0 )
         {
             // remove leaf entry
@@ -544,22 +593,32 @@ public class BPage<K, V> implements Seri
                 throw new IllegalArgumentException( I18n.err( I18n.ERR_514, key ) );
             }
             
-            result = new RemoveResult<V>();
-            result.value = values[index];
-            removeEntry( this, index );
+            result = new RemoveResult<K, V>();
+            result.value = pageNewCopy.values[index];
+            removeEntry( pageNewCopy, index );
 
             // update this BPage
-            btree.recordManager.update( recordId, this, this );
+            btree.recordManager.update( recordId, pageNewCopy, this );
         }
         else
         {
             // recurse into Btree to remove entry on a children page
             BPage<K, V> child = childBPage( index );
             result = child.remove( height, key );
+            
+            if ( result.pageNewCopy != null )
+            {
+                child = result.pageNewCopy;
+                result.pageNewCopy = null;
+            }
+            else
+            {
+                child = btree.copyOnWrite( child );
+            }
 
             // update children
-            keys[index] = child.getLargestKey();
-            btree.recordManager.update( recordId, this, this );
+            pageNewCopy.keys[index] = child.getLargestKey();
+            btree.recordManager.update( recordId, pageNewCopy, this );
 
             if ( result.underflow )
             {
@@ -569,10 +628,11 @@ public class BPage<K, V> implements Seri
                     throw new IllegalStateException( I18n.err( I18n.ERR_513, "1" ) );
                 }
                 
-                if ( index < children.length - 1 )
+                if ( index < pageNewCopy.children.length - 1 )
                 {
                     // exists greater brother page
-                    BPage<K, V> brother = childBPage( index + 1 );
+                    BPage<K, V> brother = pageNewCopy.childBPage( index + 1 );
+                    brother = btree.copyOnWrite( brother );
                     int bfirst = brother.first;
                     
                     if ( bfirst < half )
@@ -606,12 +666,12 @@ public class BPage<K, V> implements Seri
                         }
 
                         // update child's largest key
-                        keys[index] = child.getLargestKey();
+                        pageNewCopy.keys[index] = child.getLargestKey();
 
                         // no change in previous/next BPage
 
                         // update BPages
-                        btree.recordManager.update( recordId, this, this );
+                        btree.recordManager.update( recordId, pageNewCopy, this );
                         btree.recordManager.update( brother.recordId, brother, this );
                         btree.recordManager.update( child.recordId, child, this );
 
@@ -638,24 +698,25 @@ public class BPage<K, V> implements Seri
                         btree.recordManager.update( brother.recordId, brother, this );
 
                         // remove "child" from current BPage
-                        if ( isLeaf )
+                        if ( pageNewCopy.isLeaf )
                         {
-                            copyEntries( this, first, this, first + 1, index - first );
-                            setEntry( this, first, null, null );
+                            copyEntries( pageNewCopy, pageNewCopy.first, pageNewCopy, pageNewCopy.first + 1, index - pageNewCopy.first );
+                            setEntry( pageNewCopy, pageNewCopy.first, null, null );
                         }
                         else
                         {
-                            copyChildren( this, first, this, first + 1, index - first );
-                            setChild( this, first, null, -1 );
+                            copyChildren( pageNewCopy, pageNewCopy.first, pageNewCopy, pageNewCopy.first + 1, index - pageNewCopy.first );
+                            setChild( pageNewCopy, pageNewCopy.first, null, -1 );
                         }
                         
-                        first += 1;
-                        btree.recordManager.update( recordId, this, this );
+                        pageNewCopy.first += 1;
+                        btree.recordManager.update( recordId, pageNewCopy, this );
 
                         // re-link previous and next BPages
                         if ( child.previous != 0 )
                         {
                             BPage<K, V> prev = loadBPage( child.previous );
+                            prev = btree.copyOnWrite( prev );
                             prev.next = child.next;
                             btree.recordManager.update( prev.recordId, prev, this );
                         }
@@ -663,6 +724,7 @@ public class BPage<K, V> implements Seri
                         if ( child.next != 0 )
                         {
                             BPage<K, V> next = loadBPage( child.next );
+                            next = btree.copyOnWrite( next );
                             next.previous = child.previous;
                             btree.recordManager.update( next.recordId, next, this );
                         }
@@ -674,7 +736,8 @@ public class BPage<K, V> implements Seri
                 else
                 {
                     // page "brother" is before "child"
-                    BPage<K, V> brother = childBPage( index - 1 );
+                    BPage<K, V> brother = pageNewCopy.childBPage( index - 1 );
+                    brother = btree.copyOnWrite( brother );
                     int bfirst = brother.first;
                     
                     if ( bfirst < half )
@@ -708,12 +771,12 @@ public class BPage<K, V> implements Seri
                         }
 
                         // update brother's largest key
-                        keys[index - 1] = brother.getLargestKey();
+                        pageNewCopy.keys[index - 1] = brother.getLargestKey();
 
                         // no change in previous/next BPage
 
                         // update BPages
-                        btree.recordManager.update( recordId, this, this );
+                        btree.recordManager.update( recordId, pageNewCopy, this );
                         btree.recordManager.update( brother.recordId, brother, this );
                         btree.recordManager.update( child.recordId, child, this );
 
@@ -740,24 +803,25 @@ public class BPage<K, V> implements Seri
                         btree.recordManager.update( child.recordId, child, this );
 
                         // remove "brother" from current BPage
-                        if ( isLeaf )
+                        if ( pageNewCopy.isLeaf )
                         {
-                            copyEntries( this, first, this, first + 1, index - 1 - first );
-                            setEntry( this, first, null, null );
+                            copyEntries( pageNewCopy, pageNewCopy.first, pageNewCopy, pageNewCopy.first + 1, index - 1 - pageNewCopy.first );
+                            setEntry( pageNewCopy, pageNewCopy.first, null, null );
                         }
                         else
                         {
-                            copyChildren( this, first, this, first + 1, index - 1 - first );
-                            setChild( this, first, null, -1 );
+                            copyChildren( pageNewCopy, pageNewCopy.first, pageNewCopy, pageNewCopy.first + 1, index - 1 - pageNewCopy.first );
+                            setChild( pageNewCopy, pageNewCopy.first, null, -1 );
                         }
                         
-                        first += 1;
-                        btree.recordManager.update( recordId, this, this );
+                        pageNewCopy.first += 1;
+                        btree.recordManager.update( recordId, pageNewCopy, this );
 
                         // re-link previous and next BPages
                         if ( brother.previous != 0 )
                         {
                             BPage<K, V> prev = loadBPage( brother.previous );
+                            prev = btree.copyOnWrite( prev );
                             prev.next = brother.next;
                             btree.recordManager.update( prev.recordId, prev, this );
                         }
@@ -765,6 +829,7 @@ public class BPage<K, V> implements Seri
                         if ( brother.next != 0 )
                         {
                             BPage<K, V> next = loadBPage( brother.next );
+                            next = btree.copyOnWrite( next );
                             next.previous = brother.previous;
                             btree.recordManager.update( next.recordId, next, this );
                         }
@@ -777,7 +842,8 @@ public class BPage<K, V> implements Seri
         }
 
         // underflow if page is more than half-empty
-        result.underflow = first > half;
+        result.underflow = pageNewCopy.first > half;
+        result.pageNewCopy = pageNewCopy;
 
         return result;
     }
@@ -834,7 +900,7 @@ public class BPage<K, V> implements Seri
     /**
      * Insert entry at given position.
      */
-    private void insertEntry( BPage<K, V> page, int index, K key, V value )
+    private void insertEntry( BPage<K, V> page, int index, K key, V value ) throws IOException
     {
         K[] keys = page.keys;
         V[] values = page.values;
@@ -846,7 +912,7 @@ public class BPage<K, V> implements Seri
         System.arraycopy( values, start, values, start - 1, count );
         page.first -= 1;
         keys[index] = key;
-        values[index] = value;
+        values[index] = btree.copyValue( value );
     }
 
 
@@ -1295,6 +1361,7 @@ public class BPage<K, V> implements Seri
         data = baos.toByteArray();
         oos.close();
         baos.close();
+        
         return data;
     }
 
@@ -1316,13 +1383,18 @@ public class BPage<K, V> implements Seri
          * Existing value for the insertion key.
          */
         V existing;
+        
+        /**
+         * New version of the page doing the insert
+         */
+        BPage<K, V> pageNewCopy;
     }
 
     /** STATIC INNER CLASS
      *  Result from remove() method call. If we had to removed a BPage,
      *  it will be stored into the underflow field.
      */
-    static class RemoveResult<V>
+    static class RemoveResult<K, V>
     {
         /**
          * Set to true if underlying pages underflowed
@@ -1333,6 +1405,12 @@ public class BPage<K, V> implements Seri
          * Removed entry value
          */
         V value;
+        
+        /**
+         * New version of the page doing the remove
+         */
+        BPage<K, V> pageNewCopy;   
+        
     }
 
     /** PRIVATE INNER CLASS
@@ -1342,7 +1420,10 @@ public class BPage<K, V> implements Seri
     {
         /** Current page. */
         private BPage<K, V> page;
-
+        
+        /** context used to track browsing action */
+        ActionContext context;
+        
         /**
          * Current index in the page.  The index positionned on the next
          * tuple to return.
@@ -1354,12 +1435,16 @@ public class BPage<K, V> implements Seri
          * Create a browser.
          *
          * @param page Current page
+         * @param context context in case of action capable record manager 
          * @param index Position of the next tuple to return.
          */
-        Browser( BPage<K, V> page, int index )
+        Browser( BPage<K, V> page, int index, ActionContext context)
         {
             this.page = page;
             this.index = index;
+            this.context = context;
+            
+            outstandingBrowsers.incrementAndGet();
         }
 
 
@@ -1373,55 +1458,106 @@ public class BPage<K, V> implements Seri
          */
         public boolean getNext( Tuple<K, V> tuple ) throws IOException
         {
-            // First, check that we are within a page
-            if ( index < page.btree.pageSize )
+            btree.setAsCurrentAction( context ); 
+            try
             {
-                // We are. Now check that we have a Tuple
-                if ( page.keys[index] == null )
+                // First, check that we are within a page                                                            
+                if ( index < page.btree.pageSize )
                 {
-                    // no : reached end of the tree.
-                    return false;
+                    // We are. Now check that we have a Tuple                                                        
+                    if ( page.keys[index] == null )
+                    {
+                        // no : reached end of the tree.                                                             
+                        return false;
+                    }
+                }
+                // all the tuple for this page has been read. Move to the                                            
+                // next page, if we have one.                                                                        
+                else if ( page.next != 0 )
+                {
+                    // move to next page                                                                             
+                    page = page.loadBPage( page.next );
+                    index = page.first;
                 }
+    
+                tuple.setKey( page.keys[index] );
+                tuple.setValue( btree.copyValue( page.values[index] ) );
+                index++;
             }
-            // all the tuple for this page has been read. Move to the 
-            // next page, if we have one.
-            else if ( page.next != 0 )
+            catch( IOException e )
             {
-                // move to next page
-                page = page.loadBPage( page.next );
-                index = page.first;
+                btree.abortAction( context );
+                context = null;
+                this.close();
+                throw e;
             }
-            
-            tuple.setKey( page.keys[index] );
-            tuple.setValue( page.values[index] );
-            index++;
-            
+            finally
+            {
+                if ( context != null )
+                    btree.unsetAsCurrentAction( context );
+            }
+          
             return true;
         }
 
-
         public boolean getPrevious( Tuple<K, V> tuple ) throws IOException
         {
-            if ( index == page.first )
+            btree.setAsCurrentAction( context );           
+            try
             {
-                if ( page.previous != 0 )
+                if ( index == page.first )
                 {
-                    page = page.loadBPage( page.previous );
-                    index = page.btree.pageSize;
-                }
-                else
-                {
-                    // reached beginning of the tree
-                    return false;
+                    if ( page.previous != 0 )
+                    {
+                        page = page.loadBPage( page.previous );
+                        index = page.btree.pageSize;
+                    }
+                    else
+                    {
+                        // reached beginning of the tree                                                             
+                        return false;
+                    }
                 }
-            }
+    
+                index--;
+                tuple.setKey( page.keys[index] );
+                tuple.setValue( btree.copyValue( page.values[index] ) );
+            }
+            catch( IOException e )
+            {
+                btree.abortAction( context );
+                context = null;
+                this.close();
+                throw e;
+            }
+            finally
+            {
+                if ( context != null )
+                    btree.unsetAsCurrentAction( context );
+            }          
+
+            return true;
+        }
+        
+        @Override
+        public void close()
+        {
+            super.close();
             
-            index--;
-            tuple.setKey( page.keys[index] );
-            tuple.setValue( page.values[index] );
+            if ( context!= null )
+            {
+                btree.setAsCurrentAction( context );
+                btree.endAction( context );
+                context = null;
+            }
             
-            return true;
+            int browserCount = outstandingBrowsers.decrementAndGet();
+            if ( browserCount > 0 )
+            {
+                //System.out.println( "JDBM btree browsers are outstanding after close: " + browserCount );
+            }
         }
+
     }
     
     
@@ -1469,7 +1605,6 @@ public class BPage<K, V> implements Seri
         else
         {
             boolean isFirst = true;
-            //int index = 0;
             
             for ( K key : keys )
             {
@@ -1484,8 +1619,6 @@ public class BPage<K, V> implements Seri
 
                 sb.append( "<" );
                 sb.append( key );
-                //sb.append( "/" );
-                //sb.append( values[index] );
                 sb.append( ">" );
             }
         }



Mime
View raw message