Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 39817 invoked from network); 23 May 2010 16:01:55 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 May 2010 16:01:55 -0000 Received: (qmail 45203 invoked by uid 500); 23 May 2010 16:01:55 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 45158 invoked by uid 500); 23 May 2010 16:01:55 -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 45151 invoked by uid 99); 23 May 2010 16:01:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 May 2010 16:01:55 +0000 X-ASF-Spam-Status: No, hits=-1457.8 required=10.0 tests=ALL_TRUSTED,AWL 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; Sun, 23 May 2010 16:01:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 79B2D23889E7; Sun, 23 May 2010 16:01:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r947437 - in /directory/apacheds/trunk/xdbm-search/src: main/java/org/apache/directory/server/xdbm/AbstractStore.java test/java/org/apache/directory/server/xdbm/AbstractStoreTest.java Date: Sun, 23 May 2010 16:01:31 -0000 To: commits@directory.apache.org From: seelmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100523160131.79B2D23889E7@eris.apache.org> Author: seelmann Date: Sun May 23 16:01:31 2010 New Revision: 947437 URL: http://svn.apache.org/viewvc?rev=947437&view=rev Log: If all values are removed the values must be removed from the index. Modified: directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/AbstractStoreTest.java Modified: directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java?rev=947437&r1=947436&r2=947437&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java (original) +++ directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java Sun May 23 16:01:31 2010 @@ -1422,18 +1422,42 @@ public abstract class AbstractStore value : mods ) + /* + * If there are no attribute values in the modifications then this + * implies the complete removal of the attribute from the index. Else + * we remove individual tuples from the index. + */ + if ( mods.size() == 0 ) + { + objectClassIdx.drop( id ); + } + else { - objectClassIdx.drop( value.getString(), id ); + for ( Value value : mods ) + { + objectClassIdx.drop( value.getString(), id ); + } } } else if ( hasUserIndexOn( modsOid ) ) { Index index = getUserIndex( modsOid ); - for ( Value value : mods ) + /* + * If there are no attribute values in the modifications then this + * implies the complete removal of the attribute from the index. Else + * we remove individual tuples from the index. + */ + if ( mods.size() == 0 ) + { + ( ( Index ) index ).drop( id ); + } + else { - ( ( Index ) index ).drop( value.get(), id ); + for ( Value value : mods ) + { + ( ( Index ) index ).drop( value.get(), id ); + } } /* Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/AbstractStoreTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/AbstractStoreTest.java?rev=947437&r1=947436&r2=947437&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/AbstractStoreTest.java (original) +++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/AbstractStoreTest.java Sun May 23 16:01:31 2010 @@ -22,6 +22,7 @@ package org.apache.directory.server.xdbm import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -151,6 +152,9 @@ public class AbstractStoreTest } + /** + * Adding an objectClass value should also add it to the objectClass index. + */ @Test public void testModifyAddObjectClass() throws Exception { @@ -172,13 +176,151 @@ public class AbstractStoreTest // before modification: no "uidObject" tuple in objectClass index assertFalse( store.getObjectClassIndex().forward( "uidObject", entryId ) ); - assertFalse( lookedup.get( "objectClass" ).contains( attribVal ) ); + assertFalse( lookedup.get( "objectClass" ).contains( "uidObject" ) ); store.modify( dn, mods ); // after modification: expect "uidObject" tuple in objectClass index assertTrue( store.getObjectClassIndex().forward( "uidObject", entryId ) ); - assertTrue( lookedup.get( "objectClass" ).contains( attribVal ) ); + assertTrue( lookedup.get( "objectClass" ).contains( "uidObject" ) ); + } + + + /** + * Removing a value of an indexed attribute should also remove it from the index. + */ + @Test + public void testModifyRemoveIndexedAttribute() throws Exception + { + DN dn = new DN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." ); + dn.normalize( schemaManager.getNormalizerMapping() ); + + List mods = new ArrayList(); + EntryAttribute attrib = new DefaultEntryAttribute( SchemaConstants.OU_AT, schemaManager + .lookupAttributeTypeRegistry( SchemaConstants.OU_AT ) ); + + String attribVal = "sales"; + attrib.add( attribVal ); + + Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib ); + mods.add( add ); + + Long entryId = store.getEntryId( dn ); + Entry lookedup = store.lookup( entryId ); + + // before modification: expect "sales" tuple in ou index + Index ouIndex = ( Index ) store.getUserIndex( SchemaConstants.OU_AT ); + assertTrue( ouIndex.forward( "sales", entryId ) ); + assertTrue( lookedup.get( "ou" ).contains( "sales" ) ); + + store.modify( dn, mods ); + + // after modification: no "sales" tuple in ou index + assertFalse( ouIndex.forward( "sales", entryId ) ); + assertNull( lookedup.get( "ou" ) ); + } + + + /** + * Removing all values of an indexed attribute should not leave any tuples in the index, + * nor in the presence index. + */ + @Test + public void testModifyRemoveAllIndexedAttribute() throws Exception + { + DN dn = new DN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." ); + dn.normalize( schemaManager.getNormalizerMapping() ); + + List mods = new ArrayList(); + EntryAttribute attrib = new DefaultEntryAttribute( SchemaConstants.OU_AT, schemaManager + .lookupAttributeTypeRegistry( SchemaConstants.OU_AT ) ); + + Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib ); + mods.add( add ); + + Long entryId = store.getEntryId( dn ); + Entry lookedup = store.lookup( entryId ); + + // before modification: expect "sales" tuple in ou index + Index ouIndex = ( Index ) store.getUserIndex( SchemaConstants.OU_AT ); + assertTrue( store.getPresenceIndex().forward( SchemaConstants.OU_AT_OID, entryId ) ); + assertTrue( ouIndex.forward( "sales", entryId ) ); + assertTrue( lookedup.get( "ou" ).contains( "sales" ) ); + + store.modify( dn, mods ); + + // after modification: no "sales" tuple in ou index + assertFalse( store.getPresenceIndex().forward( SchemaConstants.OU_AT_OID, entryId ) ); + assertFalse( ouIndex.reverse( entryId ) ); + assertFalse( ouIndex.forward( "sales", entryId ) ); + assertNull( lookedup.get( "ou" ) ); + } + + + /** + * Removing an objectClass value should also remove it from the objectClass index. + */ + @Test + public void testModifyRemoveObjectClass() throws Exception + { + DN dn = new DN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." ); + dn.normalize( schemaManager.getNormalizerMapping() ); + + List mods = new ArrayList(); + EntryAttribute attrib = new DefaultEntryAttribute( SchemaConstants.OBJECT_CLASS_AT, schemaManager + .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ) ); + + String attribVal = "person"; + attrib.add( attribVal ); + + Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib ); + mods.add( add ); + + Long entryId = store.getEntryId( dn ); + Entry lookedup = store.lookup( entryId ); + + // before modification: expect "person" tuple in objectClass index + assertTrue( store.getObjectClassIndex().forward( "person", entryId ) ); + assertTrue( lookedup.get( "objectClass" ).contains( "person" ) ); + + store.modify( dn, mods ); + + // after modification: no "person" tuple in objectClass index + assertFalse( store.getObjectClassIndex().forward( "person", entryId ) ); + assertFalse( lookedup.get( "objectClass" ).contains( "person" ) ); + } + + + /** + * Removing all values of the objectClass attribute should not leave any tuples in index. + */ + @Test + public void testModifyRemoveAllObjectClass() throws Exception + { + DN dn = new DN( "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." ); + dn.normalize( schemaManager.getNormalizerMapping() ); + + List mods = new ArrayList(); + EntryAttribute attrib = new DefaultEntryAttribute( SchemaConstants.OBJECT_CLASS_AT, schemaManager + .lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ) ); + + Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib ); + mods.add( add ); + + Long entryId = store.getEntryId( dn ); + Entry lookedup = store.lookup( entryId ); + + // before modification: expect "person" tuple in objectClass index + assertTrue( store.getObjectClassIndex().reverse( entryId ) ); + assertTrue( store.getObjectClassIndex().forward( "person", entryId ) ); + assertTrue( lookedup.get( "objectClass" ).contains( "person" ) ); + + store.modify( dn, mods ); + + // after modification: no tuple in objectClass index + assertFalse( store.getObjectClassIndex().reverse( entryId ) ); + assertFalse( store.getObjectClassIndex().forward( "person", entryId ) ); + assertNull( lookedup.get( "objectClass" ) ); } }