From commits-return-21304-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Mar 09 23:01:21 2009 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 15044 invoked from network); 9 Mar 2009 23:01:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Mar 2009 23:01:21 -0000 Received: (qmail 20341 invoked by uid 500); 9 Mar 2009 23:01:21 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 20301 invoked by uid 500); 9 Mar 2009 23:01:20 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 20292 invoked by uid 99); 9 Mar 2009 23:01:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Mar 2009 16:01:20 -0700 X-ASF-Spam-Status: No, hits=-1999.6 required=10.0 tests=ALL_TRUSTED,SUBJECT_FUZZY_TION X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Mar 2009 23:01:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0B74D2388975; Mon, 9 Mar 2009 23:00:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090309230057.0B74D2388975@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 implements Index { + /** 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 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 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( attribute.getEquality().getOid() ); + MatchingRule mr = attribute.getEquality(); + + comp = new SerializableComparator( mr.getOid() ); } catch ( NamingException e ) { @@ -469,8 +489,6 @@ // ------------------------------------------------------------------------ // Index Cursor Operations // ------------------------------------------------------------------------ - - @SuppressWarnings("unchecked") public IndexCursor 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 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