directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1156585 - in /directory/apacheds/trunk: jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ xdbm-partition/src/main/java/org/apache/directo...
Date Thu, 11 Aug 2011 12:08:24 GMT
Author: elecharny
Date: Thu Aug 11 12:08:23 2011
New Revision: 1156585

URL: http://svn.apache.org/viewvc?rev=1156585&view=rev
Log:
o Added an AbstractTable which gather the common fields and methods for Table implementations

Added:
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractTable.java
Modified:
    directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlTable.java

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=1156585&r1=1156584&r2=1156585&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Thu Aug 11 12:08:23 2011
@@ -35,6 +35,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.avltree.ArrayTreeCursor;
 import org.apache.directory.server.core.avltree.Marshaller;
 import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.xdbm.AbstractTable;
 import org.apache.directory.server.xdbm.Table;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
@@ -52,7 +53,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class JdbmTable<K,V> implements Table<K,V>
+public class JdbmTable<K,V> extends AbstractTable<K,V>
 {
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( JdbmTable.class.getSimpleName()
);
@@ -60,24 +61,12 @@ public class JdbmTable<K,V> implements T
     /** the key to store and retreive the count information */
     private static final String SZSUFFIX = "_btree_sz";
 
-    /** the name of this table */
-    private final String name;
-
     /** the JDBM record manager for the file this table is managed in */
     private final RecordManager recMan;
     
     /** whether or not this table allows for duplicates */
     private final boolean allowsDuplicates;
-    
-    /** a key comparator for the keys in this Table */
-    private final Comparator<K> keyComparator;
-    
-    /** a value comparator for the values in this Table */
-    private final Comparator<V> valueComparator;
 
-    /** the current count of entries in this Table */
-    private int count;
-    
     /** the wrappedCursor JDBM btree used in this Table */
     private BTree<K, V> bt;
 
@@ -93,9 +82,6 @@ public class JdbmTable<K,V> implements T
 
     Marshaller<ArrayTree<V>> marshaller;
 
-    /** The global SchemaManager */
-    private SchemaManager schemaManager;
-
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R
     // ------------------------------------------------------------------------
@@ -123,7 +109,12 @@ public class JdbmTable<K,V> implements T
         Serializer keySerializer, Serializer valueSerializer )
         throws IOException
     {
-        this.schemaManager = schemaManager;
+        super( schemaManager, name, keyComparator, valueComparator );
+
+        if ( valueComparator == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_592 ) );
+        }
 
         // TODO make the size of the duplicate btree cache configurable via constructor
         duplicateBtrees = new SynchronizedLRUMap( 100 );
@@ -138,26 +129,7 @@ public class JdbmTable<K,V> implements T
             marshaller = new ArrayMarshaller<V>( valueComparator );
         }
 
-        if ( keyComparator == null )
-        {
-            throw new IllegalArgumentException( I18n.err( I18n.ERR_591 ) );
-        }
-        else
-        {
-            this.keyComparator = keyComparator;
-        }
-
-        if ( valueComparator == null )
-        {
-            throw new IllegalArgumentException( I18n.err( I18n.ERR_592 ) );
-        }
-        else
-        {
-            this.valueComparator = valueComparator;
-        }
-
         this.numDupLimit = numDupLimit;
-        this.name = name;
         this.recMan = manager;
 
         this.keySerializer = keySerializer;
@@ -187,7 +159,6 @@ public class JdbmTable<K,V> implements T
             recId = recMan.getNamedObject( name + SZSUFFIX );
             count = ( Integer ) recMan.fetch( recId );
         }
-
     }
 
 
@@ -209,23 +180,12 @@ public class JdbmTable<K,V> implements T
                       Serializer keySerializer, Serializer valueSerializer )
         throws IOException
     {
-        this.schemaManager = schemaManager;
+        super( schemaManager, name, keyComparator, null );
+        
         this.duplicateBtrees = null;
         this.numDupLimit = Integer.MAX_VALUE;
-        this.name = name;
         this.recMan = manager;
 
-        if ( keyComparator == null )
-        {
-            throw new IllegalArgumentException( I18n.err( I18n.ERR_591 ) );
-        }
-        else
-        {
-            this.keyComparator = keyComparator;
-        }
-
-        this.valueComparator = null;
-
         this.keySerializer = keySerializer;
         this.valueSerializer = valueSerializer;
 
@@ -256,25 +216,6 @@ public class JdbmTable<K,V> implements T
     // Simple Table Properties
     // ------------------------------------------------------------------------
 
-    
-    /**
-     * @see Table#getKeyComparator()
-     */
-    public Comparator<K> getKeyComparator()
-    {
-        return keyComparator;
-    }
-
-
-    /**
-     * @see Table#getValueComparator()
-     */
-    public Comparator<V> getValueComparator()
-    {
-        return valueComparator;
-    }
-
-
     public Serializer getKeySerializer()
     {
         return keySerializer;
@@ -295,21 +236,10 @@ public class JdbmTable<K,V> implements T
         return allowsDuplicates;
     }
 
-
-    /**
-     * @see org.apache.directory.server.xdbm.Table#getName()
-     */
-    public String getName()
-    {
-        return name;
-    }
-
-
+    
     // ------------------------------------------------------------------------
     // Count Overloads
     // ------------------------------------------------------------------------
-
-    
     /**
      * @see Table#greaterThanCount(Object)
      */
@@ -362,15 +292,6 @@ public class JdbmTable<K,V> implements T
         return getBTree( values.getBTreeRedirect() ).size();
     }
 
-
-    /**
-     * @see org.apache.directory.server.xdbm.Table#count()
-     */
-    public int count() throws IOException
-    {
-        return count;
-    }
-
     
     // ------------------------------------------------------------------------
     // get/has/put/remove Methods and Overloads

Added: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractTable.java?rev=1156585&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractTable.java
(added)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractTable.java
Thu Aug 11 12:08:23 2011
@@ -0,0 +1,114 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.server.xdbm;
+
+import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+
+/**
+ * A Abstract Table implementation aggregating the methods comon with all the 
+ * different Table implementation.
+ *
+ * @param <K> The key
+ * @param <V> The stored value
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractTable<K,V> implements Table<K,V>
+{
+    /** the name of this table */
+    protected final String name;
+
+    /** The global SchemaManager */
+    protected SchemaManager schemaManager;
+    
+    /** a key comparator for the keys in this Table */
+    protected final Comparator<K> keyComparator;
+
+    /** a value comparator for the values in this Table */
+    protected final Comparator<V> valueComparator;
+
+    /** the current count of entries in this Table */
+    protected int count;
+
+    /**
+     * Create an instance of Table
+     * 
+     * @param schemaManager The server schemaManager
+     * @param name the name of the table
+     * @param keyComparator a key comparator
+     * @param valueComparator a value comparator
+     */
+    protected AbstractTable( SchemaManager schemaManager, String name, Comparator<K>
keyComparator,
+        Comparator<V> valueComparator )
+    {
+        this.schemaManager = schemaManager;
+        this.name = name;
+
+        if ( keyComparator == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_591 ) );
+        }
+        else
+        {
+            this.keyComparator = keyComparator;
+        }
+
+        this.valueComparator = valueComparator;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Comparator<K> getKeyComparator()
+    {
+        return keyComparator;
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Comparator<V> getValueComparator()
+    {
+        return valueComparator;
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getName()
+    {
+        return name;
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public int count() throws IOException
+    {
+        return count;
+    }
+}

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlTable.java?rev=1156585&r1=1156584&r2=1156585&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlTable.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlTable.java
Thu Aug 11 12:08:23 2011
@@ -31,7 +31,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.avltree.KeyTupleAvlCursor;
 import org.apache.directory.server.core.avltree.LinkedAvlMapNode;
 import org.apache.directory.server.core.avltree.SingletonOrOrderedSet;
-import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.xdbm.AbstractTable;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.model.cursor.SingletonCursor;
@@ -43,22 +43,16 @@ import org.apache.directory.shared.ldap.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class AvlTable<K, V> implements Table<K, V>
+public class AvlTable<K, V> extends AbstractTable<K,V>
 {
     private final AvlTreeMap<K, V> avl;
-    private final String name;
-    private final Comparator<K> keyComparator;
-    private final Comparator<V> valComparator;
     private final Comparator<Tuple<K,V>> keyOnlytupleComparator;
-    private int count;
     
     
-    public AvlTable( String name, final Comparator<K> keyComparator, final Comparator<V>
valComparator, boolean dupsEnabled )
+    public AvlTable( String name, final Comparator<K> keyComparator, final Comparator<V>
valueComparator, boolean dupsEnabled )
     {
-        this.name = name;
-        this.keyComparator = keyComparator;
-        this.valComparator = valComparator;
-        this.avl = new AvlTreeMapImpl<K, V>( keyComparator, valComparator, dupsEnabled
);
+        super( null, name, keyComparator, valueComparator );
+        this.avl = new AvlTreeMapImpl<K, V>( keyComparator, valueComparator, dupsEnabled
);
         this.keyOnlytupleComparator = new Comparator<Tuple<K, V>>()
         {
             public int compare( Tuple<K, V> t0, Tuple<K, V> t1 )
@@ -81,15 +75,6 @@ public class AvlTable<K, V> implements T
     /**
      * {@inheritDoc}
      */
-    public int count() throws Exception
-    {
-        return count;
-    }
-
-    
-    /**
-     * {@inheritDoc}
-     */
     public int count( K key ) throws Exception
     {
         if ( key == null )
@@ -98,12 +83,14 @@ public class AvlTable<K, V> implements T
         }
         
         LinkedAvlMapNode<K, V> node = avl.find( key );
+        
         if ( node == null )
         {
             return 0;
         }
         
         SingletonOrOrderedSet<V> val = node.getValue();
+        
         if ( val.isOrderedSet() )
         {
             return val.getOrderedSet().getSize();
@@ -124,12 +111,14 @@ public class AvlTable<K, V> implements T
         }
         
         LinkedAvlMapNode<K, V> node = avl.find( key );
+        
         if ( node == null )
         {
             return null;
         }
         
         SingletonOrOrderedSet<V> val = node.getValue();
+        
         if ( val.isOrderedSet() )
         {
             return val.getOrderedSet().getFirst().getKey();
@@ -142,33 +131,6 @@ public class AvlTable<K, V> implements T
     /**
      * {@inheritDoc}
      */
-    public Comparator<K> getKeyComparator()
-    {
-        return keyComparator;
-    }
-
-    
-    /**
-     * {@inheritDoc}
-     */
-    public Comparator<V> getValueComparator()
-    {
-        return valComparator;
-    }
-
-    
-    /**
-     * {@inheritDoc}
-     */
-    public String getName()
-    {
-        return name;
-    }
-    
-
-    /**
-     * {@inheritDoc}
-     */
     public int greaterThanCount( K key ) throws Exception
     {
         return avl.getSize();
@@ -228,6 +190,7 @@ public class AvlTable<K, V> implements T
         }
         
         LinkedAvlMapNode<K, V> node = avl.findGreaterOrEqual( key );
+        
         if ( node == null )
         {
             return false;
@@ -239,7 +202,7 @@ public class AvlTable<K, V> implements T
             return values.findGreaterOrEqual( val ) != null;
         }
         
-        return valComparator.compare( node.getValue().getSingleton(), val ) >= 0;
+        return valueComparator.compare( node.getValue().getSingleton(), val ) >= 0;
     }
 
     
@@ -268,6 +231,7 @@ public class AvlTable<K, V> implements T
         }
         
         LinkedAvlMapNode<K, V> node = avl.findLessOrEqual( key );
+        
         if ( node == null )
         {
             return false;
@@ -279,7 +243,7 @@ public class AvlTable<K, V> implements T
             return values.findLessOrEqual( val ) != null;
         }
         
-        return valComparator.compare( node.getValue().getSingleton(), val ) <= 0;
+        return valueComparator.compare( node.getValue().getSingleton(), val ) <= 0;
     }
 
 
@@ -329,6 +293,7 @@ public class AvlTable<K, V> implements T
         }
         
         SingletonOrOrderedSet<V> value = avl.remove( key );
+        
         if ( value == null )
         {
             return;
@@ -382,6 +347,7 @@ public class AvlTable<K, V> implements T
         }
         
         LinkedAvlMapNode<K, V> node = avl.find( key );
+        
         if ( node == null )
         {
             return new EmptyCursor<Tuple<K,V>>();
@@ -408,6 +374,7 @@ public class AvlTable<K, V> implements T
         }
         
         LinkedAvlMapNode<K, V> node = avl.find( key );
+        
         if ( node == null )
         {
             return new EmptyCursor<V>();
@@ -418,7 +385,7 @@ public class AvlTable<K, V> implements T
             return new AvlTreeCursor<V>( node.getValue().getOrderedSet() );
         }
         
-        return new SingletonCursor<V>( node.getValue().getSingleton(), valComparator
);
+        return new SingletonCursor<V>( node.getValue().getSingleton(), valueComparator
);
     }
 
 



Mime
View raw message