directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1445499 - in /directory/apacheds/trunk/xdbm-partition/src: main/java/org/apache/directory/server/core/partition/impl/btree/ main/java/org/apache/directory/server/xdbm/ main/java/org/apache/directory/server/xdbm/search/impl/ test/java/org/a...
Date Wed, 13 Feb 2013 08:38:31 GMT
Author: elecharny
Date: Wed Feb 13 08:38:30 2013
New Revision: 1445499

URL: http://svn.apache.org/r1445499
Log:
o Added the AdministrativeROle index
o Injected the elements in this index
o Fixed some specific issues with the presence index

Modified:
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java
    directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1445499&r1=1445498&r2=1445499&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
Wed Feb 13 08:38:30 2013
@@ -156,12 +156,16 @@ public abstract class AbstractBTreeParti
     /** the one level scope alias index */
     protected Index<String, Entry, String> oneAliasIdx;
 
+    /** a system index on administrativeRole attribute */
+    protected Index<String, Entry, String> adminRoleIdx;
+
     /** Cached attributes types to avoid lookup all over the code */
     protected AttributeType OBJECT_CLASS_AT;
     protected AttributeType ENTRY_CSN_AT;
     protected AttributeType ENTRY_DN_AT;
     protected AttributeType ENTRY_UUID_AT;
     protected AttributeType ALIASED_OBJECT_NAME_AT;
+    protected AttributeType ADMINISTRATIVE_ROLE_AT;
 
     private static final boolean NO_REVERSE = Boolean.FALSE;
     private static final boolean WITH_REVERSE = Boolean.TRUE;
@@ -192,6 +196,7 @@ public abstract class AbstractBTreeParti
         ENTRY_CSN_AT = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT );
         ENTRY_DN_AT = schemaManager.getAttributeType( SchemaConstants.ENTRY_DN_AT );
         ENTRY_UUID_AT = schemaManager.getAttributeType( SchemaConstants.ENTRY_UUID_AT );
+        ADMINISTRATIVE_ROLE_AT = schemaManager.getAttributeType( SchemaConstants.ADMINISTRATIVE_ROLE_AT
);
     }
 
 
@@ -331,6 +336,14 @@ public abstract class AbstractBTreeParti
             addIndex( index );
         }
 
+        if ( getAdministrativeRoleIndex() == null )
+        {
+            Index<String, Entry, String> index = createSystemIndex( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID,
+                partitionPath,
+                NO_REVERSE );
+            addIndex( index );
+        }
+
         // convert and initialize system indices
         for ( String oid : systemIndices.keySet() )
         {
@@ -350,6 +363,7 @@ public abstract class AbstractBTreeParti
             .get( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID );
         objectClassIdx = ( Index<String, Entry, String> ) systemIndices.get( SchemaConstants.OBJECT_CLASS_AT_OID
);
         entryCsnIdx = ( Index<String, Entry, String> ) systemIndices.get( SchemaConstants.ENTRY_CSN_AT_OID
);
+        adminRoleIdx = ( Index<String, Entry, String> ) systemIndices.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID
);
     }
 
 
@@ -585,7 +599,7 @@ public abstract class AbstractBTreeParti
         try
         {
             Entry entry = ( ( ClonedServerEntry ) addContext.getEntry() ).getClonedEntry();
-            
+
             Dn entryDn = entry.getDn();
 
             // check if the entry already exists
@@ -697,6 +711,21 @@ public abstract class AbstractBTreeParti
 
             entryCsnIdx.add( entryCsn.getString(), id );
 
+            // Update the AdministrativeRole index, if needed
+            if ( entry.containsAttribute( ADMINISTRATIVE_ROLE_AT ) )
+            {
+                // We may have more than one role
+                Attribute adminRoles = entry.get( ADMINISTRATIVE_ROLE_AT );
+
+                for ( Value<?> value : adminRoles )
+                {
+                    adminRoleIdx.add( ( String ) value.getNormValue(), id );
+                }
+
+                // Adds only those attributes that are indexed
+                presenceIdx.add( ADMINISTRATIVE_ROLE_AT.getOid(), id );
+            }
+
             // Now work on the user defined userIndices
             for ( Attribute attribute : entry )
             {
@@ -738,7 +767,7 @@ public abstract class AbstractBTreeParti
 
                 // Remove the EntryDN attribute
                 entry.removeAttributes( ENTRY_DN_AT );
-                
+
                 // And finally add the entry into the master table
                 master.put( id, entry );
             }
@@ -805,9 +834,9 @@ public abstract class AbstractBTreeParti
 
             // We now defer the deletion to the implementing class
             Entry deletedEntry = delete( id );
-            
+
             updateCache( deleteContext );
-            
+
             return deletedEntry;
         }
         catch ( LdapException le )
@@ -918,6 +947,21 @@ public abstract class AbstractBTreeParti
             // Update the rdn, oneLevel, subLevel, and entryCsn indexes
             entryCsnIdx.drop( entry.get( ENTRY_CSN_AT ).getString(), id );
 
+            // Update the AdministrativeRole index, if needed
+            if ( entry.containsAttribute( ADMINISTRATIVE_ROLE_AT ) )
+            {
+                // We may have more than one role
+                Attribute adminRoles = entry.get( ADMINISTRATIVE_ROLE_AT );
+
+                for ( Value<?> value : adminRoles )
+                {
+                    adminRoleIdx.drop( ( String ) value.getNormValue(), id );
+                }
+
+                // Deletes only those attributes that are indexed
+                presenceIdx.drop( ADMINISTRATIVE_ROLE_AT.getOid(), id );
+            }
+
             // Update the user indexes
             for ( Attribute attribute : entry )
             {
@@ -958,7 +1002,7 @@ public abstract class AbstractBTreeParti
             {
                 sync();
             }
-            
+
             return entry;
         }
         catch ( Exception e )
@@ -1032,7 +1076,7 @@ public abstract class AbstractBTreeParti
         try
         {
             Dn dn = buildEntryDn( id );
-    
+
             return fetch( id, dn );
         }
         catch ( Exception e )
@@ -1058,17 +1102,17 @@ public abstract class AbstractBTreeParti
         try
         {
             Entry entry = lookupCache( id );
-            
+
             if ( entry != null )
             {
                 if ( !entry.containsAttribute( ENTRY_DN_AT ) )
                 {
                     entry.add( ENTRY_DN_AT, dn.getName() );
                 }
-                
+
                 return new ClonedServerEntry( entry );
             }
-            
+
             lockRead();
 
             try
@@ -1094,7 +1138,7 @@ public abstract class AbstractBTreeParti
                 }
 
                 addToCache( id, entry );
-                
+
                 return new ClonedServerEntry( entry );
             }
 
@@ -1120,9 +1164,9 @@ public abstract class AbstractBTreeParti
             Entry modifiedEntry = modify( modifyContext.getDn(),
                 modifyContext.getModItems().toArray( new Modification[]
                     {} ) );
-            
+
             modifyContext.setAlteredEntry( modifiedEntry );
-            
+
             updateCache( modifyContext );
         }
         catch ( Exception e )
@@ -1167,7 +1211,7 @@ public abstract class AbstractBTreeParti
 
         // Remove the EntryDN
         entry.removeAttributes( ENTRY_DN_AT );
-        
+
         master.put( id, entry );
 
         if ( isSyncOnWrite.get() )
@@ -1223,9 +1267,23 @@ public abstract class AbstractBTreeParti
                 presenceIdx.add( modsOid, id );
             }
         }
+        // Special case for the AdministrativeRole index
+        else if ( modsOid.equals( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID ) )
+        {
+            // We may have more than one role 
+            for ( Value<?> value : mods )
+            {
+                adminRoleIdx.add( ( String ) value.getNormValue(), id );
+            }
 
-        // add all the values in mods to the same attribute in the entry
+            // If the attr didn't exist for this id add it to presence index
+            if ( !presenceIdx.forward( modsOid, id ) )
+            {
+                presenceIdx.add( modsOid, id );
+            }
+        }
 
+        // add all the values in mods to the same attribute in the entry
         for ( Value<?> value : mods )
         {
             entry.add( mods.getAttributeType(), value );
@@ -1307,6 +1365,21 @@ public abstract class AbstractBTreeParti
                 presenceIdx.drop( modsOid, id );
             }
         }
+        // Special case for the AdministrativeRole index
+        else if ( attributeType.equals( ADMINISTRATIVE_ROLE_AT ) )
+        {
+            // Remove the previous values
+            for ( Value<?> value : entry.get( ADMINISTRATIVE_ROLE_AT ) )
+            {
+                objectClassIdx.drop( ( String ) value.getNormValue(), id );
+            }
+
+            // And add the new ones 
+            for ( Value<?> value : mods )
+            {
+                adminRoleIdx.add( ( String ) value.getNormValue(), id );
+            }
+        }
 
         String aliasAttributeOid = schemaManager.getAttributeTypeRegistry().getOidByName(
             SchemaConstants.ALIASED_OBJECT_NAME_AT );
@@ -1412,6 +1485,24 @@ public abstract class AbstractBTreeParti
                 presenceIdx.drop( modsOid, id );
             }
         }
+        // Special case for the AdministrativeRole index
+        else if ( modsOid.equals( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID ) )
+        {
+            // We may have more than one role 
+            for ( Value<?> value : mods )
+            {
+                adminRoleIdx.drop( ( String ) value.getNormValue(), id );
+            }
+
+            /*
+             * If no attribute values exist for this entryId in the index then
+             * we remove the presence index entry for the removed attribute.
+             */
+            if ( null == adminRoleIdx.reverseLookup( id ) )
+            {
+                presenceIdx.drop( modsOid, id );
+            }
+        }
 
         AttributeType attrType = schemaManager.lookupAttributeTypeRegistry( modsOid );
 
@@ -1566,7 +1657,7 @@ public abstract class AbstractBTreeParti
 
         // Remove the EntryDN
         modifiedEntry.removeAttributes( ENTRY_DN_AT );
-        
+
         master.put( entryId, modifiedEntry );
 
         if ( isSyncOnWrite.get() )
@@ -1767,7 +1858,7 @@ public abstract class AbstractBTreeParti
             {
                 rename( oldDn, newRdn, deleteOldRdn, null );
             }
-            
+
             updateCache( renameContext );
         }
         catch ( Exception e )
@@ -1881,7 +1972,7 @@ public abstract class AbstractBTreeParti
 
         // Remove the EntryDN
         entry.removeAttributes( ENTRY_DN_AT );
-        
+
         // And save the modified entry
         master.put( oldId, entry );
     }
@@ -2346,6 +2437,16 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    public Index<String, Entry, String> getAdministrativeRoleIndex()
+    {
+        return ( Index<String, Entry, String> ) systemIndices.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings("unchecked")
     public Index<String, Entry, String> getPresenceIndex()
     {
         return ( Index<String, Entry, String> ) systemIndices.get( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID
);
@@ -2745,8 +2846,8 @@ public abstract class AbstractBTreeParti
     {
         masterTableLock.writeLock().unlock();
     }
-    
-    
+
+
     /**
      * updates the cache based on the type of OperationContext
      * 
@@ -2757,7 +2858,7 @@ public abstract class AbstractBTreeParti
         // partition implementations should override this if they want to use cache
     }
 
-    
+
     /**
      * looks up for the entry with the given ID in the cache
      *
@@ -2768,8 +2869,8 @@ public abstract class AbstractBTreeParti
     {
         return null;
     }
-    
-    
+
+
     /**
      * adds the given entry to cache
      *  

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java?rev=1445499&r1=1445498&r2=1445499&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java
Wed Feb 13 08:38:30 2013
@@ -98,7 +98,8 @@ public interface Store
             ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID,
             SchemaConstants.ENTRY_CSN_AT_OID,
             SchemaConstants.ENTRY_UUID_AT_OID,
-            SchemaConstants.OBJECT_CLASS_AT_OID
+            SchemaConstants.OBJECT_CLASS_AT_OID,
+            SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID
     };
 
     public static final Set<String> SYS_INDEX_OIDS = Collections.unmodifiableSet( new
HashSet<String>( Arrays

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java?rev=1445499&r1=1445498&r2=1445499&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java
Wed Feb 13 08:38:30 2013
@@ -306,7 +306,7 @@ public class DefaultOptimizer<E> impleme
         if ( db.hasIndexOn( node.getAttributeType() ) )
         {
             Index<V, E, String> idx = ( Index<V, E, String> ) db.getIndex( node.getAttributeType()
);
-            
+
             if ( isGreaterThan )
             {
                 return idx.greaterThanCount( node.getValue().getValue() );
@@ -320,8 +320,8 @@ public class DefaultOptimizer<E> impleme
         // count for non-indexed attribute is unknown so we presume da worst
         return Long.MAX_VALUE;
     }
-    
-    
+
+
     /**
      * Get a scan count based on a Substring node : we will count the entries that are greater
      * than ABC where the filter is (attr=ABC*). Any other filter won't be evaluated (for
instance,
@@ -337,9 +337,9 @@ public class DefaultOptimizer<E> impleme
         if ( db.hasIndexOn( node.getAttributeType() ) )
         {
             Index<String, E, String> idx = ( Index<String, E, String> ) db.getIndex(
node.getAttributeType() );
-            
+
             String initial = node.getInitial();
-            
+
             if ( Strings.isEmpty( initial ) )
             {
                 // Not a (attr=ABC*) filter : full scan
@@ -391,8 +391,15 @@ public class DefaultOptimizer<E> impleme
     {
         if ( db.hasUserIndexOn( node.getAttributeType() ) )
         {
-            Index<String, Entry, String> idx = db.getPresenceIndex();
-            return idx.count( node.getAttributeType().getOid() );
+            Index<String, Entry, String> presenceIndex = db.getPresenceIndex();
+
+            return presenceIndex.count( node.getAttributeType().getOid() );
+        }
+        else if ( node.getAttributeType().getOid().equals( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID
) )
+        {
+            Index<String, Entry, String> presenceIndex = db.getPresenceIndex();
+
+            return presenceIndex.count( node.getAttributeType().getOid() );
         }
         else if ( db.hasSystemIndexOn( node.getAttributeType() )
             || ( node.getAttributeType().getOid() == SchemaConstants.ENTRY_UUID_AT_OID )
)

Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java?rev=1445499&r1=1445498&r2=1445499&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java
Wed Feb 13 08:38:30 2013
@@ -33,7 +33,6 @@ import java.util.UUID;
 
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.csn.CsnFactory;
-import org.apache.directory.api.ldap.model.cursor.Cursor;
 import org.apache.directory.api.ldap.model.entry.Attribute;
 import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
@@ -57,7 +56,6 @@ import org.apache.directory.server.const
 import org.apache.directory.server.core.api.entry.ClonedServerEntry;
 import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
-import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.server.xdbm.IndexNotFoundException;
 import org.apache.directory.server.xdbm.StoreUtils;
 import org.junit.After;
@@ -286,7 +284,7 @@ public class AvlPartitionTest
 
         Iterator<String> systemIndices = partition.getSystemIndices();
 
-        for ( int i = 0; i < 7; i++ )
+        for ( int i = 0; i < 8; i++ )
         {
             assertTrue( systemIndices.hasNext() );
             assertNotNull( systemIndices.next() );



Mime
View raw message