directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r610243 [1/2] - in /directory/sandbox/akarasulu/bigbang/apacheds: btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-stor...
Date Wed, 09 Jan 2008 00:41:36 GMT
Author: akarasulu
Date: Tue Jan  8 16:41:31 2008
New Revision: 610243

URL: http://svn.apache.org/viewvc?rev=610243&view=rev
Log:
changes ...

 o still refining the API as I use it in tests
 o added more test cases 
 o shooting for 100% code coverage


Added:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java   (with props)
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
Removed:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexComparator.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/TupleEnumeration.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Index.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexRecord.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/KeyOnlyComparator.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/MasterTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/TupleComparator.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/SerializableComparator.java

Added: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java?rev=610243&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java (added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java Tue Jan  8 16:41:31 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.core.partition.impl.btree;
+
+
+import org.apache.directory.server.schema.SerializableComparator;
+
+
+/**
+ * The default implementation of a pair of comparators which compares both
+ * keys and values of a Tuple.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DefaultTupleComparator<K,V> implements TupleComparator<K,V>
+{
+    SerializableComparator<K> keyComparator;
+    SerializableComparator<V> valueComparator;
+
+
+    public DefaultTupleComparator( SerializableComparator<K> keyComparator, SerializableComparator<V> valueComparator )
+    {
+        this.keyComparator = keyComparator;
+        this.valueComparator = valueComparator;
+    }
+
+
+    public SerializableComparator getKeyComparator()
+    {
+        return keyComparator;
+    }
+
+
+    public SerializableComparator getValueComparator()
+    {
+        return valueComparator;
+    }
+
+
+    public int compareKey( K key1, K key2 )
+    {
+        return keyComparator.compare( key1, key2 );
+    }
+
+
+    public int compareValue( V value1, V value2 )
+    {
+        return valueComparator.compare( value1, value2 );
+    }
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Index.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Index.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Index.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Index.java Tue Jan  8 16:41:31 2008
@@ -20,25 +20,23 @@
 package org.apache.directory.server.core.partition.impl.btree;
 
 
-import java.util.regex.Pattern;
 import java.io.File;
 import java.io.IOException;
 
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.server.core.cursor.Cursor;
 
 
 /**
- * Required interfaces for an index.
+ * 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
+ * values of the index.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface Index
+public interface Index<K>
 {
     int DEFAULT_INDEX_CACHE_SIZE = 100;
     
@@ -119,7 +117,7 @@
      * @return the normalized value.
      * @throws IOException if something goes wrong.
      */
-    Object getNormalized( Object attrVal ) throws IOException;
+    K getNormalized( K attrVal ) throws IOException;
 
 
     /**
@@ -139,72 +137,40 @@
      * @return the number of key/value pairs in this index with the value value
      * @throws IOException on failure to access index db files
      */
-    int count( Object attrVal ) throws IOException;
-
-
-    int count( Object attrVal, boolean isGreaterThan ) throws IOException;
-
-
-    Object forwardLookup( Object attrVal ) throws IOException;
-
-
-    Object reverseLookup( Object id ) throws IOException;
-
-
-    void add( Object attrVal, Object id ) throws IOException;
-
-
-    void add( Attribute attr, Object id ) throws IOException;
+    int count( K attrVal ) throws IOException;
 
 
-    void add( Attributes attrs, Object id ) throws IOException;
+    int greaterThanCount( K attrVal ) throws IOException;
 
 
-    void drop( Object entryId ) throws IOException;
-
-
-    void drop( Object attrVal, Object id ) throws IOException;
-
-
-    /**
-     * If the Attribute does not have any values then this reduces to a 
-     * drop(BigInteger) call.
-     */
-    void drop( Attribute attr, Object id ) throws IOException;
-
-
-    /**
-     * If the Attribute for this index within the Attributes does not have any 
-     * values then this reduces to a drop(BigInteger) call.
-     */
-    void drop( Attributes attrs, Object id ) throws IOException;
+    int lessThanCount( K attrVal ) throws IOException;
 
 
-    Cursor<IndexRecord> listReverseIndices( Object id ) throws IOException;
+    Long forwardLookup( K attrVal ) throws IOException;
 
 
-    Cursor<IndexRecord> listIndices() throws IOException;
+    K reverseLookup( Long id ) throws IOException;
 
 
-    Cursor<IndexRecord> listIndices( Object attrVal ) throws IOException;
+    void add( K attrVal, Long id ) throws IOException;
 
 
-    Cursor<IndexRecord> listIndices( Object attrVal, boolean isGreaterThan ) throws IOException;
+    void drop( Long id ) throws IOException;
 
 
-    Cursor<IndexRecord> listIndices( Pattern regex ) throws IOException;
+    void drop( K attrVal, Long id ) throws IOException;
 
 
-    Cursor<IndexRecord> listIndices( Pattern regex, String prefix ) throws IOException;
+    Cursor<IndexRecord> reverseCursor() throws IOException;
 
 
-    boolean hasValue( Object attrVal, Object id ) throws IOException;
+    Cursor<IndexRecord> cursor() throws IOException;
 
 
-    boolean hasValue( Object attrVal, Object id, boolean isGreaterThan ) throws IOException;
+    boolean hasValue( K attrVal, Long id ) throws IOException;
 
 
-    boolean hasValue( Pattern regex, Object id ) throws IOException;
+    boolean hasValue( K attrVal, Long id, boolean isGreaterThan ) throws IOException;
 
 
     void close() throws IOException;

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java Tue Jan  8 16:41:31 2008
@@ -20,6 +20,8 @@
 package org.apache.directory.server.core.partition.impl.btree;
 
 
+import org.apache.directory.shared.ldap.NotImplementedException;
+
 import java.util.NoSuchElementException;
 import java.util.regex.Pattern;
 
@@ -149,6 +151,7 @@
     // Private Methods 
     // ------------------------------------------------------------------------
 
+
     private void prefetch() throws NamingException
     {
         while ( underlying.hasMore() )
@@ -157,7 +160,8 @@
 
             if ( swapKeyVal )
             {
-                tmp.setSwapped( tuple, null );
+                throw new NotImplementedException();
+                // tmp.setSwapped( tuple, null );
             }
             else
             {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexRecord.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexRecord.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexRecord.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexRecord.java Tue Jan  8 16:41:31 2008
@@ -24,28 +24,30 @@
 
 
 /**
- * An index key value pair based on a tuple which can optionally reference the
- * indexed entry if one has been resusitated.
+ * An index key value pair based on a Tuple which can optionally reference the
+ * indexed entry if one has already been loaded.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class IndexRecord
+public class IndexRecord<K>
 {
     /** The underlying BTree Tuple */
-    private final Tuple tuple = new Tuple();
-    /** The referenced entry if resusitated */
-    private Attributes entry = null;
+    private final Tuple<K,Long> tuple = new Tuple<K,Long>();
+
+    /** The referenced entry if loaded from the store */
+    private Attributes entry;
 
 
     /**
      * Sets the key value tuple represented by this IndexRecord optionally 
-     * setting the entry if one was resusitated from the master table.
+     * setting the entry associated with the id if one was loaded from the
+     * master table.
      *
      * @param tuple the tuple for the IndexRecord
      * @param entry the resusitated entry if any
      */
-    public void setTuple( Tuple tuple, Attributes entry )
+    public void setTuple( Tuple<K,Long> tuple, Attributes entry )
     {
         this.tuple.setKey( tuple.getKey() );
         this.tuple.setValue( tuple.getValue() );
@@ -54,26 +56,11 @@
 
 
     /**
-     * Sets the key value tuple but swapping the key and the value and 
-     * optionally adding the entry if one was resusitated.
-     *
-     * @param tuple the tuple for the IndexRecord
-     * @param entry the resusitated entry if any
-     */
-    public void setSwapped( Tuple tuple, Attributes entry )
-    {
-        this.tuple.setKey( tuple.getValue() );
-        this.tuple.setValue( tuple.getKey() );
-        this.entry = entry;
-    }
-
-
-    /**
      * Gets the entry id for this IndexRecord. 
      *
      * @return the id of the entry indexed
      */
-    public Object getEntryId()
+    public Long getEntryId()
     {
         return tuple.getValue();
     }
@@ -84,7 +71,7 @@
      *
      * @return the key of the entry indexed
      */
-    public Object getIndexKey()
+    public K getIndexKey()
     {
         return tuple.getKey();
     }
@@ -95,7 +82,7 @@
      *
      * @param id the id of the entry
      */
-    public void setEntryId( Object id )
+    public void setEntryId( Long id )
     {
         tuple.setValue( id );
     }
@@ -106,7 +93,7 @@
      *
      * @param key the key of the IndexRecord
      */
-    public void setIndexKey( Object key )
+    public void setIndexKey( K key )
     {
         tuple.setKey( key );
     }
@@ -157,7 +144,7 @@
      * 
      * @param record the record whose contents we copy
      */
-    public void copy( IndexRecord record )
+    public void copy( IndexRecord<K> record )
     {
         entry = record.getAttributes();
         tuple.setKey( record.getIndexKey() );

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/KeyOnlyComparator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/KeyOnlyComparator.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/KeyOnlyComparator.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/KeyOnlyComparator.java Tue Jan  8 16:41:31 2008
@@ -31,14 +31,14 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class KeyOnlyComparator implements TupleComparator, Serializable
+public class KeyOnlyComparator<K,V> implements TupleComparator<K,V>, Serializable
 {
     private static final long serialVersionUID = 3544956549803161397L;
 
-    private SerializableComparator keyComparator = null;
+    private SerializableComparator<K> keyComparator;
 
 
-    public KeyOnlyComparator(SerializableComparator comparator)
+    public KeyOnlyComparator( SerializableComparator<K> comparator )
     {
         keyComparator = comparator;
     }
@@ -50,7 +50,7 @@
      *
      * @return the comparator for comparing keys.
      */
-    public SerializableComparator getKeyComparator()
+    public SerializableComparator<K> getKeyComparator()
     {
         return keyComparator;
     }
@@ -59,7 +59,7 @@
     /**
      * Will throw an UnsupportedOperationException every time.
      */
-    public SerializableComparator getValueComparator()
+    public SerializableComparator<V> getValueComparator()
     {
         throw new UnsupportedOperationException();
     }
@@ -75,7 +75,7 @@
      * is less than the second, or a postive value if the first is greater than
      * the second byte array.
      */
-    public int compareKey( Object key1, Object key2 )
+    public int compareKey( K key1, K key2 )
     {
         return keyComparator.compare( key1, key2 );
     }
@@ -91,7 +91,7 @@
      * is less than the second, or a postive value if the first is greater than
      * the second Object.
      */
-    public int compareValue( Object value1, Object value2 )
+    public int compareValue( V value1, V value2 )
     {
         throw new UnsupportedOperationException();
     }

Added: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java?rev=610243&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java (added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java Tue Jan  8 16:41:31 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.core.partition.impl.btree;
+
+
+import org.apache.directory.server.schema.SerializableComparator;
+
+
+/**
+ * A serializable comparator for long values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LongComparator extends SerializableComparator<Long>
+{
+    public static final LongComparator INSTANCE = new LongComparator();
+    private static final long serialVersionUID = 3690478030414165816L;
+
+
+    public LongComparator()
+    {
+        super( "1.3.6.1.4.1.18060.0.4.1.1.2" );
+    }
+
+
+    public int compare( Long l1, Long l2 )
+    {
+        return ( l1 < l2 ? -1 : ( l1.equals( l2 ) ? 0 : 1 ) );
+    }
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/MasterTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/MasterTable.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/MasterTable.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/MasterTable.java Tue Jan  8 16:41:31 2008
@@ -60,7 +60,7 @@
      * @return the newly created entry's Attributes
      * @throws NamingException if there is a write error on the underlying Db.
      */
-    Attributes put( Attributes entry, Object id ) throws NamingException;
+    Attributes put( Attributes entry, Object id ) throws IOException;
 
 
     /**
@@ -70,7 +70,7 @@
      * @return the Attributes of the deleted entry
      * @throws NamingException if there is a write error on the underlying Db
      */
-    Attributes delete( Object id ) throws NamingException;
+    Attributes delete( Object id ) throws IOException;
 
 
     /**
@@ -81,7 +81,7 @@
      * @throws NamingException if the admin table storing sequences cannot be
      * read.
      */
-    Object getCurrentId() throws NamingException;
+    Object getCurrentId() throws IOException;
 
 
     /**
@@ -92,7 +92,7 @@
      * @throws NamingException if the admin table storing sequences cannot be
      * read and writen to.
      */
-    Object getNextId() throws NamingException;
+    Object getNextId() throws IOException;
 
 
     /**
@@ -102,7 +102,7 @@
      * @return the value of the property
      * @throws NamingException when the underlying admin table cannot be read
      */
-    String getProperty( String property ) throws NamingException;
+    String getProperty( String property ) throws IOException;
 
 
     /**
@@ -112,5 +112,5 @@
      * @param value the value of the property
      * @throws NamingException when the underlying admin table cannot be writen
      */
-    void setProperty( String property, String value ) throws NamingException;
+    void setProperty( String property, String value ) throws IOException;
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java Tue Jan  8 16:41:31 2008
@@ -41,7 +41,7 @@
      * @return the comparator pair or null if this Table was not created with
      * one.
      */
-    TupleComparator getComparator();
+    TupleComparator<K,V> getComparator();
 
 
     /**
@@ -78,15 +78,20 @@
      */
     boolean isDupsEnabled();
 
-
+    
     /**
-     * Checks to see if this Table has enabled sorting on the values of
-     * duplicate keys.
+     * Checks whether or not calls to count the number of keys greater than or
+     * less than the key are exact.
+     * 
+     * Checking to see the number of values greater than or less than some key
+     * may be excessively costly.  Since this is not a critical function but 
+     * one that assists in optimizing searches some implementations can just 
+     * return a worst case (maximum) guess.  
      *
-     * @return true if duplicate key values are sorted, false otherwise.
+     * @return true if the count is an exact value or a worst case guess 
      */
-    boolean isSortedDupsEnabled();
-
+    boolean isCountExact();
+    
 
     // ------------------------------------------------------------------------
     // Simple Table Key/Value Assertions 
@@ -277,16 +282,27 @@
 
 
     /**
-     * Returns the number of records greater than or less than a key value.  The
-     * key need not exist for this call to return a non-zero value.
+     * Gets the number of records greater than or equal to a key value.  The 
+     * specific key argument provided need not exist for this call to return 
+     * a non-zero value.
      *
-     * @param key the Object key to count.
-     * @param isGreaterThan boolean set to true to count for greater than and
-     * equal to record keys, or false for less than or equal to keys.
-     * @return the number of keys greater or less than key.
-     * @throws IOException if there is a failure to read the underlying Db
+     * @param key the key to use in comparisons
+     * @return the number of keys greater than or equal to the key
+     * @throws IOException if there is a failure to read the underlying db
+     */
+    int greaterThanCount( K key ) throws IOException;
+
+
+    /**
+     * Gets the number of records less than or equal to a key value.  The 
+     * specific key argument provided need not exist for this call to return 
+     * a non-zero value.
+     *
+     * @param key the key to use in comparisons
+     * @return the number of keys less than or equal to the key
+     * @throws IOException if there is a failure to read the underlying db
      */
-    int count( K key, boolean isGreaterThan ) throws IOException;
+    int lessThanCount( K key ) throws IOException;
 
 
     /**

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/TupleComparator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/TupleComparator.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/TupleComparator.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/TupleComparator.java Tue Jan  8 16:41:31 2008
@@ -31,7 +31,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface TupleComparator extends Serializable
+public interface TupleComparator<K,V> extends Serializable
 {
     /**
      * Gets the comparator used to compare keys.  May be null in which
@@ -39,7 +39,7 @@
      *
      * @return the comparator for comparing keys.
      */
-    SerializableComparator getKeyComparator();
+    SerializableComparator<K> getKeyComparator();
 
 
     /**
@@ -48,7 +48,7 @@
      *
      * @return the binary comparator for comparing values.
      */
-    SerializableComparator getValueComparator();
+    SerializableComparator<V> getValueComparator();
 
 
     /**
@@ -61,7 +61,7 @@
      * is less than the second, or a postive value if the first is greater than
      * the second byte array.
      */
-    int compareKey( Object key1, Object key2 );
+    int compareKey( K key1, K key2 );
 
 
     /**
@@ -74,5 +74,5 @@
      * is less than the second, or a postive value if the first is greater than
      * the second Object.
      */
-    int compareValue( Object value1, Object value2 );
+    int compareValue( V value1, V value2 );
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java Tue Jan  8 16:41:31 2008
@@ -28,16 +28,12 @@
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.schema.SerializableComparator;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.SynchronizedLRUMap;
+import org.apache.directory.shared.ldap.NotImplementedException;
 
-import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
 import java.io.File;
 import java.io.IOException;
-import java.util.regex.Pattern;
 
 
 /** 
@@ -48,7 +44,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class JdbmIndex implements Index
+public class JdbmIndex<K> implements Index<K>
 {
     /**
      * default duplicate limit before duplicate keys switch to using a btree for values
@@ -68,13 +64,13 @@
      * the value of the btree is the entry id of the entry containing an attribute with
      * that value
      */
-    private JdbmTable forward;
+    private JdbmTable<K, Long> forward;
     /**
      * the reverse btree where the btree key is the entry id of the entry containing a
      * value for the indexed attribute, and the btree value is the value of the indexed
      * attribute
      */
-    private JdbmTable reverse;
+    private JdbmTable<Long,K> reverse;
     /**
      * the JDBM record manager for the file containing this index
      */
@@ -139,7 +135,7 @@
     }
 
 
-    public void init( AttributeType attributeType, File wkDirPath ) throws NamingException
+    public void init( AttributeType attributeType, File wkDirPath ) throws IOException
     {
         this.keyCache = new SynchronizedLRUMap( cacheSize );
         this.attribute = attributeType;
@@ -149,21 +145,10 @@
         }
 
         File file = new File( this.wkDirPath.getPath() + File.separator + attribute.getName() );
-
-
-        try
-        {
-            String path = file.getAbsolutePath();
-            BaseRecordManager base = new BaseRecordManager( path );
-            base.disableTransactions();
-            this.recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
-        }
-        catch ( IOException e )
-        {
-            NamingException ne = new NamingException( "Could not initialize the record manager" );
-            ne.setRootCause( e );
-            throw ne;
-        }
+        String path = file.getAbsolutePath();
+        BaseRecordManager base = new BaseRecordManager( path );
+        base.disableTransactions();
+        this.recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
 
         initTables();
         initialized = true;
@@ -173,25 +158,33 @@
     /**
      * Initializes the forward and reverse tables used by this Index.
      * 
-     * @throws NamingException if we cannot initialize the forward and reverse 
+     * @throws IOException if we cannot initialize the forward and reverse
      * tables
      */
-    private void initTables() throws NamingException
+    private void initTables() throws IOException
     {
-        SerializableComparator comp;
-        comp = new SerializableComparator( attribute.getEquality().getOid() );
+        SerializableComparator<K> comp;
+
+        try
+        {
+            comp = new SerializableComparator<K>( attribute.getEquality().getOid() );
+        }
+        catch ( NamingException e )
+        {
+            throw new IOException( "Failed to find an equality matching rule for attribute type", e );
+        }
 
         /*
          * 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.
          */
-        forward = new JdbmTable( 
+        forward = new JdbmTable<K, Long>(
             attribute.getName() + FORWARD_BTREE, 
             true,
             numDupLimit,
             recMan, 
-            new IndexComparator( comp, true ),
+            new ForwardIndexComparator<K>( comp ),
             null, null );
             //LongSerializer.INSTANCE );
 
@@ -201,12 +194,12 @@
          * is single valued according to its specification based on a schema 
          * then duplicate keys should not be allowed within the reverse table.
          */
-        reverse = new JdbmTable( 
+        reverse = new JdbmTable<Long,K>(
             attribute.getName() + REVERSE_BTREE, 
             !attribute.isSingleValue(),
             numDupLimit,
             recMan,
-            new IndexComparator( comp, false ),
+            new ReverseIndexComparator<K>( comp ),
             null, //LongSerializer.INSTANCE,
             null);
     }
@@ -356,18 +349,24 @@
     /**
      * @see Index#count(java.lang.Object)
      */
-    public int count( Object attrVal ) throws IOException
+    public int count( K attrVal ) throws IOException
     {
         return forward.count( getNormalized( attrVal ) );
     }
 
 
+    public int greaterThanCount( K attrVal ) throws IOException
+    {
+        return forward.greaterThanCount( getNormalized( attrVal ) );
+    }
+    
+    
     /**
      * @see org.apache.directory.server.core.partition.impl.btree.Index#count(java.lang.Object, boolean)
      */
-    public int count( Object attrVal, boolean isGreaterThan ) throws IOException
+    public int lessThanCount( K attrVal ) throws IOException
     {
-        return forward.count( getNormalized( attrVal ), isGreaterThan );
+        return forward.lessThanCount( getNormalized( attrVal ) );
     }
 
 
@@ -379,16 +378,16 @@
     /**
      * @see Index#forwardLookup(java.lang.Object)
      */
-    public Long forwardLookup( Object attrVal ) throws IOException
+    public Long forwardLookup( K attrVal ) throws IOException
     {
-        return ( Long ) forward.get( getNormalized( attrVal ) );
+        return forward.get( getNormalized( attrVal ) );
     }
 
 
     /**
-     * @see Index#reverseLookup(Object)
+     * @see Index#reverseLookup(Long)
      */
-    public Object reverseLookup( Object id ) throws IOException
+    public K reverseLookup( Long id ) throws IOException
     {
         return reverse.get( id );
     }
@@ -400,9 +399,9 @@
 
 
     /**
-     * @see Index#add(Object,Object)
+     * @see Index#add(Object, Long)
      */
-    public synchronized void add( Object attrVal, Object id ) throws IOException
+    public synchronized void add( K attrVal, Long id ) throws IOException
     {
         forward.put( getNormalized( attrVal ), id );
         reverse.put( id, getNormalized( attrVal ) );
@@ -410,36 +409,9 @@
 
 
     /**
-     * @see Index#add(Attribute, Object)
+     * @see Index#drop(Object,Long)
      */
-    public synchronized void add( Attribute attr, Object id ) throws IOException
-    {
-        // Can efficiently batch add to the reverse table 
-        NamingEnumeration values = attr.getAll();
-        reverse.put( id, values );
-
-        // Have no choice but to add each value individually to forward table
-        values = attr.getAll();
-        while ( values.hasMore() )
-        {
-            forward.put( values.next(), id );
-        }
-    }
-
-
-    /**
-     * @see Index#add(Attributes, Object)
-     */
-    public synchronized void add( Attributes attrs, Object id ) throws IOException
-    {
-        add( AttributeUtils.getAttribute( attrs, attribute ), id );
-    }
-
-
-    /**
-     * @see Index#drop(Object,Object)
-     */
-    public synchronized void drop( Object attrVal, Object id ) throws IOException
+    public synchronized void drop( K attrVal, Long id ) throws IOException
     {
         forward.remove( getNormalized( attrVal ), id );
         reverse.remove( id, getNormalized( attrVal ) );
@@ -447,112 +419,37 @@
 
 
     /**
-     * @see Index#drop(Object)
+     * @see Index#drop(Long)
      */
-    public void drop( Object entryId ) throws IOException
+    public void drop( Long id ) throws IOException
     {
-        NamingEnumeration<Object> values = reverse.listValues( entryId );
-
-        while ( values.hasMore() )
-        {
-            forward.remove( values.next(), entryId );
-        }
-
-        reverse.remove( entryId );
-    }
-
-
-    /**
-     * @see Index#drop(Attribute, Object)
-     */
-    public void drop( Attribute attr, Object id ) throws IOException
-    {
-        // Can efficiently batch remove from the reverse table 
-        NamingEnumeration values = attr.getAll();
-
-        // If their are no values in attr this is a request to drop all
-        if ( !values.hasMore() )
-        {
-            drop( id );
-            return;
-        }
-
-        reverse.remove( id, values );
+        Cursor<Tuple<Long,K>> values = reverse.cursor();
+        Tuple<Long,K> tuple = new Tuple<Long,K>( id, null );
+        values.before( tuple );
 
-        // Have no choice but to remove values individually from forward table
-        values = attr.getAll();
-        while ( values.hasMore() )
+        while ( values.next() )
         {
-            forward.remove( values.next(), id );
+            forward.remove( values.get().getValue(), id );
         }
-    }
-
 
-    /**
-     * @see Index#drop(Attributes, Object)
-     */
-    public void drop( Attributes attrs, Object id ) throws IOException
-    {
-        drop( AttributeUtils.getAttribute( attrs, attribute ), id );
+        reverse.remove( id );
     }
 
 
     // ------------------------------------------------------------------------
-    // Index Listing Operations
+    // Index Cursor Operations
     // ------------------------------------------------------------------------
 
 
-    /**
-     * @see Index#listReverseIndices(Object)
-     */
-    public Cursor<IndexRecord> listReverseIndices( Object id ) throws IOException
-    {
-        return new IndexEnumeration<Tuple>( reverse.listTuples( id ), true );
-    }
-
-
-    /**
-     * @see Index#listIndices()
-     */
-    public Cursor<IndexRecord> listIndices() throws IOException
+    public Cursor<IndexRecord> reverseCursor() throws IOException
     {
-        return new IndexEnumeration<Tuple>( forward.listTuples() );
+        throw new NotImplementedException();
     }
 
 
-    /**
-     * @see Index#listIndices(Object)
-     */
-    public Cursor<IndexRecord> listIndices( Object attrVal ) throws IOException
+    public Cursor<IndexRecord> cursor() throws IOException
     {
-        return new IndexEnumeration<Tuple>( forward.listTuples( getNormalized( attrVal ) ) );
-    }
-
-
-    /**
-     * @see Index#listIndices(Object,boolean)
-     */
-    public Cursor<IndexRecord> listIndices( Object attrVal, boolean isGreaterThan ) throws IOException
-    {
-        return new IndexEnumeration<Tuple>( forward.listTuples( getNormalized( attrVal ), isGreaterThan ) );
-    }
-
-
-    /**
-     * @see Index#listIndices(Pattern)
-     */
-    public Cursor<IndexRecord> listIndices( Pattern regex ) throws IOException
-    {
-        return new IndexEnumeration<Tuple>( forward.listTuples(), false, regex );
-    }
-
-
-    /**
-     * @see Index#listIndices(Pattern,String)
-     */
-    public Cursor<IndexRecord> listIndices( Pattern regex, String prefix ) throws IOException
-    {
-        return new IndexEnumeration<Tuple>( forward.listTuples( getNormalized( prefix ), true ), false, regex );
+        throw new NotImplementedException();
     }
 
 
@@ -562,37 +459,23 @@
 
     
     /**
-     * @see Index#hasValue(java.lang.Object,
-     * Object)
+     * @see Index#hasValue(Object,Long)
      */
-    public boolean hasValue( Object attrVal, Object id ) throws IOException
+    public boolean hasValue( K attrVal, Long id ) throws IOException
     {
         return forward.has( getNormalized( attrVal ), id );
     }
 
 
     /**
-     * @see Index#hasValue(java.lang.Object,
-     * Object, boolean)
+     * @see Index#hasValue(Object, Long, boolean)
      */
-    public boolean hasValue( Object attrVal, Object id, boolean isGreaterThan ) throws IOException
+    public boolean hasValue( K attrVal, Long id, boolean isGreaterThan ) throws IOException
     {
         return forward.has( getNormalized( attrVal ), id, isGreaterThan );
     }
 
 
-    /**
-     * @see Index#hasValue(Pattern,Object)
-     */
-    public boolean hasValue( Pattern regex, Object id ) throws IOException
-    {
-        IndexEnumeration<Tuple> list = new IndexEnumeration<Tuple>( reverse.listTuples( id ), true, regex );
-        boolean hasValue = list.hasMore();
-        list.close();
-        return hasValue;
-    }
-
-
     // ------------------------------------------------------------------------
     // Maintenance Methods 
     // ------------------------------------------------------------------------
@@ -623,20 +506,22 @@
      * TODO I don't think the keyCache is required anymore since the normalizer
      * will cache values for us.
      */
-    public Object getNormalized( Object attrVal ) throws IOException
+    public K getNormalized( K attrVal ) throws IOException
     {
         if ( attrVal instanceof Long )
         {
             return attrVal;
         }
-        
-        Object normalized = keyCache.get( attrVal );
+
+        //noinspection unchecked
+        K normalized = ( K ) keyCache.get( attrVal );
 
         if ( null == normalized )
         {
             try
             {
-                normalized = attribute.getEquality().getNormalizer().normalize( attrVal );
+                //noinspection unchecked
+                normalized = ( K ) attribute.getEquality().getNormalizer().normalize( attrVal );
             }
             catch ( NamingException e )
             {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java Tue Jan  8 16:41:31 2008
@@ -82,6 +82,7 @@
         }
     };
 
+
     private final JdbmTable adminTbl;
 
 
@@ -91,29 +92,15 @@
      * @param recMan the jdbm record manager
      * @throws NamingException if there is an error opening the Db file.
      */
-    public JdbmMasterTable( RecordManager recMan ) throws NamingException
+    public JdbmMasterTable( RecordManager recMan ) throws IOException
     {
         super( DBF, recMan, LONG_COMPARATOR, LongSerializer.INSTANCE, new AttributesSerializer() );
         adminTbl = new JdbmTable( "admin", recMan, STRING_COMPARATOR, null, null );
-        try
-        {
-            String seqValue = ( String ) adminTbl.get( SEQPROP_KEY );
-        }
-        catch ( IOException e )
-        {
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-        }
+        String seqValue = ( String ) adminTbl.get( SEQPROP_KEY );
 
         if ( null == seqValue )
         {
-            try
-            {
-                adminTbl.put( SEQPROP_KEY, "0" );
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-            }
+            adminTbl.put( SEQPROP_KEY, "0" );
         }
     }
 
@@ -141,7 +128,7 @@
      * @return the Attributes of the entry put
      * @throws NamingException if there is a write error on the underlying Db.
      */
-    public Attributes put( Attributes entry, Object id ) throws NamingException
+    public Attributes put( Attributes entry, Object id ) throws IOException
     {
         return ( Attributes ) super.put( id, entry );
     }
@@ -154,7 +141,7 @@
      * @return the Attributes of the deleted entry
      * @throws NamingException if there is a write error on the underlying Db
      */
-    public Attributes delete( Object id ) throws NamingException
+    public Attributes delete( Object id ) throws IOException
     {
         return ( Attributes ) super.remove( id );
     }
@@ -168,32 +155,18 @@
      * @throws NamingException if the admin table storing sequences cannot be
      *                         read.
      */
-    public Long getCurrentId() throws NamingException
+    public Long getCurrentId() throws IOException
     {
-        Long id;
+        Long id = null;
 
         synchronized ( adminTbl )
         {
-            try
-            {
-                id = new Long( ( String ) adminTbl.get( SEQPROP_KEY ) );
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-            }
+            id = new Long( ( String ) adminTbl.get( SEQPROP_KEY ) );
 
             //noinspection ConstantConditions
             if ( null == id )
             {
-                try
-                {
-                    adminTbl.put( SEQPROP_KEY, "0" );
-                }
-                catch ( IOException e )
-                {
-                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-                }
+                adminTbl.put( SEQPROP_KEY, "0" );
                 id = 0L;
             }
         }
@@ -212,45 +185,25 @@
      * @throws NamingException if the admin table storing sequences cannot be
      *                         read and writen to.
      */
-    public Long getNextId() throws NamingException
+    public Long getNextId() throws IOException
     {
-        Long lastVal;
         Long nextVal;
+        Long lastVal = null;
 
         synchronized ( adminTbl )
         {
-            try
-            {
-                lastVal = new Long( ( String ) adminTbl.get( SEQPROP_KEY ) );
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-            }
+            lastVal = new Long( ( String ) adminTbl.get( SEQPROP_KEY ) );
 
             //noinspection ConstantConditions
             if ( null == lastVal )
             {
-                try
-                {
-                    adminTbl.put( SEQPROP_KEY, "1" );
-                }
-                catch ( IOException e )
-                {
-                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-                }
+                adminTbl.put( SEQPROP_KEY, "1" );
                 return 1L;
-            } else
+            }
+            else
             {
                 nextVal = lastVal + 1L;
-                try
-                {
-                    adminTbl.put( SEQPROP_KEY, nextVal.toString() );
-                }
-                catch ( IOException e )
-                {
-                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-                }
+                adminTbl.put( SEQPROP_KEY, nextVal.toString() );
             }
         }
 
@@ -265,18 +218,11 @@
      * @return the value of the property
      * @throws NamingException when the underlying admin table cannot be read
      */
-    public String getProperty( String property ) throws NamingException
+    public String getProperty( String property ) throws IOException
     {
         synchronized ( adminTbl )
         {
-            try
-            {
-                return ( String ) adminTbl.get( property );
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-            }
+            return ( String ) adminTbl.get( property );
         }
     }
 
@@ -288,18 +234,11 @@
      * @param value    the value of the property
      * @throws NamingException when the underlying admin table cannot be writen
      */
-    public void setProperty( String property, String value ) throws NamingException
+    public void setProperty( String property, String value ) throws IOException
     {
         synchronized ( adminTbl )
         {
-            try
-            {
-                adminTbl.put( property, value );
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-            }
+            adminTbl.put( property, value );
         }
     }
 



Mime
View raw message