directory-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1304379&view=rev
Log:
o Added a flag in the Index Interface to allow an index not to have a reverse table
o Modified the JdbmIndex and AvlIndex table to check this flag before manipulating the reverse
table
o Initialized the Presence, ObjectClass and entryCSN index with no reverse table
o Modified the SubstringEvaluator to use the evaluateWithoutIndex() method when the index
does not have a reverse table

Modified:
    directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
    directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
    directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/avl/AvlPartition.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/xdbm/AbstractIndex.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlRdnIndex.java
    directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
    directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java

Modified: directory/apacheds/branches/index-work/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/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
(original)
+++ directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
Fri Mar 23 14:44:21 2012
@@ -33,9 +33,11 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.partition.impl.btree.LongComparator;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractIndex;
+import org.apache.directory.server.xdbm.EmptyIndexCursor;
 import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.server.xdbm.IndexCursor;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
+import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.model.cursor.Tuple;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
@@ -120,7 +122,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public JdbmIndex()
     {
-        super();
+        super( true );
         initialized = false;
     }
 
@@ -130,7 +132,17 @@ public class JdbmIndex<K, O> extends Abs
      */
     public JdbmIndex( String attributeId )
     {
-        super( attributeId );
+        super( attributeId, true );
+        initialized = false;
+    }
+
+
+    /**
+     * Creates a JdbmIndex instance for a give AttributeId
+     */
+    public JdbmIndex( String attributeId, boolean withReverse )
+    {
+        super( attributeId, withReverse );
         initialized = false;
     }
 
@@ -225,16 +237,19 @@ public class JdbmIndex<K, O> extends Abs
          * is single valued according to its specification based on a schema
          * then duplicate keys should not be allowed within the reverse table.
          */
-        if ( attributeType.isSingleValued() )
+        if ( withReverse )
         {
-            reverse = new JdbmTable<Long, K>( schemaManager, attributeType.getOid()
+ REVERSE_BTREE, recMan,
-                LongComparator.INSTANCE, LongSerializer.INSTANCE, null );
-        }
-        else
-        {
-            reverse = new JdbmTable<Long, K>( schemaManager, attributeType.getOid()
+ REVERSE_BTREE, numDupLimit,
-                recMan,
-                LongComparator.INSTANCE, comp, LongSerializer.INSTANCE, null );
+            if ( attributeType.isSingleValued() )
+            {
+                reverse = new JdbmTable<Long, K>( schemaManager, attributeType.getOid()
+ REVERSE_BTREE, recMan,
+                    LongComparator.INSTANCE, LongSerializer.INSTANCE, null );
+            }
+            else
+            {
+                reverse = new JdbmTable<Long, K>( schemaManager, attributeType.getOid()
+ REVERSE_BTREE, numDupLimit,
+                    recMan,
+                    LongComparator.INSTANCE, comp, LongSerializer.INSTANCE, null );
+            }
         }
     }
 
@@ -347,7 +362,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public K reverseLookup( Long id ) throws Exception
     {
-        return reverse.get( id );
+        if ( withReverse )
+        {
+            return reverse.get( id );
+        }
+        else
+        {
+            return null;
+        }
     }
 
 
@@ -362,7 +384,11 @@ public class JdbmIndex<K, O> extends Abs
     {
         // The pair to be removed must exists
         forward.put( attrVal, id );
-        reverse.put( id, attrVal );
+
+        if ( withReverse )
+        {
+            reverse.put( id, attrVal );
+        }
     }
 
 
@@ -375,7 +401,11 @@ public class JdbmIndex<K, O> extends Abs
         if ( forward.has( attrVal, id ) )
         {
             forward.remove( attrVal, id );
-            reverse.remove( id, attrVal );
+
+            if ( withReverse )
+            {
+                reverse.remove( id, attrVal );
+            }
         }
     }
 
@@ -396,7 +426,10 @@ public class JdbmIndex<K, O> extends Abs
         }
 
         // Remove the id -> key from the reverse index
-        reverse.remove( entryId );
+        if ( withReverse )
+        {
+            reverse.remove( entryId );
+        }
     }
 
 
@@ -406,7 +439,14 @@ public class JdbmIndex<K, O> extends Abs
     @SuppressWarnings("unchecked")
     public IndexCursor<K, O, Long> reverseCursor() throws Exception
     {
-        return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) reverse.cursor(), false
);
+        if ( withReverse )
+        {
+            return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) reverse.cursor(),
false );
+        }
+        else
+        {
+            return new EmptyIndexCursor<K, O, Long>();
+        }
     }
 
 
@@ -420,7 +460,14 @@ public class JdbmIndex<K, O> extends Abs
     @SuppressWarnings("unchecked")
     public IndexCursor<K, O, Long> reverseCursor( Long id ) throws Exception
     {
-        return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) reverse.cursor( id ),
false );
+        if ( withReverse )
+        {
+            return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) reverse.cursor( id
), false );
+        }
+        else
+        {
+            return new EmptyIndexCursor<K, O, Long>();
+        }
     }
 
 
@@ -433,7 +480,14 @@ public class JdbmIndex<K, O> extends Abs
 
     public Cursor<K> reverseValueCursor( Long id ) throws Exception
     {
-        return reverse.valueCursor( id );
+        if ( withReverse )
+        {
+            return reverse.valueCursor( id );
+        }
+        else
+        {
+            return new EmptyCursor<K>();
+        }
     }
 
 
@@ -469,7 +523,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverse( Long id ) throws Exception
     {
-        return reverse.has( id );
+        if ( withReverse )
+        {
+            return reverse.has( id );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -523,7 +584,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverseGreaterOrEq( Long id ) throws Exception
     {
-        return reverse.hasGreaterOrEqual( id );
+        if ( withReverse )
+        {
+            return reverse.hasGreaterOrEqual( id );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -532,7 +600,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverseGreaterOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasGreaterOrEqual( id, attrVal );
+        if ( withReverse )
+        {
+            return reverse.hasGreaterOrEqual( id, attrVal );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -541,7 +616,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverseLessOrEq( Long id ) throws Exception
     {
-        return reverse.hasLessOrEqual( id );
+        if ( withReverse )
+        {
+            return reverse.hasLessOrEqual( id );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -550,7 +632,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverseLessOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasLessOrEqual( id, attrVal );
+        if ( withReverse )
+        {
+            return reverse.hasLessOrEqual( id, attrVal );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -591,7 +680,14 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean isDupsEnabled()
     {
-        return reverse.isDupsEnabled();
+        if ( withReverse )
+        {
+            return reverse.isDupsEnabled();
+        }
+        else
+        {
+            return false;
+        }
     }
 
 

Modified: directory/apacheds/branches/index-work/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/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
(original)
+++ directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
Fri Mar 23 14:44:21 2012
@@ -358,7 +358,7 @@ public class JdbmPartition extends Abstr
         {
             LOG.debug( "Supplied index {} is not a JdbmIndex.  "
                 + "Will create new JdbmIndex using copied configuration parameters.", index
);
-            jdbmIndex = new JdbmIndex( index.getAttributeId() );
+            jdbmIndex = new JdbmIndex( index.getAttributeId(), true );
             jdbmIndex.setCacheSize( index.getCacheSize() );
             jdbmIndex.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT );
             jdbmIndex.setWkDirPath( index.getWkDirPath() );
@@ -413,7 +413,7 @@ public class JdbmPartition extends Abstr
     /**
      * {@inheritDoc}
      */
-    protected final Index createSystemIndex( String oid, URI path )  throws Exception
+    protected final Index createSystemIndex( String oid, URI path, boolean withReverse )
 throws Exception
     {
         LOG.debug( "Supplied index {} is not a JdbmIndex.  " +
          "Will create new JdbmIndex using copied configuration parameters." );
@@ -427,7 +427,7 @@ public class JdbmPartition extends Abstr
         }
         else
         {
-            jdbmIndex = new JdbmIndex( oid );
+            jdbmIndex = new JdbmIndex( oid, withReverse );
             jdbmIndex.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT );
         }
 

Modified: directory/apacheds/branches/index-work/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/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
(original)
+++ directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
Fri Mar 23 14:44:21 2012
@@ -55,6 +55,7 @@ public class JdbmRdnIndex<E> extends Jdb
 
     public JdbmRdnIndex()
     {
+        super();
         initialized = false;
     }
 

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/avl/AvlPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/avl/AvlPartition.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/avl/AvlPartition.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/avl/AvlPartition.java
Fri Mar 23 14:44:21 2012
@@ -159,7 +159,7 @@ public class AvlPartition extends Abstra
         {
             LOG.debug( "Supplied index {} is not a AvlIndex. "
                 + "Will create new AvlIndex using copied configuration parameters.", index
);
-            avlIndex = new AvlIndex( index.getAttributeId() );
+            avlIndex = new AvlIndex( index.getAttributeId(), true );
         }
 
         avlIndex.init( schemaManager, schemaManager.lookupAttributeTypeRegistry( index.getAttributeId()
) );
@@ -171,7 +171,7 @@ public class AvlPartition extends Abstra
     /**
      * {@inheritDoc}
      */
-    protected final Index createSystemIndex( String oid, URI path ) throws Exception
+    protected final Index createSystemIndex( String oid, URI path, boolean withReverse )
throws Exception
     {
         LOG.debug( "Supplied index {} is not a JdbmIndex.  "
             + "Will create new JdbmIndex using copied configuration parameters." );
@@ -186,7 +186,7 @@ public class AvlPartition extends Abstra
         {
             LOG.debug( "Supplied index {} is not a AvlIndex. "
                 + "Will create new AvlIndex using copied configuration parameters." );
-            avlIndex = new AvlIndex( oid );
+            avlIndex = new AvlIndex( oid, withReverse );
         }
 
         return avlIndex;

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=1304379&r1=1304378&r2=1304379&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 23 14:44:21 2012
@@ -175,6 +175,8 @@ public abstract class AbstractBTreeParti
     protected AttributeType ENTRY_UUID_AT;
     protected AttributeType ALIASED_OBJECT_NAME_AT;
 
+    private static final boolean NO_REVERSE = Boolean.FALSE;
+    private static final boolean WITH_REVERSE = Boolean.TRUE;
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
@@ -285,61 +287,61 @@ public abstract class AbstractBTreeParti
         // add missing system indices
         if ( getPresenceIndex() == null )
         {
-            Index<String, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID,
partitionPath );
+            Index<String, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID,
partitionPath, NO_REVERSE );
             addIndex( index );
         }
 
         if ( getOneLevelIndex() == null )
         {
-            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_ONE_LEVEL_AT_OID,
partitionPath );
+            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_ONE_LEVEL_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getSubLevelIndex() == null )
         {
-            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID,
partitionPath );
+            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getRdnIndex() == null )
         {
-            Index<ParentIdAndRdn<ID>, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID,
partitionPath );
+            Index<ParentIdAndRdn<ID>, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getAliasIndex() == null )
         {
-            Index<String, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_ALIAS_AT_OID,
partitionPath );
+            Index<String, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_ALIAS_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getOneAliasIndex() == null )
         {
-            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID,
partitionPath );
+            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getSubAliasIndex() == null )
         {
-            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID,
partitionPath );
+            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getObjectClassIndex() == null )
         {
-            Index<String, Entry, ID> index = createSystemIndex( SchemaConstants.OBJECT_CLASS_AT_OID,
partitionPath );
+            Index<String, Entry, ID> index = createSystemIndex( SchemaConstants.OBJECT_CLASS_AT_OID,
partitionPath, NO_REVERSE );
             addIndex( index );
         }
 
         if ( getEntryUuidIndex() == null )
         {
-            Index<String, Entry, ID> index = createSystemIndex( SchemaConstants.ENTRY_UUID_AT_OID,
partitionPath );
+            Index<String, Entry, ID> index = createSystemIndex( SchemaConstants.ENTRY_UUID_AT_OID,
partitionPath, WITH_REVERSE );
             addIndex( index );
         }
 
         if ( getEntryCsnIndex() == null )
         {
-            Index<String, Entry, ID> index = createSystemIndex( SchemaConstants.ENTRY_CSN_AT_OID,
partitionPath );
+            Index<String, Entry, ID> index = createSystemIndex( SchemaConstants.ENTRY_CSN_AT_OID,
partitionPath, NO_REVERSE );
             addIndex( index );
         }
 
@@ -756,8 +758,8 @@ public abstract class AbstractBTreeParti
             rdnIdx.drop( id );
             oneLevelIdx.drop( id );
             subLevelIdx.drop( id );
-            entryCsnIdx.drop( id );
-            entryUuidIdx.drop( id );
+            entryCsnIdx.drop( entry.get( ENTRY_CSN_AT ).getString(), id );
+            entryUuidIdx.drop( entry.get( ENTRY_UUID_AT ).getString(), id );
 
             // Update the user indexes
             for ( Attribute attribute : entry )
@@ -1148,11 +1150,11 @@ public abstract class AbstractBTreeParti
         {
             // if the id exists in the index drop all existing attribute
             // value index entries and add new ones
-            if ( objectClassIdx.reverse( id ) )
+            for ( Value<?> value : entry.get( OBJECT_CLASS_AT ) )
             {
-                objectClassIdx.drop( id );
+                objectClassIdx.drop( value.getString(), id );
             }
-
+            
             for ( Value<?> value : mods )
             {
                 objectClassIdx.add( value.getString(), id );
@@ -1245,7 +1247,10 @@ public abstract class AbstractBTreeParti
              */
             if ( mods.size() == 0 )
             {
-                objectClassIdx.drop( id );
+                for ( Value<?> objectClass : entry.get( OBJECT_CLASS_AT ) )
+                {
+                    objectClassIdx.drop( objectClass.getString(), id );
+                }
             }
             else
             {
@@ -1818,8 +1823,9 @@ public abstract class AbstractBTreeParti
      */
     private void updateCsnIndex( Entry entry, ID id ) throws Exception
     {
-        entryCsnIdx.drop( id );
-        entryCsnIdx.add( entry.get( SchemaConstants.ENTRY_CSN_AT ).getString(), id );
+        String entryCsn = entry.get( SchemaConstants.ENTRY_CSN_AT ).getString();
+        entryCsnIdx.drop( entryCsn, id );
+        entryCsnIdx.add( entryCsn, id );
     }
 
 
@@ -2624,5 +2630,5 @@ public abstract class AbstractBTreeParti
      * @return The created index
      * @throws Exception If the index can't be created
      */
-     protected abstract Index createSystemIndex( String indexOid, URI path ) throws Exception;
+     protected abstract Index createSystemIndex( String indexOid, URI path, boolean withReverse
) throws Exception;
 }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndex.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndex.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndex.java
Fri Mar 23 14:44:21 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.xdbm;
 
@@ -44,6 +44,8 @@ public abstract class AbstractIndex<K, O
     /** whether or not this index has been initialized */
     protected boolean initialized;
 
+    /** Tells if this index has a Reverse table */
+    protected boolean withReverse;
 
     /**
      * Creates a new instance of AbstractIndex.
@@ -52,6 +54,18 @@ public abstract class AbstractIndex<K, O
      */
     protected AbstractIndex()
     {
+        this.withReverse = true;
+    }
+
+    
+    /**
+     * Creates a new instance of AbstractIndex.
+     * 
+     * @param attributeId the attribute ID
+     */
+    protected AbstractIndex( boolean withReverse )
+    {
+        this.withReverse = withReverse;
     }
 
 
@@ -60,9 +74,10 @@ public abstract class AbstractIndex<K, O
      * 
      * @param attributeId the attribute ID
      */
-    protected AbstractIndex( String attributeId )
+    protected AbstractIndex( String attributeId, boolean withReverse )
     {
         this.attributeId = attributeId;
+        this.withReverse = withReverse;
     }
 
 
@@ -132,4 +147,13 @@ public abstract class AbstractIndex<K, O
             throw new IllegalStateException( I18n.err( I18n.ERR_575, property ) );
         }
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasReverse()
+    {
+        return withReverse;
+    }
 }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
Fri Mar 23 14:44:21 2012
@@ -261,4 +261,11 @@ public interface Index<K, O, ID>
      * @return true if duplicate keys are allowed false otherwise
      */
     boolean isDupsEnabled();
+    
+    
+    /**
+     * Tells if the index has a reverse table or not
+     * @return true if the index has a reverse table
+     */
+    boolean hasReverse();
 }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
Fri Mar 23 14:44:21 2012
@@ -26,8 +26,10 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.partition.impl.btree.LongComparator;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractIndex;
+import org.apache.directory.server.xdbm.EmptyIndexCursor;
 import org.apache.directory.server.xdbm.IndexCursor;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
+import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.model.cursor.Tuple;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
@@ -50,13 +52,19 @@ public class AvlIndex<K, O> extends Abst
 
     public AvlIndex()
     {
-        super();
+        super( true );
     }
 
 
     public AvlIndex( String attributeId )
     {
-        super( attributeId );
+        super( attributeId, true );
+    }
+
+
+    public AvlIndex( String attributeId, boolean withReverse )
+    {
+        super( attributeId, withReverse );
     }
 
 
@@ -98,13 +106,16 @@ public class AvlIndex<K, O> extends Abst
          * is single valued according to its specification based on a schema
          * then duplicate keys should not be allowed within the reverse table.
          */
-        if ( attributeType.isSingleValued() )
+        if ( withReverse )
         {
-            reverse = new AvlTable<Long, K>( attributeType.getName(), LongComparator.INSTANCE,
comp, false );
-        }
-        else
-        {
-            reverse = new AvlTable<Long, K>( attributeType.getName(), LongComparator.INSTANCE,
comp, true );
+            if ( attributeType.isSingleValued() )
+            {
+                reverse = new AvlTable<Long, K>( attributeType.getName(), LongComparator.INSTANCE,
comp, false );
+            }
+            else
+            {
+                reverse = new AvlTable<Long, K>( attributeType.getName(), LongComparator.INSTANCE,
comp, true );
+            }
         }
     }
 
@@ -112,7 +123,11 @@ public class AvlIndex<K, O> extends Abst
     public void add( K attrVal, Long id ) throws Exception
     {
         forward.put( attrVal, id );
-        reverse.put( id, attrVal );
+        
+        if ( withReverse )
+        {
+            reverse.put( id, attrVal );
+        }
     }
 
 
@@ -156,15 +171,18 @@ public class AvlIndex<K, O> extends Abst
      */
     public void drop( Long id ) throws Exception
     {
-        Cursor<Tuple<Long, K>> cursor = reverse.cursor( id );
-
-        while ( cursor.next() )
+        if ( withReverse )
         {
-            Tuple<Long, K> tuple = cursor.get();
-            forward.remove( tuple.getValue(), id );
+            Cursor<Tuple<Long, K>> cursor = reverse.cursor( id );
+    
+            while ( cursor.next() )
+            {
+                Tuple<Long, K> tuple = cursor.get();
+                forward.remove( tuple.getValue(), id );
+            }
+    
+            reverse.remove( id );
         }
-
-        reverse.remove( id );
     }
 
 
@@ -174,7 +192,11 @@ public class AvlIndex<K, O> extends Abst
     public void drop( K attrVal, Long id ) throws Exception
     {
         forward.remove( attrVal, id );
-        reverse.remove( id, attrVal );
+        
+        if ( withReverse )
+        {
+            reverse.remove( id, attrVal );
+        }
     }
 
 
@@ -293,7 +315,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverse( Long id ) throws Exception
     {
-        return reverse.has( id );
+        if ( withReverse )
+        {
+            return reverse.has( id );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -302,7 +331,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverse( Long id, K attrVal ) throws Exception
     {
-        return reverse.has( id, attrVal );
+        if ( withReverse )
+        {
+            return reverse.has( id, attrVal );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -312,7 +348,14 @@ public class AvlIndex<K, O> extends Abst
     @SuppressWarnings("unchecked")
     public IndexCursor<K, O, Long> reverseCursor() throws Exception
     {
-        return new IndexCursorAdaptor( reverse.cursor(), false );
+        if ( withReverse )
+        {
+            return new IndexCursorAdaptor( reverse.cursor(), false );
+        }
+        else
+        {
+            return new EmptyIndexCursor<K, O, Long>();
+        }
     }
 
 
@@ -322,7 +365,14 @@ public class AvlIndex<K, O> extends Abst
     @SuppressWarnings("unchecked")
     public IndexCursor<K, O, Long> reverseCursor( Long id ) throws Exception
     {
-        return new IndexCursorAdaptor( reverse.cursor( id ), false );
+        if ( withReverse )
+        {
+            return new IndexCursorAdaptor( reverse.cursor( id ), false );
+        }
+        else
+        {
+            return new EmptyIndexCursor<K, O, Long>();
+        }
     }
 
 
@@ -331,7 +381,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverseGreaterOrEq( Long id ) throws Exception
     {
-        return reverse.hasGreaterOrEqual( id );
+        if ( withReverse )
+        {
+            return reverse.hasGreaterOrEqual( id );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -340,7 +397,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverseGreaterOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasGreaterOrEqual( id, attrVal );
+        if ( withReverse )
+        {
+            return reverse.hasGreaterOrEqual( id, attrVal );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -349,7 +413,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverseLessOrEq( Long id ) throws Exception
     {
-        return reverse.hasLessOrEqual( id );
+        if ( withReverse )
+        {
+            return reverse.hasLessOrEqual( id );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -358,7 +429,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverseLessOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasLessOrEqual( id, attrVal );
+        if ( withReverse )
+        {
+            return reverse.hasLessOrEqual( id, attrVal );
+        }
+        else
+        {
+            return false;
+        }
     }
 
 
@@ -367,7 +445,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public K reverseLookup( Long id ) throws Exception
     {
-        return reverse.get( id );
+        if ( withReverse )
+        {
+            return reverse.get( id );
+        }
+        else
+        {
+            return null;
+        }
     }
 
 
@@ -376,7 +461,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public Cursor<K> reverseValueCursor( Long id ) throws Exception
     {
-        return reverse.valueCursor( id );
+        if ( withReverse )
+        {
+            return reverse.valueCursor( id );
+        }
+        else
+        {
+            return new EmptyCursor<K>();
+        }
     }
 
 
@@ -403,7 +495,14 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean isDupsEnabled()
     {
-        return reverse.isDupsEnabled();
+        if ( withReverse )
+        {
+            return reverse.isDupsEnabled();
+        }
+        else
+        {
+            return false;
+        }
     }
 
 

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlRdnIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlRdnIndex.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlRdnIndex.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlRdnIndex.java
Fri Mar 23 14:44:21 2012
@@ -40,12 +40,13 @@ public class AvlRdnIndex<E> extends AvlI
 
     public AvlRdnIndex()
     {
+        super();
     }
 
 
     public AvlRdnIndex( String attributeId )
     {
-        super( attributeId );
+        super( attributeId, true );
     }
 
 
@@ -77,7 +78,7 @@ public class AvlRdnIndex<E> extends AvlI
         LongComparator.INSTANCE.setSchemaManager( schemaManager );
 
         /*
-         * The forward key/value map stores attribute values to master table 
+         * The forward key/value map stores attribute values to master table
          * primary keys.  A value for an attribute can occur several times in
          * different entries so the forward map can have more than one value.
          */

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
Fri Mar 23 14:44:21 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.xdbm.search.impl;
 
@@ -127,8 +127,7 @@ public class SubstringEvaluator<ID exten
     @SuppressWarnings("unchecked")
     public boolean evaluate( IndexEntry<?, ID> indexEntry ) throws Exception
     {
-
-        if ( idx == null )
+        if ( ( idx == null ) || ( !idx.hasReverse() ) )
         {
             return evaluateWithoutIndex( ( IndexEntry<String, ID> ) indexEntry );
         }
@@ -196,7 +195,7 @@ public class SubstringEvaluator<ID exten
             IndexEntry<String, ID> rec = entries.get();
 
             // once match is found cleanup and return true
-            if ( regex.matcher( ( String ) rec.getValue() ).matches() )
+            if ( regex.matcher( rec.getValue() ).matches() )
             {
                 entries.close();
                 return true;
@@ -232,7 +231,7 @@ public class SubstringEvaluator<ID exten
             IndexEntry<String, ID> rec = entries.get();
 
             // once match is found cleanup and return true
-            if ( regex.matcher( ( String ) rec.getValue() ).matches() )
+            if ( regex.matcher( rec.getValue() ).matches() )
             {
                 entries.close();
                 return true;

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java?rev=1304379&r1=1304378&r2=1304379&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java
(original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java
Fri Mar 23 14:44:21 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.xdbm;
 
@@ -307,8 +307,8 @@ public class PartitionTest
     {
         Dn dn = new Dn( schemaManager, "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
 
-        Attribute attrib = new DefaultAttribute( SchemaConstants.OBJECT_CLASS_AT, schemaManager
-            .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ) );
+        Attribute attrib = new DefaultAttribute( "ObjectClass", schemaManager
+            .lookupAttributeTypeRegistry( "ObjectClass" ) );
 
         Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
attrib );
 
@@ -316,14 +316,12 @@ public class PartitionTest
         Entry lookedup = partition.lookup( entryId );
 
         // before modification: expect "person" tuple in objectClass index
-        assertTrue( partition.getObjectClassIndex().reverse( entryId ) );
         assertTrue( partition.getObjectClassIndex().forward( "person", entryId ) );
         assertTrue( lookedup.get( "objectClass" ).contains( "person" ) );
 
         lookedup = partition.modify( dn, add );
 
         // after modification: no tuple in objectClass index
-        assertFalse( partition.getObjectClassIndex().reverse( entryId ) );
         assertFalse( partition.getObjectClassIndex().forward( "person", entryId ) );
         assertNull( lookedup.get( "objectClass" ) );
     }
@@ -347,13 +345,11 @@ public class PartitionTest
         Entry lookedup = partition.lookup( entryId );
 
         assertNotSame( csn, lookedup.get( csnAt ).getString() );
-        assertNotSame( csn, partition.getEntryCsnIndex().reverseLookup( entryId ) );
 
         lookedup = partition.modify( dn, add );
 
         String updateCsn = lookedup.get( csnAt ).getString();
         assertEquals( csn, updateCsn );
-        assertEquals( csn, partition.getEntryCsnIndex().reverseLookup( entryId ) );
 
         csn = csnF.newInstance().toString();
 
@@ -361,13 +357,11 @@ public class PartitionTest
         modEntry.add( csnAt, csn );
 
         assertNotSame( csn, updateCsn );
-        assertNotSame( csn, partition.getEntryCsnIndex().reverseLookup( entryId ) );
 
         lookedup = partition
             .modify( dn, new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
csnAt, csn ) );
 
         assertEquals( csn, lookedup.get( csnAt ).getString() );
-        assertEquals( csn, partition.getEntryCsnIndex().reverseLookup( entryId ) );
     }
 
 



Mime
View raw message