You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/05/01 19:22:23 UTC

svn commit: r1332757 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/ interceptors/collective/src/main/java/org/apache/directory/server/core/collective/ interceptors/operational/src/main/j...

Author: elecharny
Date: Tue May  1 17:22:23 2012
New Revision: 1332757

URL: http://svn.apache.org/viewvc?rev=1332757&view=rev
Log:
Removed the call to getSearchControls(). The gain is around 10% in performance.

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java
    directory/apacheds/trunk/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
    directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java?rev=1332757&r1=1332756&r2=1332757&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java Tue May  1 17:22:23 2012
@@ -26,8 +26,6 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.naming.directory.SearchControls;
-
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
@@ -79,6 +77,9 @@ public abstract class SearchingOperation
     /** A set containing the returning attributeTypesOptions */
     protected Set<AttributeTypeOptions> returningAttributes;
 
+    /** The set of attributes to return as String */
+    protected String[] returningAttributesString;
+
     /** A flag if the search operation is abandoned */
     protected boolean abandoned = false;
 
@@ -128,29 +129,34 @@ public abstract class SearchingOperation
     }
 
 
-    public void setReturningAttributes( String[] attributesIds ) throws LdapException
+    public void setReturningAttributes( String... attributesIds ) throws LdapException
     {
-        if ( attributesIds != null && attributesIds.length != 0 )
+        if ( ( attributesIds != null ) && ( attributesIds.length != 0 ) )
         {
             returningAttributes = new HashSet<AttributeTypeOptions>();
-
+            Set<String> attributesString = new HashSet<String>();
+            int nbInvalid = 0;
+            
             for ( String returnAttribute : attributesIds )
             {
                 if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
                 {
                     noAttributes = true;
+                    attributesString.add( SchemaConstants.NO_ATTRIBUTE );
                     continue;
                 }
 
                 if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
                 {
                     allOperationalAttributes = true;
+                    attributesString.add( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
                     continue;
                 }
 
                 if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
                 {
                     allUserAttributes = true;
+                    attributesString.add( SchemaConstants.ALL_USER_ATTRIBUTES );
                     continue;
                 }
 
@@ -164,20 +170,36 @@ public abstract class SearchingOperation
                     AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options );
 
                     returningAttributes.add( attrOptions );
+                    attributesString.add( attributeType.getOid() );
                 }
                 catch ( LdapNoSuchAttributeException nsae )
                 {
                     LOG.warn( "Requested attribute {} does not exist in the schema, it will be ignored",
                         returnAttribute );
                     // Unknown attributes should be silently ignored, as RFC 2251 states
+                    nbInvalid++;
                 }
             }
 
-            // reset the noAttrubte flag if it is already set cause that will be ignored if any other AT is requested
+            // reset the noAttribute flag if it is already set cause that will be ignored if any other AT is requested
             if ( noAttributes && ( allUserAttributes || allOperationalAttributes || ( !returningAttributes.isEmpty() ) ) )
             {
                 noAttributes = false;
             }
+            
+            if ( attributesString.size() > 0 )
+            {
+                returningAttributesString = attributesString.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
+            }
+            else if ( nbInvalid > 0 )
+            {
+                returningAttributesString = ArrayUtils.EMPTY_STRING_ARRAY;
+            }
+            else
+            {
+                returningAttributesString = new String[]{ SchemaConstants.ALL_USER_ATTRIBUTES };
+                allUserAttributes = true;
+            }
         }
     }
 
@@ -345,69 +367,11 @@ public abstract class SearchingOperation
 
 
     /**
-     * Creates a new SearchControls object populated with the parameters
-     * contained in this SearchOperationContext in normalized form.
-     *
-     * @return a new SearchControls object
-     */
-    public SearchControls getSearchControls()
-    {
-        return getSearchControls( false );
-    }
-
-
-    /**
-     * Creates a new SearchControls object populated with the parameters
-     * contained in this SearchOperationContext.
-     *
-     * @param denormalized true if attribute values are <b>not</b> normalized
-     * @return a new SearchControls object
+     * @return the returningAttributesString
      */
-    public SearchControls getSearchControls( boolean denormalized )
+    public String[] getReturningAttributesString()
     {
-        SearchControls controls = new SearchControls();
-        controls.setCountLimit( sizeLimit );
-        controls.setSearchScope( scope.getScope() );
-        controls.setTimeLimit( timeLimit );
-
-        Set<String> allReturningAttributes = new HashSet<String>();
-
-        if ( noAttributes )
-        {
-            allReturningAttributes.add( SchemaConstants.NO_ATTRIBUTE );
-        }
-
-        if ( allUserAttributes )
-        {
-            allReturningAttributes.add( SchemaConstants.ALL_USER_ATTRIBUTES );
-        }
-
-        if ( allOperationalAttributes )
-        {
-            allReturningAttributes.add( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
-        }
-
-        if ( returningAttributes != null )
-        {
-            for ( AttributeTypeOptions at : returningAttributes )
-            {
-                if ( denormalized )
-                {
-                    allReturningAttributes.add( at.getAttributeType().getName() );
-                }
-                else
-                {
-                    allReturningAttributes.add( at.getAttributeType().getOid() );
-                }
-            }
-        }
-
-        if ( allReturningAttributes.size() > 0 )
-        {
-            controls.setReturningAttributes( allReturningAttributes.toArray( ArrayUtils.EMPTY_STRING_ARRAY ) );
-        }
-
-        return controls;
+        return returningAttributesString;
     }
 
 

Modified: directory/apacheds/trunk/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java?rev=1332757&r1=1332756&r2=1332757&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java Tue May  1 17:22:23 2012
@@ -87,7 +87,7 @@ public class CollectiveAttributeIntercep
     {
         public boolean accept( SearchingOperationContext operation, Entry entry ) throws Exception
         {
-            String[] retAttrs = operation.getSearchControls().getReturningAttributes();
+            String[] retAttrs = operation.getReturningAttributesString();
             addCollectiveAttributes( operation, entry, retAttrs );
 
             return true;

Modified: directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=1332757&r1=1332756&r2=1332757&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java Tue May  1 17:22:23 2012
@@ -95,7 +95,7 @@ public class OperationalAttributeInterce
     {
         public boolean accept( SearchingOperationContext operation, Entry entry ) throws Exception
         {
-            if ( operation.getSearchControls().getReturningAttributes() == null )
+            if ( operation.getReturningAttributesString() == null )
             {
                 return true;
             }
@@ -111,7 +111,7 @@ public class OperationalAttributeInterce
     {
         public boolean accept( SearchingOperationContext operation, Entry entry ) throws Exception
         {
-            return operation.getSearchControls().getReturningAttributes() != null
+            return operation.getReturningAttributesString() != null
                 || filterOperationalAttributes( entry );
         }
     }

Modified: directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=1332757&r1=1332756&r2=1332757&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Tue May  1 17:22:23 2012
@@ -30,8 +30,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.naming.directory.SearchControls;
-
 import org.apache.directory.server.core.shared.SchemaService;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.InterceptorEnum;
@@ -389,18 +387,18 @@ public class SchemaInterceptor extends B
      * " If there are attribute descriptions in "
      * " the list which are not recognized, they are ignored by the server."
      *
-     * @param searchCtls The SearchControls we will filter
+     * @param searchContext The SearchControls we will filter
      */
     // This will suppress PMD.EmptyCatchBlock warnings in this method
     @SuppressWarnings("PMD.EmptyCatchBlock")
-    private void filterAttributesToReturn( SearchControls searchCtls )
+    private void filterAttributesToReturn( SearchOperationContext searchContext ) throws LdapException
     {
-        String[] attributes = searchCtls.getReturningAttributes();
+        String[] attributes = searchContext.getReturningAttributesString();
 
         if ( ( attributes == null ) || ( attributes.length == 0 ) )
         {
             // We have no attributes, that means "*" (all users attributes)
-            searchCtls.setReturningAttributes( SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+            //searchContext.setReturningAttributes( SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
             return;
         }
 
@@ -472,7 +470,7 @@ public class SchemaInterceptor extends B
         {
             // We just have to pass the special 1.1 attribute,
             // as we don't want to return any attribute
-            searchCtls.setReturningAttributes( SchemaConstants.NO_ATTRIBUTE_ARRAY );
+            searchContext.setReturningAttributes( SchemaConstants.NO_ATTRIBUTE_ARRAY );
             return;
         }
 
@@ -486,7 +484,7 @@ public class SchemaInterceptor extends B
             newAttributesList[pos++] = entry.getValue();
         }
 
-        searchCtls.setReturningAttributes( newAttributesList );
+        searchContext.setReturningAttributes( newAttributesList );
     }
 
 
@@ -1459,15 +1457,14 @@ public class SchemaInterceptor extends B
     public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
     {
         Dn base = searchContext.getDn();
-        SearchControls searchCtls = searchContext.getSearchControls();
         ExprNode filter = searchContext.getFilter();
 
         // We have to eliminate bad attributes from the request, accordingly
         // to RFC 2251, chap. 4.5.1. Basically, all unknown attributes are removed
         // from the list
-        if ( searchCtls.getReturningAttributes() != null )
+        if ( searchContext.getReturningAttributesString() != null )
         {
-            filterAttributesToReturn( searchCtls );
+            filterAttributesToReturn( searchContext );
         }
 
         // We also have to check the H/R flag for the filter attributes
@@ -1480,7 +1477,7 @@ public class SchemaInterceptor extends B
         {
             EntryFilteringCursor cursor = next( searchContext );
 
-            if ( searchCtls.getReturningAttributes() != null )
+            if ( searchContext.getReturningAttributesString() != null )
             {
                 cursor.addEntryFilter( topFilter );
                 return cursor;
@@ -1529,7 +1526,7 @@ public class SchemaInterceptor extends B
                 {
                     // call.setBypass( true );
                     Entry serverEntry = SchemaService.getSubschemaEntry( directoryService,
-                        searchCtls.getReturningAttributes() );
+                        searchContext.getReturningAttributesString() );
                     serverEntry.setDn( base );
                     return new BaseEntryFilteringCursor( new SingletonCursor<Entry>( serverEntry ), searchContext );
                 }
@@ -1547,7 +1544,7 @@ public class SchemaInterceptor extends B
                 {
                     // call.setBypass( true );
                     Entry serverEntry = SchemaService.getSubschemaEntry( directoryService,
-                        searchCtls.getReturningAttributes() );
+                        searchContext.getReturningAttributesString() );
                     serverEntry.setDn( base );
                     EntryFilteringCursor cursor = new BaseEntryFilteringCursor(
                         new SingletonCursor<Entry>( serverEntry ), searchContext );