directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r751899 - in /directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm: JdbmIndex.java JdbmStore.java
Date Mon, 09 Mar 2009 23:00:56 GMT
Author: elecharny
Date: Mon Mar  9 23:00:56 2009
New Revision: 751899

URL: http://svn.apache.org/viewvc?rev=751899&view=rev
Log:
Fix a NPE when we try to create an index on an attributeType which has no EQUALITY matching
rule

Modified:
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=751899&r1=751898&r2=751899&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
Mon Mar  9 23:00:56 2009
@@ -31,7 +31,10 @@
 import org.apache.directory.server.xdbm.Tuple;
 import org.apache.directory.server.xdbm.IndexCursor;
 import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.util.SynchronizedLRUMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.naming.NamingException;
 import java.io.File;
@@ -48,6 +51,9 @@
  */
 public class JdbmIndex<K,O> implements Index<K,O>
 {
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( JdbmIndex.class.getSimpleName()
);
+
     /**
      * default duplicate limit before duplicate keys switch to using a btree for values
      */
@@ -55,46 +61,56 @@
 
     /**  the key used for the forward btree name */
     public static final String FORWARD_BTREE = "_forward";
+    
     /**  the key used for the reverse btree name */
     public static final String REVERSE_BTREE = "_reverse";
 
     /** the attribute type resolved for this JdbmIndex */
     private AttributeType attribute;
+
     /**
      * the forward btree where the btree key is the value of the indexed attribute and
      * the value of the btree is the entry id of the entry containing an attribute with
      * that value
      */
     protected JdbmTable<K, Long> forward;
+    
     /**
      * the reverse btree where the btree key is the entry id of the entry containing a
      * value for the indexed attribute, and the btree value is the value of the indexed
      * attribute
      */
     protected JdbmTable<Long,K> reverse;
+    
     /**
      * the JDBM record manager for the file containing this index
      */
     protected RecordManager recMan;
+    
     /**
      * the normalized value cache for this index
      * @todo I don't think the keyCache is required anymore since the normalizer
      * will cache values for us.
      */
     protected SynchronizedLRUMap keyCache;
+    
     /** the size (number of index entries) for the cache */
     protected int cacheSize = DEFAULT_INDEX_CACHE_SIZE;
+    
     /**
      * duplicate limit before duplicate keys switch to using a btree for values
      */
     protected int numDupLimit = DEFAULT_DUPLICATE_LIMIT;
+    
     /**
      * the attribute identifier set at configuration time for this index which may not
      * be the OID but an alias name for the attributeType associated with this Index
      */
     private String attributeId;
+    
     /** whether or not this index has been initialized */
     protected boolean initialized;
+    
     /** a customm working directory path when specified in configuration */
     protected File wkDirPath;
 
@@ -136,8 +152,10 @@
 
     public void init( AttributeType attributeType, File wkDirPath ) throws IOException
     {
-        this.keyCache = new SynchronizedLRUMap( cacheSize );
-        this.attribute = attributeType;
+        LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
+        
+        keyCache = new SynchronizedLRUMap( cacheSize );
+        attribute = attributeType;
 
         if ( attributeId == null )
         {
@@ -182,7 +200,9 @@
 
         try
         {
-            comp = new SerializableComparator<K>( attribute.getEquality().getOid()
);
+            MatchingRule mr = attribute.getEquality();
+            
+            comp = new SerializableComparator<K>( mr.getOid() );
         }
         catch ( NamingException e )
         {
@@ -469,8 +489,6 @@
     // ------------------------------------------------------------------------
     // Index Cursor Operations
     // ------------------------------------------------------------------------
-
-
     @SuppressWarnings("unchecked")
     public IndexCursor<K, O> reverseCursor() throws Exception
     {
@@ -514,8 +532,6 @@
     // ------------------------------------------------------------------------
     // Value Assertion (a.k.a Index Lookup) Methods //
     // ------------------------------------------------------------------------
-
-    
     /**
      * @see Index#forward(Object)
      */
@@ -626,8 +642,6 @@
     // ------------------------------------------------------------------------
     // Maintenance Methods 
     // ------------------------------------------------------------------------
-
-
     /**
      * @see org.apache.directory.server.xdbm.Index#close()
      */

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=751899&r1=751898&r2=751899&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
Mon Mar  9 23:00:56 2009
@@ -64,6 +64,7 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -372,9 +373,23 @@
             for ( Index<?,E> index : userIndices.values() )
             {
                 String oid = oidRegistry.getOid( index.getAttributeId() );
-                tmp.put( oid, index );
-                ( ( JdbmIndex ) index ).init( attributeTypeRegistry.lookup( oid ), workingDirectory
);
+                AttributeType attributeType = attributeTypeRegistry.lookup( oid );
+                
+                // Check that the attributeType has an EQUALITY matchingRule
+                MatchingRule mr = attributeType.getEquality();
+                
+                if ( mr != null )
+                {
+                    ( ( JdbmIndex ) index ).init( attributeTypeRegistry.lookup( oid ), workingDirectory
);
+                    tmp.put( oid, index );
+                }
+                else
+                {
+                    LOG.error( "Cannot build an index for attribute '{}', no EQUALITY MatchingRule
defined",
+                        attributeType.getName() );
+                }
             }
+            
             userIndices = tmp;
         }
         else



Mime
View raw message