You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/10/31 20:54:54 UTC

svn commit: r1029473 - in /directory/apacheds/trunk: core-annotations/src/main/java/org/apache/directory/server/core/annotations/ core-annotations/src/main/java/org/apache/directory/server/core/factory/ jdbm-partition/src/main/java/org/apache/directory...

Author: elecharny
Date: Sun Oct 31 19:54:53 2010
New Revision: 1029473

URL: http://svn.apache.org/viewvc?rev=1029473&view=rev
Log:
o Removed the cacheSize parameter from the CreateIndex @
o Directly use the JdbmIndex instead of the GenericIndex when instanciating an Index in tests
o Added some checks to avoid dropping when the element does not exist in a index
o Added some Javadoc

Modified:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
    directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java?rev=1029473&r1=1029472&r2=1029473&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java (original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java Sun Oct 31 19:54:53 2010
@@ -33,7 +33,7 @@ import org.apache.directory.server.xdbm.
  *     name = "example",
  *     @Indexes( {
  *         @CreateIndex( attribute = "cn" ),
- *         @CreateIndex( attribute = "sn', cacheSize = "100" )
+ *         @CreateIndex( attribute = "sn' )
  *     })
  * )
  * </pre>

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java?rev=1029473&r1=1029472&r2=1029473&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java (original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java Sun Oct 31 19:54:53 2010
@@ -41,7 +41,7 @@ import org.apache.directory.server.core.
  *         }),
  *     @Indexes( {
  *         @CreateIndex( attribute = "cn" ),
- *         @CreateIndex( attribute = "sn', cacheSize = "100" )
+ *         @CreateIndex( attribute = "sn' )
  *     })
  * )
  * </pre>

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java?rev=1029473&r1=1029472&r2=1029473&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java (original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java Sun Oct 31 19:54:53 2010
@@ -35,9 +35,8 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.server.xdbm.GenericIndex;
-import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
@@ -121,21 +120,10 @@ public class DSAnnotationProcessor
 
                     for ( CreateIndex createIndex : indexes )
                     {
-                        Index index;
-                        
-                        if ( createIndex.type() == Index.class )
-                        {
-                            // The annotation does not specify a specific index type.
-                            // We use the generic index implementation.
-                            index = new GenericIndex( createIndex.attribute(), createIndex.cacheSize() );
-                        }
-                        else
-                        {
-                            // The annotation contains a specific index type, we use that type.
-                            index = createIndex.type().newInstance();
-                            index.setAttributeId( createIndex.attribute() );
-                            index.setCacheSize( createIndex.cacheSize() );
-                        }
+                        // The annotation does not specify a specific index type.
+                        // We use the generic index implementation.
+                        JdbmIndex index = new JdbmIndex();
+                        index.setAttributeId( createIndex.attribute() );
                         
                         btreePartition.addIndexedAttributes( index );
                     }

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1029473&r1=1029472&r2=1029473&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java Sun Oct 31 19:54:53 2010
@@ -396,9 +396,8 @@ public class JdbmIndex<K, O> implements 
     // ------------------------------------------------------------------------
     // Scan Count Methods
     // ------------------------------------------------------------------------
-
     /**
-     * @see org.apache.directory.server.xdbm.Index#count()
+     * {@inheritDoc}
      */
     public int count() throws IOException
     {
@@ -407,7 +406,7 @@ public class JdbmIndex<K, O> implements 
 
 
     /**
-     * @see Index#count(java.lang.Object)
+     * {@inheritDoc}
      */
     public int count( K attrVal ) throws Exception
     {
@@ -461,8 +460,11 @@ public class JdbmIndex<K, O> implements 
      */
     public synchronized void add( K attrVal, Long id ) throws Exception
     {
-        forward.put( getNormalized( attrVal ), id );
-        reverse.put( id, getNormalized( attrVal ) );
+        K normalizedValue = getNormalized( attrVal );
+
+        // The pair to be removed must exists
+        forward.put( normalizedValue, id );
+        reverse.put( id, normalizedValue );
     }
 
 
@@ -471,8 +473,14 @@ public class JdbmIndex<K, O> implements 
      */
     public synchronized void drop( K attrVal, Long id ) throws Exception
     {
-        forward.remove( getNormalized( attrVal ), id );
-        reverse.remove( id, getNormalized( attrVal ) );
+        K normalizedValue = getNormalized( attrVal );
+        
+        // The pair to be removed must exists
+        if ( forward.has( normalizedValue, id ) )
+        {
+            forward.remove( normalizedValue, id );
+            reverse.remove( id, normalizedValue );
+        }
     }
 
 

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java?rev=1029473&r1=1029472&r2=1029473&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java Sun Oct 31 19:54:53 2010
@@ -27,18 +27,20 @@ import org.apache.directory.shared.ldap.
 
 
 /**
- * An index into the master table which returns one or more entry's positions
- * in the master table for those entries which posses an attribute with the
- * specified value.  Cursors over indices can also be gotten to traverse the
+ * An index used to retrieve elements into the master table. Each stored element that is
+ * indexed has a unique identifier (ID). We may have more than one element associated with
+ * a value (K). We may cache the retrieved element (O). <br/>
+ * Cursors over indices can also be gotten to traverse the
  * values of the index.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @param <K> The Index key type
- * @param <O> The indexed value type
- * @param <ID> The unisuqe identifier type
+ * @param <K> The Indexed value type, used to retrieve an element
+ * @param <O> The indexed element type, when retrieved
+ * @param <ID> The unique identifier type in the master table
  */
 public interface Index<K, O, ID>
 {
+    /** The default cache size (ie, the number of elements we stored in the cache) */
     int DEFAULT_INDEX_CACHE_SIZE = 100;
 
 
@@ -166,39 +168,54 @@ public interface Index<K, O, ID>
     K reverseLookup( ID id ) throws Exception;
 
 
+    /**
+     * Add an entry into the index, associated with the element ID. The added
+     * value is the key to retrieve the element having the given ID.
+     * 
+     * @param attrVal The added value
+     * @param id The element ID pointed by the added value
+     * @throws Exception If the addition can't be done
+     */
     void add( K attrVal, ID id ) throws Exception;
 
 
     /**
      * Remove all the reference to an entry from the index.
-     * 
+     * <br/>
      * As an entry might be referenced more than once in the forward index,
      * depending on which index we are dealing with, we need to iterate 
      * over all the values contained into the reverse index for this entryId.
-     * 
+     * <br/>
      * For instance, considering the ObjectClass index for an entry having
      * three ObjectClasses (top, person, inetOrgPerson), then the reverse
      * index will contain :
-     * 
+     * <pre>
      * [entryId, [top, person, inetOrgPerson]]
-     * 
+     * </pre>
      * and the forward index will contain many entries like :
+     * <pre>
      * [top, [..., entryId, ...]]
      * [person,  [..., entryId, ...]]
      * [inetOrgPerson,  [..., entryId, ...]]
-     * 
+     * </pre>
      * So dropping the entryId means that we must first get all the values from
      * the reverse index (and we will get [top, person, inetOrgPerson]) then to
      * iterate through all those values to remove entryId from the associated 
      * list of entryIds.
      * 
-     * 
      * @param entryId The master table entry ID to remove
      * @throws Exception
      */
     void drop( ID entryId ) throws Exception;
 
 
+    /**
+     * Remove the pair <K,ID> from the index for the given value and id. 
+     * 
+     * @param attrVal The value we want to remove from the index
+     * @param id The associated ID
+     * @throws Exception If the removal can't be done
+     */
     void drop( K attrVal, ID id ) throws Exception;