directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1572064 - in /directory/apacheds/trunk: interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/ xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/
Date Wed, 26 Feb 2014 14:43:58 GMT
Author: elecharny
Date: Wed Feb 26 14:43:57 2014
New Revision: 1572064

URL: http://svn.apache.org/r1572064
Log:
Fix for DIRSERVER-1961 :
- the transformation of an EmptyEvaluator into a BaseLevelScopeEvaluator is not anymore done
- the removeObjectClass() method has been fixed to not keep a more selective node than necessary.

Modified:
    directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java

Modified: directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java?rev=1572064&r1=1572063&r2=1572064&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
(original)
+++ directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
Wed Feb 26 14:43:57 2014
@@ -37,6 +37,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.filter.ObjectClassNode;
 import org.apache.directory.api.ldap.model.filter.OrNode;
 import org.apache.directory.api.ldap.model.filter.PresenceNode;
+import org.apache.directory.api.ldap.model.filter.UndefinedNode;
 import org.apache.directory.api.ldap.model.name.Ava;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.name.Rdn;
@@ -305,11 +306,12 @@ public class NormalizationInterceptor ex
 
 
     /**
-     * Remove the (ObjectClass=*) node from brancheNode, if we have one.
+     * Remove the (ObjectClass=*) node from an AndNode, if we have one.
      */
-    private ExprNode handleBranchNode( ExprNode node, BranchNode newBranchNode )
+    private ExprNode handleAndNode( ExprNode node )
     {
         int nbNodes = 0;
+        AndNode newAndNode = new AndNode();
 
         for ( ExprNode child : ( ( BranchNode ) node ).getChildren() )
         {
@@ -317,31 +319,76 @@ public class NormalizationInterceptor ex
 
             if ( !( modifiedNode instanceof ObjectClassNode ) )
             {
-                newBranchNode.addNode( modifiedNode );
+                newAndNode.addNode( modifiedNode );
                 nbNodes++;
             }
+
+            if ( modifiedNode instanceof UndefinedNode )
+            {
+                // We can just return an Undefined node as nothing will get selected
+                return UndefinedNode.UNDEFINED_NODE;
+            }
         }
 
         switch ( nbNodes )
         {
             case 0:
-                // Unlikely... But (&(ObjectClass=*)) is still an option 
+                // Unlikely... But (&(ObjectClass=*)) or (|(ObjectClass=*)) are still
an option
                 return ObjectClassNode.OBJECT_CLASS_NODE;
 
             case 1:
-                if ( newBranchNode instanceof NotNode )
-                {
-                    return newBranchNode;
-                }
-                else
-                {
-                    // We can safely remove the AND/OR node and replace it with its first
child
-                    return newBranchNode.getFirstChild();
-                }
+                // We can safely remove the AND/OR node and replace it with its first child
+                return newAndNode.getFirstChild();
 
             default:
-                return newBranchNode;
+                return newAndNode;
+        }
+    }
+
+
+    /**
+     * Remove the (ObjectClass=*) node from a NotNode, if we have one.
+     */
+    private ExprNode handleNotNode( ExprNode node )
+    {
+        for ( ExprNode child : ( ( BranchNode ) node ).getChildren() )
+        {
+            ExprNode modifiedNode = removeObjectClass( child );
+
+            if ( modifiedNode instanceof ObjectClassNode )
+            {
+                // We don't want any entry which has an ObjectClass, return an undefined
node
+                return UndefinedNode.UNDEFINED_NODE;
+            }
+
+            if ( modifiedNode instanceof UndefinedNode )
+            {
+                // Here, we will select everything
+                return ObjectClassNode.OBJECT_CLASS_NODE;
+            }
+        }
+
+        return node;
+    }
+
+
+    /**
+     * Remove the (ObjectClass=*) node from an OrNode, if we have one.
+     */
+    private ExprNode handleOrNode( ExprNode node )
+    {
+        for ( ExprNode child : ( ( BranchNode ) node ).getChildren() )
+        {
+            ExprNode modifiedNode = removeObjectClass( child );
+
+            if ( modifiedNode instanceof ObjectClassNode )
+            {
+                // We can return immediately with an ObjectClass node
+                return ObjectClassNode.OBJECT_CLASS_NODE;
+            }
         }
+
+        return node;
     }
 
 
@@ -352,18 +399,19 @@ public class NormalizationInterceptor ex
     {
         if ( node instanceof LeafNode )
         {
-            LeafNode ln = ( LeafNode ) node;
-            
-            if ( ln.getAttributeType() == OBJECT_CLASS_AT )
+            LeafNode leafNode = ( LeafNode ) node;
+
+            if ( leafNode.getAttributeType() == OBJECT_CLASS_AT )
             {
-                if ( ln instanceof PresenceNode )
+                if ( leafNode instanceof PresenceNode )
                 {
                     // We can safely remove the node and return an undefined node
                     return ObjectClassNode.OBJECT_CLASS_NODE;
                 }
-                else if ( ln instanceof EqualityNode )
+                else if ( leafNode instanceof EqualityNode )
                 {
-                    Value<String> v = ( ( EqualityNode<String> ) ln ).getValue();
+                    Value<String> v = ( ( EqualityNode<String> ) leafNode ).getValue();
+
                     if( v.getNormValue().equals( SchemaConstants.TOP_OC ) )
                     {
                         // Here too we can safely remove the node and return an undefined
node
@@ -372,28 +420,22 @@ public class NormalizationInterceptor ex
                 }
             }
         }
-        
+
         // --------------------------------------------------------------------
-        //                 H A N D L E   B R A N C H   N O D E S       
+        //                 H A N D L E   B R A N C H   N O D E S
         // --------------------------------------------------------------------
-        
+
         if ( node instanceof AndNode )
         {
-            AndNode newAndNode = new AndNode();
-
-            return handleBranchNode( node, newAndNode );
+            return handleAndNode( node );
         }
         else if ( node instanceof OrNode )
         {
-            OrNode newOrNode = new OrNode();
-
-            return handleBranchNode( node, newOrNode );
+            return handleOrNode( node );
         }
         else if ( node instanceof NotNode )
         {
-            NotNode newNotNode = new NotNode();
-
-            return handleBranchNode( node, newNotNode );
+            return handleNotNode( node );
         }
         else
         {

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java?rev=1572064&r1=1572063&r2=1572064&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
Wed Feb 26 14:43:57 2014
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License.
- * 
+ *
  */
 package org.apache.directory.server.xdbm.search.impl;
 
@@ -47,7 +47,6 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.search.PartitionSearchResult;
 import org.apache.directory.server.xdbm.search.SearchEngine;
 import org.apache.directory.server.xdbm.search.evaluator.BaseLevelScopeEvaluator;
-import org.apache.directory.server.xdbm.search.evaluator.EmptyEvaluator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,7 +54,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Given a search filter and a scope the search engine identifies valid
  * candidate entries returning their ids.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class DefaultSearchEngine implements SearchEngine
@@ -149,13 +148,13 @@ public class DefaultSearchEngine impleme
         // --------------------------------------------------------------------
         Dn aliasedBase = null;
 
-        
+
         if ( db.getAliasCache() != null )
         {
             Element aliasBaseElement = db.getAliasCache().get( baseId );
-            
+
             if ( aliasBaseElement != null )
-            { 
+            {
                 aliasedBase = (Dn)(aliasBaseElement).getObjectValue();
             }
         }
@@ -163,7 +162,7 @@ public class DefaultSearchEngine impleme
         {
             aliasedBase = db.getAliasIndex().reverseLookup( baseId );
         }
-        
+
         Dn effectiveBase = baseDn;
         String effectiveBaseId = baseId;
 
@@ -202,7 +201,7 @@ public class DefaultSearchEngine impleme
                 evaluator = evaluatorBuilder.build( filter );
 
                 // Special case if the filter selects no candidate
-                if ( ( evaluator == null ) || ( evaluator instanceof EmptyEvaluator ) )
+                if ( evaluator == null ) //|| ( evaluator instanceof EmptyEvaluator ) )
                 {
                     ScopeNode node = new ScopeNode( aliasDerefMode, effectiveBase, effectiveBaseId,
scope );
                     evaluator = new BaseLevelScopeEvaluator<Entry>( db, node );
@@ -265,7 +264,7 @@ public class DefaultSearchEngine impleme
             {
                 IndexEntry<String, String> indexEntry = cursor.get();
 
-                // Here, the indexEntry contains a <UUID, Entry> tuple. Convert it
to <UUID, UUID> 
+                // Here, the indexEntry contains a <UUID, Entry> tuple. Convert it
to <UUID, UUID>
                 IndexEntry<String, String> forwardIndexEntry = new IndexEntry<String,
String>();
                 forwardIndexEntry.setKey( indexEntry.getKey() );
                 forwardIndexEntry.setId( indexEntry.getKey() );



Mime
View raw message