directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1307585 - in /directory: apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/parti...
Date Fri, 30 Mar 2012 19:44:22 GMT
Author: elecharny
Date: Fri Mar 30 19:44:21 2012
New Revision: 1307585

URL: http://svn.apache.org/viewvc?rev=1307585&view=rev
Log:
o Used the RdnIndex instead of the OneLevelIndex for the List( ID ) method
o Made the IndexCursorAdaptor class extends the AbstarctIndexCursor, removing some of its
duplicated methods
o Removed the useless TupleCursor
o Fixed the ParentIdAndRdn compareTo() method
o Added a ChildrenCursor to be able to browse the RdnIdx to find all the children of an entry
o Fixed some tests, improving the checks

Added:
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
Removed:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/TupleCursor.java
Modified:
    directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
    directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java

Modified: directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
(original)
+++ directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Fri Mar 30 19:44:21 2012
@@ -515,8 +515,13 @@ public class JdbmStoreTest
         assertNotNull( cursor );
         cursor.beforeFirst();
         assertTrue( cursor.next() );
-        assertEquals( 2L, ( long ) cursor.get().getId() );
+        assertEquals( 3L, ( long ) cursor.get().getId() );
+        assertTrue( cursor.next() );
+        assertEquals( 4L, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertEquals( 2L, ( long ) cursor.get().getId() );
+        assertFalse( cursor.next() );
+        
         assertEquals( 3, store.getChildCount( 1L ) );
 
         store.delete( 2L );

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
Fri Mar 30 19:44:21 2012
@@ -63,6 +63,8 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.search.Optimizer;
 import org.apache.directory.server.xdbm.search.SearchEngine;
+import org.apache.directory.server.xdbm.search.impl.ChildrenCursor;
+import org.apache.directory.server.xdbm.search.impl.OneLevelScopeCursor;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
@@ -536,6 +538,15 @@ public abstract class AbstractBTreeParti
         
     }
 
+    
+    /*
+    private void dumpAllRdnIdx() throws Exception
+    {
+        dumpRdnIdx( getRootId(), "" );
+        System.out.println( "-----------------------------" );
+    }
+    */
+
    
     private void dumpRdnIdx() throws Exception
     {
@@ -547,6 +558,27 @@ public abstract class AbstractBTreeParti
     }
     
     
+    /*
+    private void dumpRdnIdx( ID id, String tabs ) throws Exception
+    {
+        // Start with the root
+        IndexCursor<ParentIdAndRdn<ID>,Entry,ID> cursor = rdnIdx.forwardCursor();
+        
+        IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>,
ID>();
+        startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) );
+        cursor.before( startingPos );
+        
+        while ( cursor.next() )
+        {
+            IndexEntry<ParentIdAndRdn<ID>, ID> entry = cursor.get();
+            System.out.println( tabs + entry );
+        }
+        
+        cursor.close();
+    }
+    */
+    
+    
     private void dumpRdnIdx( ID id, int nbSibbling, String tabs ) throws Exception
     {
         // Start with the root
@@ -560,7 +592,7 @@ public abstract class AbstractBTreeParti
         while ( cursor.next() && ( countChildren < nbSibbling ) )
         {
             IndexEntry<ParentIdAndRdn<ID>, ID> entry = cursor.get();
-            System.out.println( tabs + entry.getValue() );
+            System.out.println( tabs + entry );
             countChildren++;
             
             // And now, the children
@@ -910,12 +942,20 @@ public abstract class AbstractBTreeParti
     {
         try
         {
+            // Fetch the entry
+            ParentIdAndRdn<ID> parent = rdnIdx.reverseLookup( id );
+            
             // We use the OneLevel index to get all the entries from a starting point
-            // and below
-            IndexCursor<ID, Entry, ID> cursor = oneLevelIdx.forwardCursor( id );
-            cursor.beforeValue( id, null );
+            // and below up to the number of children
+            IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor = rdnIdx.forwardCursor();
+            
+            IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>,
ID>();
+            startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) );
+            cursor.before( startingPos );
+
+            dumpRdnIdx();
 
-            return cursor;
+            return new ChildrenCursor( this, id, cursor );
         }
         catch ( Exception e )
         {

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java
Fri Mar 30 19:44:21 2012
@@ -22,6 +22,7 @@ package org.apache.directory.server.core
 
 import java.util.Iterator;
 
+import org.apache.directory.server.xdbm.AbstractIndexCursor;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.IndexCursor;
 import org.apache.directory.server.xdbm.IndexEntry;
@@ -31,7 +32,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.CursorIterator;
 import org.apache.directory.shared.ldap.model.cursor.Tuple;
-import org.apache.directory.shared.ldap.model.cursor.TupleCursor;
 
 
 /**
@@ -40,7 +40,7 @@ import org.apache.directory.shared.ldap.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class IndexCursorAdaptor<K, O, ID> implements IndexCursor<K, O, ID>
+public class IndexCursorAdaptor<K, O, ID> extends AbstractIndexCursor<K, O, ID>
 {
     @SuppressWarnings("unchecked")
     final Cursor<Tuple> wrappedCursor;
@@ -80,26 +80,6 @@ public class IndexCursorAdaptor<K, O, ID
     }
 
 
-    @SuppressWarnings("unchecked")
-    public void beforeValue( ID id, K key ) throws Exception
-    {
-        if ( wrappedCursor instanceof TupleCursor )
-        {
-            ( ( TupleCursor ) wrappedCursor ).beforeValue( key, id );
-        }
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public void afterValue( ID id, K key ) throws Exception
-    {
-        if ( wrappedCursor instanceof TupleCursor )
-        {
-            ( ( TupleCursor ) wrappedCursor ).afterValue( key, id );
-        }
-    }
-
-
     public void before( IndexEntry<K, ID> element ) throws Exception
     {
         wrappedCursor.before( element.getTuple() );
@@ -234,4 +214,12 @@ public class IndexCursorAdaptor<K, O, ID
         throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION,
getClass().getName()
             .concat( "." ).concat( "isLast()" ) ) );
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String getUnsupportedMessage()
+    {
+        return UNSUPPORTED_MSG;
+    }
 }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
Fri Mar 30 19:44:21 2012
@@ -193,7 +193,17 @@ public class ParentIdAndRdn<ID extends C
         // Special case when that.rdns = null : we are searching for oneLevel or subLevel
scope
         if ( that.rdns == null )
         {
-            return parentId.compareTo( that.parentId );
+            int val = parentId.compareTo( that.parentId );
+            
+            if ( val != 0 )
+            {
+                return val;
+            }
+            else
+            {
+                // The current value is necessarily superior
+                return 1;
+            }
         }
 
         if ( rdns == null )

Added: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java?rev=1307585&view=auto
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
(added)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
Fri Mar 30 19:44:21 2012
@@ -0,0 +1,171 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.xdbm.search.impl;
+
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.xdbm.AbstractIndexCursor;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.IndexCursor;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.shared.ldap.model.cursor.Cursor;
+import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+
+
+/**
+ * A Cursor over entries satisfying one level scope constraints with alias
+ * dereferencing considerations when enabled during search.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ChildrenCursor<ID extends Comparable<ID>> extends AbstractIndexCursor<ID,
Entry, ID>
+{
+    /** Error message for unsupported operations */
+    private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_719 );
+
+    /** A Cursor over the entries in the scope of the search base */
+    private final IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor;
+
+    /** The entry database/store */
+    private final Store<Entry, ID> db;
+    
+    /** The current position in the cursor */
+    private int currentChild;
+    
+    /** The max number of childen */
+    private int maxChildren;
+
+    /**
+     * Creates a Cursor over entries satisfying one level scope criteria.
+     *
+     * @param db the entry store
+     * @param evaluator an IndexEntry (candidate) evaluator
+     * @throws Exception on db access failures
+     */
+    //@SuppressWarnings("unchecked")
+    public ChildrenCursor( Store<Entry, ID> db, ID id, IndexCursor<ParentIdAndRdn<ID>,Entry,
ID> cursor )
+        throws Exception
+    {
+        this.db = db;
+        ParentIdAndRdn<ID> parent = db.getRdnIndex().reverseLookup( id );
+        currentChild = 0;
+        
+        if ( parent == null )
+        {
+            maxChildren = 0;
+        }
+        else
+        {
+            maxChildren = parent.getNbChildren();
+        }
+        
+        this.cursor = cursor;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String getUnsupportedMessage()
+    {
+        return UNSUPPORTED_MSG;
+    }
+
+
+    public void beforeFirst() throws Exception
+    {
+        checkNotClosed( "beforeFirst()" );
+        setAvailable( false );
+    }
+
+
+    public void afterLast() throws Exception
+    {
+        throw new UnsupportedOperationException( getUnsupportedMessage() );
+    }
+
+
+    public boolean first() throws Exception
+    {
+        beforeFirst();
+        currentChild = -1;
+        
+        return next();
+    }
+
+
+    public boolean last() throws Exception
+    {
+        throw new UnsupportedOperationException( getUnsupportedMessage() );
+    }
+
+
+    public boolean previous() throws Exception
+    {
+        throw new UnsupportedOperationException( getUnsupportedMessage() );
+    }
+
+
+    public boolean next() throws Exception
+    {
+        checkNotClosed( "next()" );
+        
+        if ( currentChild < maxChildren )
+        {
+            currentChild++;
+
+            return cursor.next();
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    public IndexEntry<ID, ID> get() throws Exception
+    {
+        checkNotClosed( "get()" );
+
+        IndexEntry entry = cursor.get();
+        
+        return entry;
+    }
+
+
+    @Override
+    public void close() throws Exception
+    {
+        cursor.close();
+
+        super.close();
+    }
+
+
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        cursor.close( cause );
+
+        super.close( cause );
+    }
+}
\ No newline at end of file

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
Fri Mar 30 19:44:21 2012
@@ -54,6 +54,7 @@ public class DefaultSearchEngine<ID exte
 {
     /** the Optimizer used by this DefaultSearchEngine */
     private final Optimizer optimizer;
+    
     /** the Database this DefaultSearchEngine operates on */
     private final Store<Entry, ID> db;
     /** creates Cursors over entries satisfying filter expressions */

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
Fri Mar 30 19:44:21 2012
@@ -414,12 +414,15 @@ public class AvlPartitionTest
     {
         assertEquals( 3, partition.getChildCount( 1L ) );
 
-        Cursor<IndexEntry<Long, Long>> cursor = partition.list( 1L );
+        Cursor<IndexEntry<Long, Long>> cursor = partition.list( 2L );
         assertNotNull( cursor );
         cursor.beforeFirst();
         assertTrue( cursor.next() );
-        assertEquals( 2L, ( long ) cursor.get().getId() );
+        assertEquals( 6L, ( long ) cursor.get().getId() );
         assertTrue( cursor.next() );
+        assertEquals( 5L, ( long ) cursor.get().getId() );
+        assertFalse( cursor.next() );
+        
         assertEquals( 3, partition.getChildCount( 1L ) );
 
         partition.delete( 2L );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java?rev=1307585&r1=1307584&r2=1307585&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java
Fri Mar 30 19:44:21 2012
@@ -39,7 +39,7 @@ public abstract class AbstractCursor<E> 
     /**
      * {@inheritDoc}
      */
-    public final void setClosureMonitor( ClosureMonitor monitor )
+    public void setClosureMonitor( ClosureMonitor monitor )
     {
         if ( monitor == null )
         {
@@ -65,7 +65,7 @@ public abstract class AbstractCursor<E> 
     /**
      * {@inheritDoc}
      */
-    public final boolean isClosed()
+    public boolean isClosed() throws Exception
     {
         return monitor.isClosed();
     }



Mime
View raw message