felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r500136 - /incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/
Date Fri, 26 Jan 2007 03:59:03 GMT
Author: akarasulu
Date: Thu Jan 25 19:59:02 2007
New Revision: 500136

URL: http://svn.apache.org/viewvc?view=rev&rev=500136
Log:
adding btree wrapper structures for bundledb

Added:
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/BigIntegerComparator.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Index.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertion.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertionCursor.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexComparator.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexConfiguration.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexNotFoundException.java   (with props)
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecord.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecordCursor.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IteratorTupleCursor.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/KeyOnlyComparator.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/MasterTable.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/NoDupsTupleCursor.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Table.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple2IndexRecordCursor.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleBrowser.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleComparator.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleCursor.java
    incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleRenderer.java

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/BigIntegerComparator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/BigIntegerComparator.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/BigIntegerComparator.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/BigIntegerComparator.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,68 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.math.BigInteger;
+
+
+/**
+ * Compares BigInteger keys and values within a table.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision: 437007 $
+ */
+public class BigIntegerComparator implements java.util.Comparator, java.io.Serializable
+{
+    /** A instance of this comparator */
+    public static final BigIntegerComparator INSTANCE = new BigIntegerComparator();
+
+    /**
+     * Version id for serialization.
+     */
+    static final long serialVersionUID = 1L;
+
+
+    /**
+     * Compare two objects.
+     * 
+     * @param an_obj1
+     *            First object
+     * @param an_obj2
+     *            Second object
+     * @return 1 if obj1 > obj2, 0 if obj1 == obj2, -1 if obj1 < obj2
+     */
+    public int compare( Object an_obj1, Object an_obj2 )
+    {
+        if ( an_obj1 == null )
+        {
+            throw new IllegalArgumentException( "Argument 'an_obj1' is null" );
+        }
+
+        if ( an_obj2 == null )
+        {
+            throw new IllegalArgumentException( "Argument 'an_obj2' is null" );
+        }
+
+        BigInteger l_int1 = ( BigInteger ) an_obj1;
+        BigInteger l_int2 = ( BigInteger ) an_obj2;
+        return l_int1.compareTo( l_int2 );
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Index.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Index.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Index.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Index.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,62 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.regex.Pattern;
+
+
+/**
+ * Required interfaces for an index.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface Index
+{
+    String getProperty();
+    int count() throws IOException;
+    int count( String propertyValue ) throws IOException;
+    int count( String propertyValue, boolean isGreaterThan ) throws IOException;
+
+    BigInteger forwardLookup( String propertyValue ) throws IOException;
+    String reverseLookup( BigInteger id ) throws IOException;
+
+    void add( String propertyValue, BigInteger id ) throws IOException;
+    void drop( BigInteger id ) throws IOException;
+    void drop( String propertyValue ) throws IOException;
+    void drop( String propertyValue, BigInteger id ) throws IOException;
+
+    Tuple2IndexRecordCursor listReverseIndices( BigInteger id ) throws IOException;
+    Tuple2IndexRecordCursor listIndices() throws IOException;
+    Tuple2IndexRecordCursor listIndices( String propertyValue ) throws IOException;
+    Tuple2IndexRecordCursor listIndices( String propertyValue, boolean isGreaterThan ) throws IOException;
+    Tuple2IndexRecordCursor listIndices( Pattern regex ) throws IOException;
+    Tuple2IndexRecordCursor listIndices( Pattern regex, String prefix ) throws IOException;
+    
+    boolean hasValue( String propertyValue, BigInteger id ) throws IOException;
+    boolean hasValue( String attrVal, BigInteger id, boolean isGreaterThan ) throws IOException;
+    boolean hasValue( Pattern regex, BigInteger id ) throws IOException;
+
+    void close() throws IOException;
+    void sync() throws IOException;
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertion.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertion.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertion.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertion.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,49 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+
+
+/**
+ * Asserts whether or not a candidate should be returned in searching based on
+ * hard coded logic.  This interface is not related to the filter AssertionNode.
+ * It is strictly used for purposes internal to the search engine.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface IndexAssertion
+{
+    /**
+     * Tests to see if a perspective candidate should be returned based on 
+     * the evaluation of hard coded logic.  If the entry has not been 
+     * resusitated then the getAttributes member of the record will be null.  As
+     * a side-effect an index assertion may populate the entry attribute after
+     * resusitating an entry from the master table.
+     * 
+     * @param record an index record of the entry
+     * @return true if the entry should be returned, false otherwise
+     * @throws IOException if their are failures while asserting the 
+     * condition
+     */
+    boolean assertCandidate( IndexRecord record ) throws IOException;
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertionCursor.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertionCursor.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertionCursor.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexAssertionCursor.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,154 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * A prefetching NamingEnumeration over an underlying NamingEnumeration which 
+ * determines if a element should be returned based on a Assertion.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class IndexAssertionCursor implements IndexRecordCursor
+{
+    /** The prefetched candidate */
+    private final IndexRecord prefetched = new IndexRecord();
+    /** The returned candidate */
+    private final IndexRecord candidate = new IndexRecord();
+    /** The iteration cursor */
+    private final IndexRecordCursor underlying;
+    /** LUT used to avoid returning duplicates */
+    private final Map<BigInteger,BigInteger> candidates;
+    /** */
+    private final IndexAssertion assertion;
+    /** */
+    private final boolean checkDups;
+    /** */
+    private boolean hasMore = true;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+    public IndexAssertionCursor( IndexRecordCursor underlying, IndexAssertion assertion ) throws IOException
+    {
+        this.underlying = underlying;
+        candidates = null;
+        this.assertion = assertion;
+        checkDups = false;
+        prefetch();
+    }
+
+
+    public IndexAssertionCursor( IndexRecordCursor underlying, IndexAssertion assertion, boolean enableDupCheck )
+        throws IOException
+    {
+        this.underlying = underlying;
+        candidates = new HashMap<BigInteger,BigInteger>();
+        this.assertion = assertion;
+        checkDups = enableDupCheck;
+        prefetch();
+    }
+
+
+    public IndexRecord next() throws IOException
+    {
+        candidate.copy( prefetched );
+        prefetch();
+        return candidate;
+    }
+
+
+    public boolean hasMore()
+    {
+        return hasMore;
+    }
+
+
+    public void close() throws IOException
+    {
+        hasMore = false;
+        underlying.close();
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Private and Protected Methods
+    // ------------------------------------------------------------------------
+
+    
+    private void prefetch() throws IOException
+    {
+        IndexRecord rec = null;
+
+        /*
+         * Scan underlying Cursor until we arrive at the next valid candidate
+         * if the cursor is exhuasted we clean up after completing the loop
+         */
+        while ( underlying.hasMore() )
+        {
+            rec = ( IndexRecord ) underlying.next();
+
+            // If value is valid then we set it as the next candidate to return
+            if ( assertion.assertCandidate( rec ) )
+            {
+                if ( checkDups )
+                {
+                    boolean dup = candidates.containsKey( rec.getEntryId() );
+
+                    if ( dup )
+                    {
+                        /*
+                         * Dup checking is on and candidate is a duplicate that
+                         * has already been seen so we need to skip it.
+                         */
+                        continue;
+                    }
+                    else
+                    {
+                        /*
+                         * Dup checking is on and the candidate is not in the 
+                         * dup LUT so we need to set it as the next to return 
+                         * and add it to the LUT in case we encounter it another
+                         * time.
+                         */
+                        prefetched.copy( rec );
+                        candidates.put( rec.getEntryId(), rec.getEntryId() );
+                        return;
+                    }
+                }
+
+                prefetched.copy( rec );
+                return;
+            }
+        }
+
+        // At this pt the underlying Cursor has been exhausted so we close up
+        close();
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexComparator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexComparator.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexComparator.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexComparator.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,123 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.util.Comparator;
+
+
+/**
+ * TupleComparator for index records.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class IndexComparator implements TupleComparator
+{
+    private static final long serialVersionUID = 3257283621751633459L;
+
+    private static final Comparator BIG_INTEGER_COMPARATOR = BigIntegerComparator.INSTANCE;
+    /** Whether or not the key/value is swapped */
+    private final boolean isForwardMap;
+    /** The key comparison to use */
+    private final Comparator keyComp;
+
+
+    /**
+     * Creates an IndexComparator.
+     *
+     * @param keyComp the table comparator to use for keys
+     * @param isForwardMap whether or not the comparator should swap the 
+     * key value pair while conducting comparisons.
+     */
+    public IndexComparator( Comparator keyComp, boolean isForwardMap )
+    {
+        this.keyComp = keyComp;
+        this.isForwardMap = isForwardMap;
+    }
+
+
+    /**
+     * Gets the comparator used to compare keys.  May be null in which
+     * case the compareKey method will throw an UnsupportedOperationException.
+     *
+     * @return the comparator for comparing keys.
+     */
+    public Comparator getKeyComparator()
+    {
+        if ( isForwardMap )
+        {
+            return keyComp;
+        }
+
+        return BIG_INTEGER_COMPARATOR;
+    }
+
+
+    /**
+     * Gets the binary comparator used to compare valuess.  May be null in which
+     * case the compareValue method will throw an UnsupportedOperationException.
+     *
+     * @return the binary comparator for comparing values.
+     */
+    public Comparator getValueComparator()
+    {
+        if ( isForwardMap )
+        {
+            return BIG_INTEGER_COMPARATOR;
+        }
+
+        return keyComp;
+    }
+
+
+    /**
+     * Compares key Object to determine their sorting order returning a
+     * value = to, < or > than 0.
+     *
+     * @param key1 the first key to compare
+     * @param key2 the other key to compare to the first
+     * @return 0 if both are equal, a negative value less than 0 if the first
+     * is less than the second, or a postive value if the first is greater than
+     * the second byte array.
+     */
+    @SuppressWarnings("unchecked")
+    public int compareKey( Object key1, Object key2 )
+    {
+        return getKeyComparator().compare( key1, key2 );
+    }
+
+
+    /**
+     * Comparse value Objects to determine their sorting order returning a
+     * value = to, < or > than 0.
+     *
+     * @param value1 the first value to compare
+     * @param value2 the other value to compare to the first
+     * @return 0 if both are equal, a negative value less than 0 if the first
+     * is less than the second, or a postive value if the first is greater than
+     * the second Object.
+     */
+    @SuppressWarnings("unchecked")
+    public int compareValue( Object value1, Object value2 )
+    {
+        return getValueComparator().compare( value1, value2 );
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexConfiguration.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexConfiguration.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexConfiguration.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,85 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+/**
+ * An immutable configuration object for partition indices on entry attributes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IndexConfiguration
+{
+    public static final int DEFAULT_INDEX_CACHE_SIZE = 100;
+    public static final int DEFAULT_DUPLICATE_LIMIT = 256;
+    
+    private String propertyId;
+    private int cacheSize = DEFAULT_INDEX_CACHE_SIZE;
+    private int duplicateLimit = DEFAULT_DUPLICATE_LIMIT;
+    
+    
+    protected void setPropertyId( String attributeId )
+    {
+        this.propertyId = attributeId;
+    }
+    
+    
+    public String getPropertyId()
+    {
+        return propertyId;
+    }
+
+
+    protected void setCacheSize( int cacheSize )
+    {
+        this.cacheSize = cacheSize;
+    }
+
+
+    protected void setDuplicateLimit( int duplicateLimit )
+    {
+        this.duplicateLimit = duplicateLimit;
+    }
+
+
+    public int getCacheSize()
+    {
+        return cacheSize;
+    }
+
+
+    public int getDuplicateLimit()
+    {
+        return duplicateLimit;
+    }
+    
+    
+    public int hashCode()
+    {
+        return this.propertyId.hashCode();
+    }
+    
+    
+    public String toString()
+    {
+        return this.propertyId;
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexNotFoundException.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexNotFoundException.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexNotFoundException.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,74 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+/**
+ * NamingException for missing indicies if full table scans are disallowed.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class IndexNotFoundException extends RuntimeException
+{
+    private static final long serialVersionUID = 3906088970608981815L;
+
+    /** the name of the index that was not found */
+    private final String indexName;
+
+
+    /**
+     * Constructs an Exception with a detailed message.
+     * 
+     * @param indexName the name of the index that was not found 
+     */
+    public IndexNotFoundException(String indexName)
+    {
+        super( "Cannot efficiently search the DIB w/o an index on attribute " + indexName
+            + "\n. To allow such searches please contact the "
+            + "directory\nadministrator to create the index or to enable "
+            + "referrals on searches using these\nattributes to a replica with " + "the required set of indices." );
+        this.indexName = indexName;
+    }
+
+
+    /**
+     * Constructs an Exception with a detailed message.
+     * 
+     * @param message the message associated with the exception.
+     * @param indexName the name of the index that was not found 
+     */
+    public IndexNotFoundException(String message, String indexName)
+    {
+        super( message );
+        this.indexName = indexName;
+    }
+
+
+    /**
+     * Gets the name of the attribute the index was missing for.
+     *
+     * @return the name of the attribute the index was missing for.
+     */
+    public String getIndexName()
+    {
+        return indexName;
+    }
+}

Propchange: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexNotFoundException.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecord.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecord.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecord.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecord.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,167 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.math.BigInteger;
+import java.util.Properties;
+
+
+/**
+ * An index key value pair based on a tuple which can optionally reference the
+ * indexed entry if one has been resusitated.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class IndexRecord
+{
+    /** The underlying BTree Tuple */
+    private final Tuple tuple = new Tuple();
+    /** The referenced entry if resusitated */
+    private Properties entry = null;
+
+
+    /**
+     * Sets the key value tuple represented by this IndexRecord optionally 
+     * setting the entry if one was resusitated from the master table.
+     *
+     * @param tuple the tuple for the IndexRecord
+     * @param entry the resusitated entry if any
+     */
+    public void setTuple( Tuple tuple, Properties entry )
+    {
+        this.tuple.setKey( tuple.getKey() );
+        this.tuple.setValue( tuple.getValue() );
+        this.entry = entry;
+    }
+
+
+    /**
+     * 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, Properties 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 BigInteger getEntryId()
+    {
+        return ( BigInteger ) tuple.getValue();
+    }
+
+
+    /**
+     * Gets the index key ( the attribute's value ) for this IndexRecord.
+     *
+     * @return the key of the entry indexed
+     */
+    public Object getIndexKey()
+    {
+        return tuple.getKey();
+    }
+
+
+    /**
+     * Sets the entry id.
+     *
+     * @param id the id of the entry
+     */
+    public void setEntryId( BigInteger id )
+    {
+        tuple.setValue( id );
+    }
+
+
+    /**
+     * Sets the index key.
+     *
+     * @param key the key of the IndexRecord
+     */
+    public void setIndexKey( Object key )
+    {
+        tuple.setKey( key );
+    }
+
+
+    /**
+     * Gets the entry of this IndexRecord if one was resusitated form the master
+     * table.
+     * 
+     * @return the entry's Properties
+     */
+    public Properties getProperties()
+    {
+        if ( entry == null )
+        {
+            return null;
+        }
+
+        return ( Properties ) entry.clone();
+    }
+
+
+    /**
+     * Sets the entry's Properties.
+     * 
+     * @param entry the entry's Properties
+     */
+    public void setProperties( Properties entry )
+    {
+        this.entry = entry;
+    }
+
+
+    /**
+     * Clears the tuple key, the tuple value and the entry fields.
+     */
+    public void clear()
+    {
+        entry = null;
+        tuple.setKey( null );
+        tuple.setValue( null );
+    }
+
+
+    /**
+     * Utility method used to copy the contents of one IndexRecord into this
+     * IndexRecord.
+     * 
+     * @param record the record whose contents we copy
+     */
+    public void copy( IndexRecord record )
+    {
+        entry = record.getProperties();
+        tuple.setKey( record.getIndexKey() );
+        tuple.setValue( record.getEntryId() );
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecordCursor.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecordCursor.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecordCursor.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IndexRecordCursor.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,34 @@
+/*
+ *  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.felix.bundledb.btree;
+
+import java.io.IOException;
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface IndexRecordCursor
+{
+    void close() throws IOException;
+    boolean hasMore();
+    IndexRecord next() throws IOException;
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IteratorTupleCursor.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IteratorTupleCursor.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IteratorTupleCursor.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/IteratorTupleCursor.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,84 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.util.Iterator;
+
+
+/**
+ * A NamingEnumeration that returns underlying Iterator values for a single key
+ * as Tuples.
+ * 
+ * <p>
+ * WARNING: The tuple returned is reused every time for efficiency and populated
+ * a over and over again with the new value.  The key never changes.
+ * </p>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class IteratorTupleCursor implements TupleCursor
+{
+    private final Object key;
+    private final Iterator iterator;
+    private final Tuple tuple = new Tuple();
+
+
+    /**
+     * Creates a cursor over an Iterator of single key's values
+     * 
+     * @param key the keys whose duplicate values are to be returned
+     * @param iterator the underlying iterator this cursor uses
+     */
+    public IteratorTupleCursor( Object key, Iterator iterator )
+    {
+        this.key = key;
+        tuple.setKey( key );
+        this.iterator = iterator;
+    }
+
+
+    /**
+     * Gets the next value as a Tuple.
+     */
+    public Tuple next()
+    {
+        tuple.setKey( key );
+        tuple.setValue( iterator.next() );
+        return tuple;
+    }
+
+
+    /**
+     * Checks if another value is available.
+     *
+     * @see javax.naming.NamingEnumeration#hasMore()
+     */
+    public boolean hasMore()
+    {
+        return iterator.hasNext();
+    }
+
+
+    public void close()
+    {
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/KeyOnlyComparator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/KeyOnlyComparator.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/KeyOnlyComparator.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/KeyOnlyComparator.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,98 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+
+/**
+ * A TupleComparator that compares keys only.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class KeyOnlyComparator implements TupleComparator, Serializable
+{
+    private static final long serialVersionUID = 3544956549803161397L;
+
+    private Comparator keyComparator = null;
+
+
+    public KeyOnlyComparator( Comparator comparator )
+    {
+        keyComparator = comparator;
+    }
+
+
+    /**
+     * Gets the comparator used to compare keys.  May be null in which
+     * case the compareKey method will throw an UnsupportedOperationException.
+     *
+     * @return the comparator for comparing keys.
+     */
+    public Comparator getKeyComparator()
+    {
+        return keyComparator;
+    }
+
+
+    /**
+     * Will throw an UnsupportedOperationException every time.
+     */
+    public Comparator getValueComparator()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    /**
+     * Compares key Object to determine their sorting order returning a
+     * value = to, < or > than 0.
+     *
+     * @param key1 the first key to compare
+     * @param key2 the other key to compare to the first
+     * @return 0 if both are equal, a negative value less than 0 if the first
+     * is less than the second, or a postive value if the first is greater than
+     * the second byte array.
+     */
+    @SuppressWarnings("unchecked")
+    public int compareKey( Object key1, Object key2 )
+    {
+        return keyComparator.compare( key1, key2 );
+    }
+
+
+    /**
+     * Comparse value Objects to determine their sorting order returning a
+     * value = to, < or > than 0.
+     *
+     * @param value1 the first value to compare
+     * @param value2 the other value to compare to the first
+     * @return 0 if both are equal, a negative value less than 0 if the first
+     * 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 )
+    {
+        throw new UnsupportedOperationException();
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/MasterTable.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/MasterTable.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/MasterTable.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/MasterTable.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,116 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Properties;
+
+
+/**
+ * The master table used to store the Attributes of entries.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface MasterTable extends Table
+{
+    /** the name of the dbf file for this table */
+    String DBF = "master";
+
+    /** the sequence key - stores last sequence value in the admin table */
+    String SEQPROP_KEY = "__sequence__";
+
+
+    /**
+     * Gets the Properties of an entry from this MasterTable.
+     *
+     * @param id the BigInteger id of the entry to retrieve.
+     * @return the Properties of the entry with operational Properties and all.
+     * @throws IOException if there is a read error on the underlying Db.
+     */
+    Properties get( BigInteger id ) throws IOException;
+
+
+    /**
+     * Puts the Properties of an entry into this master table at an index 
+     * specified by id.  Used both to create new entries and update existing 
+     * ones.
+     *
+     * @param entry the Properties of entry w/ operational Properties
+     * @param id the BigInteger id of the entry to put
+     * @return the newly created entry's Properties
+     * @throws IOException if there is a write error on the underlying Db.
+     */
+    Properties put( Properties entry, BigInteger id ) throws IOException;
+
+
+    /**
+     * Deletes a entry from the master table at an index specified by id.
+     *
+     * @param id the BigInteger id of the entry to delete
+     * @return the Properties of the deleted entry
+     * @throws IOException if there is a write error on the underlying Db
+     */
+    Properties delete( BigInteger id ) throws IOException;
+
+
+    /**
+     * Get's the current id value from this master database's sequence without
+     * affecting the seq.
+     *
+     * @return the current value.
+     * @throws IOException if the admin table storing sequences cannot be
+     * read.
+     */
+    BigInteger getCurrentId() throws IOException;
+
+
+    /**
+     * Get's the next value from this SequenceBDb.  This has the side-effect of
+     * changing the current sequence values perminantly in memory and on disk.
+     *
+     * @return the current value incremented by one.
+     * @throws IOException if the admin table storing sequences cannot be
+     * read and writen to.
+     */
+    BigInteger getNextId() throws IOException;
+
+
+    /**
+     * Gets a persistant property stored in the admin table of this MasterTable.
+     *
+     * @param property the key of the property to get the value of
+     * @return the value of the property
+     * @throws IOException when the underlying admin table cannot be read
+     */
+    String getProperty( String property ) throws IOException;
+
+
+    /**
+     * Sets a persistant property stored in the admin table of this MasterTable.
+     *
+     * @param property the key of the property to set the value of
+     * @param value the value of the property
+     * @throws IOException when the underlying admin table cannot be writen
+     */
+    void setProperty( String property, String value ) throws IOException;
+}
\ No newline at end of file

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/NoDupsTupleCursor.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/NoDupsTupleCursor.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/NoDupsTupleCursor.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/NoDupsTupleCursor.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,144 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+
+
+/**
+ * A simple NamingEnumeration over a TupleBrowser on a table that does not allow
+ * duplicates.
+ * 
+ * <p> WARNING: The Tuple returned by this listing is always the same instance 
+ * object returned every time. It is reused to for the sake of efficency rather 
+ * than creating a new tuple for each hasMore() call.
+ * </p>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class NoDupsTupleCursor implements TupleCursor
+{
+    /** Temporary Tuple used to return results */
+    private final Tuple returned = new Tuple();
+    /** Temporary Tuple used to store prefetched values */
+    private final Tuple prefetched = new Tuple();
+    /** The JDBM TupleBrowser this NamingEnumeration wraps */
+    private final TupleBrowser browser;
+    /** The direction of this NamingEnumeration */
+    private final boolean doAscendingScan;
+    /** Whether or not this NamingEnumeration can advance */
+    private boolean hasNext = true;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R
+    // ------------------------------------------------------------------------
+
+    /**
+     * Creates a cursor over a TupleBrowser where duplicates are not expected.
+     */
+    public NoDupsTupleCursor( TupleBrowser browser, boolean doAscendingScan ) throws IOException
+    {
+        this.browser = browser;
+        this.doAscendingScan = doAscendingScan;
+        prefetch();
+    }
+
+
+    // ------------------------------------------------------------------------
+    // NamingEnumeration Interface Method Implementations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Returns the same Tuple every time but with different key/value pairs.
+     */
+    public Tuple next() throws IOException
+    {
+        // Load values into the Tuple to return
+        returned.setKey( prefetched.getKey() );
+        returned.setValue( prefetched.getValue() );
+
+        // Prefetch next set of values to return if and return last prefetched
+        prefetch();
+        return returned;
+    }
+
+
+    /**
+     * @see javax.naming.NamingEnumeration#hasMore()
+     */
+    public boolean hasMore()
+    {
+        return hasNext;
+    }
+
+
+    /**
+     * Sets hasNext to false.
+     *
+     * @see javax.naming.NamingEnumeration#close()
+     */
+    public void close()
+    {
+        hasNext = false;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Private/Package Friendly Methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Gets the direction of this NamingEnumeration.
+     *
+     * @return true if this NamingEnumeration is ascending on keys, false 
+     * otherwise.
+     */
+    public boolean doAscendingScan()
+    {
+        return doAscendingScan;
+    }
+
+
+    /**
+     * Prefetches a value into prefetched over writing whatever values were 
+     * contained in the Tuple.
+     *
+     * @throws NamingException if the TupleBrowser browser could not advance
+     */
+    private void prefetch() throws IOException
+    {
+        // Prefetch into tuple!
+        boolean isSuccess = false;
+
+        if ( doAscendingScan )
+        {
+            isSuccess = browser.getNext( prefetched );
+        }
+        else
+        {
+            isSuccess = browser.getPrevious( prefetched );
+        }
+
+        hasNext = isSuccess;
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Table.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Table.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Table.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Table.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,361 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+
+/**
+ * A backend friendly wrapper around a JDBM BTree that transparent enables
+ * duplicates when the BTree does not support them.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface Table
+{
+    /**
+     * Gets the comparator used by this Table: may be null if this Table was
+     * not initialized with one.
+     *
+     * @return the final comparator instance or null if this Table was not
+     * created with one.
+     */
+    TupleComparator getComparator();
+
+
+    /**
+     * Gets the data renderer used by this Table to display or log records keys
+     * and values.
+     *
+     * @return the renderer used
+     */
+    TupleRenderer getRenderer();
+
+
+    /**
+     * Sets the data renderer to by used by this Table to display or log record
+     * keys and values.
+     *
+     * @param renderer the DataRenderer instance to used as the renderer.
+     */
+    void setRenderer( TupleRenderer renderer );
+
+
+    /**
+     * Gets the name of this Table.
+     *
+     * @return the name
+     */
+    String getName();
+
+
+    /**
+     * Checks to see if this Table has enabled the use of duplicate keys.
+     *
+     * @return true if duplicate keys are enabled, false otherwise.
+     */
+    boolean isDupsEnabled();
+
+
+    /**
+     * Checks to see if this Table has enabled sorting on the values of
+     * duplicate keys.
+     *
+     * @return true if duplicate key values are sorted, false otherwise.
+     */
+    boolean isSortedDupsEnabled();
+
+
+    // ------------------------------------------------------------------------
+    // Simple Table Key/Value Assertions 
+    // ------------------------------------------------------------------------
+
+    /**
+     * Checks to see if this table has a key: same as a get call with a check to
+     * see if the returned value is null or not.
+     *
+     * @param key the Object of the key to check for
+     * @return true if the key exists, false otherwise.
+     * @throws IOException if there is a failure to read the underlying Db
+     */
+    boolean has( Object key ) throws IOException;
+
+
+    /**
+     * Checks to see if this table has a key with a specific value.
+     *
+     * @param key the key Object to check for
+     * @param value the value Object to check for
+     * @return true if a record with the key and value exists, false otherwise.
+     * @throws IOException if there is a failure to read the underlying Db
+     */
+    boolean has( Object key, Object value ) throws IOException;
+
+
+    /**
+     * Checks to see if this table has a record with a key greater/less than or
+     * equal to the key argument.  The key argument need not exist for this
+     * call to return true.  The underlying database must be a BTree because
+     * this method depends on the use of sorted keys.
+     *
+     * @param key the key Object to compare keys to
+     * @param isGreaterThan boolean for greater than or less then comparison
+     * @return true if a record with a key greater/less than the key argument
+     * exists, false otherwise
+     * @throws IOException if there is a failure to read the underlying Db,
+     * or if the underlying Db is not a Btree.
+     */
+    boolean has( Object key, boolean isGreaterThan ) throws IOException;
+
+
+    /**
+     * Checks to see if this table has a record with a key equal to the
+     * argument key with a value greater/less than or equal to the value
+     * argument provided.  The key argument <strong>MUST</strong> exist for
+     * this call to return true and the underlying Db must be a Btree that
+     * allows for sorted duplicate values.  The entire basis to this method
+     * depends on the fact that duplicate key values are sorted according to
+     * a valid value comparator function.
+     *
+     * If the table does not support duplicates then an 
+     * UnsupportedOperationException is thrown.
+     *
+     * @param key the key Object
+     * @param val the value Object to compare values to
+     * @param isGreaterThan boolean for greater than or less then comparison
+     * @return true if a record with a key greater/less than the key argument
+     * exists, false otherwise
+     * @throws IOException if there is a failure to read the underlying Db
+     * or if the underlying Db is not of the Btree type that allows sorted
+     * duplicate values.
+     */
+    boolean has( Object key, Object val, boolean isGreaterThan ) throws IOException;
+
+
+    // ------------------------------------------------------------------------
+    // Table Value Accessors/Mutators
+    // ------------------------------------------------------------------------
+
+    /**
+     * Gets the value of a record by key if the key exists.  If this Table
+     * allows duplicate keys then the first key will be returned.  If this
+     * Table is also a Btree that first key will be the smallest key in the
+     * Table as specificed by this Table's comparator or the default berkeley
+     * bytewise lexical comparator.
+     *
+     * @param key the key of the record
+     * @return the value of the record with key if key exists or null if
+     * no such record exists.
+     * @throws IOException if there is a failure to read the underlying Db
+     */
+    Object get( Object key ) throws IOException;
+
+
+    /**
+     * Puts a record into this Table.
+     *
+     * @param key the key of the record
+     * @param value the value of the record.
+     * @return the last value present for key or null if this the key did not
+     * exist before.
+     * @throws IOException if there is a failure to read or write to
+     * the underlying Db
+     */
+    Object put( Object key, Object value ) throws IOException;
+
+
+    /**
+     * Efficiently puts a set of values into the Table.  If the Table does not 
+     * support duplicate keys then only the first key within the enumeration is
+     * added.  If there are more elements left after this single addition an
+     * UnsupportedOperationException is thrown.  Nothing is added if the table
+     * does not support duplicates and there is more than one element in the
+     * enumeration.
+     *
+     * @param key the key to use for the values
+     * @param values the values supplied as an enumeration
+     * @throws IOException if something goes wrong
+     */
+    Object put( Object key, Enumeration values ) throws IOException;
+
+
+    /**
+     * Removes all records with key from this Table.
+     *
+     * @param key the key of the records to remove
+     * @throws IOException if there is a failure to read or write to
+     * the underlying Db
+     */
+    Object remove( Object key ) throws IOException;
+
+
+    /**
+     * Removes a single specific record with key and value from this Table.
+     *
+     * @param key the key of the record to remove
+     * @param value the value of the record to remove
+     * @throws IOException if there is a failure to read or write to
+     * the underlying Db
+     */
+    Object remove( Object key, Object value ) throws IOException;
+
+
+    /**
+     * Removes a set of values with the same key from this Table.  If this 
+     * table does not allow duplicates the method will attempt to remove the 
+     * first value in the enumeration if one exists.  If there is more than one 
+     * value within the enumeration after the first drop an 
+     * UnsupportedOperationException is thrown.  Nothing is removed if there is 
+     * more than one element on the enumeration and the table does not support
+     * duplicates.
+     *
+     * @param key the key of the records to remove
+     * @return the first value removed
+     * @throws IOException if there is a failure to read or write to
+     * the underlying Db
+     */
+    Object remove( Object key, Enumeration values ) throws IOException;
+
+
+    /**
+     * Sets a cursor to the first record in the Table with a key value of
+     * key and enables single next steps across all duplicate records with
+     * this key.  This enumeration will only iterate over duplicates of the key.
+     * Unlike listTuples(Object) which returns Tuples from the enumerations 
+     * advances methods this call returns an enumeration with just the values
+     * of the key.
+     * 
+     * @param key the key to iterate over
+     * @throws IOException if the underlying browser could not be set
+     */
+    TupleCursor listValues( Object key ) throws IOException;
+
+
+    // ------------------------------------------------------------------------
+    // listTuple overloads
+    // ------------------------------------------------------------------------
+
+    /**
+     * Sets a cursor to the first record in the Table and enables single
+     * next steps across all records.
+     *
+     * @throws IOException if the underlying cursor could not be set.
+     */
+    TupleCursor listTuples() throws IOException;
+
+
+    /**
+     * Sets a cursor to the first record in the Table with a key value of
+     * key and enables single next steps across all duplicate records with
+     * this key.  This cursor will only iterate over duplicates of the key.
+     *
+     * @param key the key to iterate over
+     * @throws IOException if the underlying cursor could not be set
+     */
+    TupleCursor listTuples( Object key ) throws IOException;
+
+
+    /**
+     * Sets a cursor to the first record in the Table with a key value
+     * greater/less than or equal to key and enables single next steps across
+     * all records with key values equal to or less/greater than key.
+     *
+     * @param key the key to use to position this cursor to record with a key
+     * greater/less than or equal to it
+     * @param isGreaterThan if true the cursor iterates up over ascending keys
+     * greater than or equal to the key argument, but if false this cursor
+     * iterates down over descending keys less than or equal to key argument
+     * @throws IOException if the underlying cursor could not be set
+     */
+    TupleCursor listTuples( Object key, boolean isGreaterThan ) throws IOException;
+
+
+    /**
+     * Sets a cursor to the first record in the Table with a key equal to
+     * the key argument whose value is greater/less than or equal to val and
+     * enables single next steps across all records with key equal to key.
+     * Hence this cursor will only iterate over duplicate keys where values are
+     * less than or greater than or equal to val.
+     *
+     * If the table does not support duplicates then an 
+     * UnsupportedOperationException is thrown.
+     *
+     * @param key the key to use to position this cursor to record with a key
+     * equal to it.
+     * @param val the value to use to position this cursor to record with a
+     * value greater/less than or equal to it.
+     * @param isGreaterThan if true the cursor iterates up over ascending 
+     * values greater than or equal to the val argument, but if false this 
+     * cursor iterates down over descending values less than or equal to val 
+     * argument starting from the largest value going down
+     * @throws IOException if the underlying cursor could not be set or
+     * this method is called over a cursor on a table that does not have sorted
+     * duplicates enabled.
+     */
+    TupleCursor listTuples( Object key, Object val, boolean isGreaterThan ) throws IOException;
+
+
+    // ------------------------------------------------------------------------
+    // Table Record Count Methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Gets the count of the number of records in this Table.
+     *
+     * @return the number of records
+     * @throws IOException if there is a failure to read the underlying Db
+     */
+    int count() throws IOException;
+
+
+    /**
+     * Gets the count of the number of records in this Table with a specific
+     * key: returns the number of duplicates for a key.
+     *
+     * @param key the Object key to count.
+     * @return the number of duplicate records for a key.
+     * @throws IOException if there is a failure to read the underlying Db
+     */
+    int count( Object key ) throws IOException;
+
+
+    /**
+     * 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.
+     *
+     * @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
+     */
+    int count( Object key, boolean isGreaterThan ) throws IOException;
+
+
+    /**
+     * Closes the underlying Db of this Table.
+     *
+     * @throws IOException on any failures
+     */
+    void close() throws IOException;
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,103 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+/**
+ * A key/value tuple for simple two column Tables.  Implemented to provide 
+ * independence from the Jdbm Tuple class.  Key and value copying should be 
+ * performed to transpose jdbm.helper.Tuple data into our generic Tuple.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class Tuple
+{
+    /** the key for this Tuple */
+    private Object key;
+    /** the value for this Tuple */
+    private Object value;
+
+
+    /**
+     * Do nothing default that has a null key and null value.
+     */
+    public Tuple()
+    {
+        // does nothing!
+    }
+
+
+    /**
+     * Creates a Tuple using a key and a value.
+     * 
+     * @param key the key to set
+     * @param value the value to set
+     */
+    public Tuple(Object key, Object value)
+    {
+        this.key = key;
+        this.value = value;
+    }
+
+
+    /**
+     * Gets the key for this Tuple.
+     *
+     * @return the Tuple's key
+     */
+    public Object getKey()
+    {
+        return key;
+    }
+
+
+    /**
+     * Sets the key for this Tuple.
+     *
+     * @param key the new key to set
+     */
+    public void setKey( Object key )
+    {
+        this.key = key;
+    }
+
+
+    /**
+     * Gets the value for this Tuple.
+     *
+     * @return the Tuple's value
+     */
+    public Object getValue()
+    {
+        return value;
+    }
+
+
+    /**
+     * Sets the value for this Tuple.
+     *
+     * @param value the new value to set
+     */
+    public void setValue( Object value )
+    {
+        this.value = value;
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple2IndexRecordCursor.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple2IndexRecordCursor.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple2IndexRecordCursor.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/Tuple2IndexRecordCursor.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,139 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+
+/**
+ * A NamingEnumeration over an Index which returns IndexRecords.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public class Tuple2IndexRecordCursor implements IndexRecordCursor
+{
+    /** */
+    private final Pattern re;
+    /** */
+    private final IndexRecord tmp = new IndexRecord();
+    /** */
+    private final IndexRecord returned = new IndexRecord();
+    /** */
+    private final IndexRecord prefetched = new IndexRecord();
+    /** */
+    private final boolean swapKeyVal;
+    /** */
+    private final TupleCursor underlying;
+
+    /** */
+    private boolean hasMore = true;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+    
+    public Tuple2IndexRecordCursor( TupleCursor list ) throws IOException
+    {
+        this( list, false, null );
+    }
+
+
+    public Tuple2IndexRecordCursor( TupleCursor list, boolean swapKeyVal ) throws IOException
+    {
+        this( list, swapKeyVal, null );
+    }
+
+
+    public Tuple2IndexRecordCursor( TupleCursor list, boolean swapKeyVal, Pattern regex ) throws IOException
+    {
+        re = regex;
+        underlying = list;
+        this.swapKeyVal = swapKeyVal;
+
+        if ( !underlying.hasMore() )
+        {
+            hasMore = false;
+            return;
+        }
+
+        prefetch();
+    }
+
+
+    public IndexRecord next() throws IOException
+    {
+        returned.copy( prefetched );
+        prefetch();
+        return returned;
+    }
+
+
+    public boolean hasMore()
+    {
+        return hasMore;
+    }
+
+
+    public void close() throws IOException
+    {
+        hasMore = false;
+        underlying.close();
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Private Methods 
+    // ------------------------------------------------------------------------
+
+    
+    private void prefetch() throws IOException
+    {
+        while ( underlying.hasMore() )
+        {
+            Tuple tuple = ( Tuple ) underlying.next();
+
+            if ( swapKeyVal )
+            {
+                tmp.setSwapped( tuple, null );
+            }
+            else
+            {
+                tmp.setTuple( tuple, null );
+            }
+
+            // If regex is null just transfer into prefetched from tmp record
+            // but if it is not then use it to match.  Successful match shorts
+            // while loop.
+            if ( null == re || re.matcher( ( String ) tmp.getIndexKey() ).matches() )
+            {
+                prefetched.copy( tmp );
+                return;
+            }
+        }
+
+        // If we got down here then cursor has been consumed without a match!
+        hasMore = false;
+    }
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleBrowser.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleBrowser.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleBrowser.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleBrowser.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,54 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+
+
+/**
+ * TupleBrowser interface used to abstract 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface TupleBrowser
+{
+    /**
+     * Gets the next value deemed greater than the last using the key 
+     * comparator.
+     *
+     * @param tuple the tuple to populate with a key/value pair
+     * @return true if there was a next that was populated or false otherwise
+     * @throws IOException @todo
+     */
+    boolean getNext( Tuple tuple ) throws IOException;
+
+
+    /**
+     * Gets the previous value deemed greater than the last using the key 
+     * comparator.
+     *
+     * @param tuple the tuple to populate with a key/value pair
+     * @return true if there was a previous value populated or false otherwise
+     * @throws IOException @todo
+     */
+    boolean getPrevious( Tuple tuple ) throws IOException;
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleComparator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleComparator.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleComparator.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleComparator.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,77 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+
+/**
+ * Used to compare the sorting order of binary data.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface TupleComparator extends Serializable
+{
+    /**
+     * Gets the comparator used to compare keys.  May be null in which
+     * case the compareKey method will throw an UnsupportedOperationException.
+     *
+     * @return the comparator for comparing keys.
+     */
+    Comparator getKeyComparator();
+
+
+    /**
+     * Gets the binary comparator used to compare valuess.  May be null in which
+     * case the compareValue method will throw an UnsupportedOperationException.
+     *
+     * @return the binary comparator for comparing values.
+     */
+    Comparator getValueComparator();
+
+
+    /**
+     * Compares key Object to determine their sorting order returning a
+     * value = to, < or > than 0.
+     *
+     * @param key1 the first key to compare
+     * @param key2 the other key to compare to the first
+     * @return 0 if both are equal, a negative value less than 0 if the first
+     * 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 );
+
+
+    /**
+     * Comparse value Objects to determine their sorting order returning a
+     * value = to, < or > than 0.
+     *
+     * @param value1 the first value to compare
+     * @param value2 the other value to compare to the first
+     * @return 0 if both are equal, a negative value less than 0 if the first
+     * is less than the second, or a postive value if the first is greater than
+     * the second Object.
+     */
+    int compareValue( Object value1, Object value2 );
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleCursor.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleCursor.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleCursor.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleCursor.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,36 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+import java.io.IOException;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface TupleCursor
+{
+    void close() throws IOException;
+    boolean hasMore();
+    Tuple next() throws IOException;
+}

Added: incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleRenderer.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleRenderer.java?view=auto&rev=500136
==============================================================================
--- incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleRenderer.java (added)
+++ incubator/felix/sandbox/akarasulu/bundledb/src/main/java/org/apache/felix/bundledb/btree/TupleRenderer.java Thu Jan 25 19:59:02 2007
@@ -0,0 +1,48 @@
+/*
+ *  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.felix.bundledb.btree;
+
+
+/**
+ * A table key/value String renderer for the display or logging of
+ * human readable potentially binary data.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 491471 $
+ */
+public interface TupleRenderer
+{
+    /**
+     * Gets the key Object rendered as a String.
+     *
+     * @param key the key Object
+     * @return the String representation of the key Object
+     */
+    String getKeyString( Object key );
+
+
+    /**
+     * Gets the value Object rendered as a String.
+     *
+     * @param value the value Object
+     * @return the String representation of the value Object
+     */
+    String getValueString( Object value );
+}



Mime
View raw message