directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1303043 - in /directory: apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/ apacheds/tr...
Date Tue, 20 Mar 2012 17:49:25 GMT
Author: elecharny
Date: Tue Mar 20 17:49:25 2012
New Revision: 1303043

URL: http://svn.apache.org/viewvc?rev=1303043&view=rev
Log:
o Get rid of the getNormalized() method in JdbmIndex and AvlIndex : the values are already
normalized anyway
o Fixed a couple of places where the values weren't normalized before being injected into
the index
o Some entries formating
o Fixed the parser that was not creating an Assertion Value depending on the AttributeType
syntax

Modified:
    directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
    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/Index.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
    directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/StoreUtils.java
    directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1303043&r1=1303042&r2=1303043&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
(original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
Tue Mar 20 17:49:25 2012
@@ -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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.core.partition.impl.btree.jdbm;
 
@@ -47,7 +47,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-/** 
+/**
  * A Jdbm based index implementation. It creates an Index for a give AttributeType.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -219,7 +219,7 @@ public class JdbmIndex<K, O> extends Abs
         comp = new SerializableComparator<K>( mr.getOid() );
 
         /*
-         * The forward key/value map stores attribute values to master table 
+         * The forward key/value map stores attribute values to master table
          * primary keys.  A value for an attribute can occur several times in
          * different entries so the forward map can have more than one value.
          */
@@ -232,7 +232,7 @@ public class JdbmIndex<K, O> extends Abs
         /*
          * Now the reverse map stores the primary key into the master table as
          * the key and the values of attributes as the value.  If an attribute
-         * is single valued according to its specification based on a schema 
+         * is single valued according to its specification based on a schema
          * then duplicate keys should not be allowed within the reverse table.
          */
         if ( attributeType.isSingleValued() )
@@ -295,7 +295,7 @@ public class JdbmIndex<K, O> extends Abs
      * Gets the working directory path to something other than the default. Sometimes more
      * performance is gained by locating indices on separate disk spindles.
      *
-     * @return optional working directory path 
+     * @return optional working directory path
      */
     public URI getWkDirPath()
     {
@@ -320,13 +320,13 @@ public class JdbmIndex<K, O> extends Abs
      */
     public int count( K attrVal ) throws Exception
     {
-        return forward.count( getNormalized( attrVal ) );
+        return forward.count( attrVal );
     }
 
 
     public int greaterThanCount( K attrVal ) throws Exception
     {
-        return forward.greaterThanCount( getNormalized( attrVal ) );
+        return forward.greaterThanCount( attrVal );
     }
 
 
@@ -335,7 +335,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public int lessThanCount( K attrVal ) throws Exception
     {
-        return forward.lessThanCount( getNormalized( attrVal ) );
+        return forward.lessThanCount( attrVal );
     }
 
 
@@ -348,7 +348,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public Long forwardLookup( K attrVal ) throws Exception
     {
-        return forward.get( getNormalized( attrVal ) );
+        return forward.get( attrVal );
     }
 
 
@@ -370,11 +370,9 @@ public class JdbmIndex<K, O> extends Abs
      */
     public synchronized void add( K attrVal, Long id ) throws Exception
     {
-        K normalizedValue = getNormalized( attrVal );
-
         // The pair to be removed must exists
-        forward.put( normalizedValue, id );
-        reverse.put( id, normalizedValue );
+        forward.put( attrVal, id );
+        reverse.put( id, attrVal );
     }
 
 
@@ -383,13 +381,11 @@ public class JdbmIndex<K, O> extends Abs
      */
     public synchronized void drop( K attrVal, Long id ) throws Exception
     {
-        K normalizedValue = getNormalized( attrVal );
-
         // The pair to be removed must exists
-        if ( forward.has( normalizedValue, id ) )
+        if ( forward.has( attrVal, id ) )
         {
-            forward.remove( normalizedValue, id );
-            reverse.remove( id, normalizedValue );
+            forward.remove( attrVal, id );
+            reverse.remove( id, attrVal );
         }
     }
 
@@ -465,7 +461,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean forward( K attrVal ) throws Exception
     {
-        return forward.has( getNormalized( attrVal ) );
+        return forward.has( attrVal );
     }
 
 
@@ -474,7 +470,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean forward( K attrVal, Long id ) throws Exception
     {
-        return forward.has( getNormalized( attrVal ), id );
+        return forward.has( attrVal, id );
     }
 
 
@@ -492,7 +488,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverse( Long id, K attrVal ) throws Exception
     {
-        return forward.has( getNormalized( attrVal ), id );
+        return forward.has( attrVal, id );
     }
 
 
@@ -501,7 +497,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean forwardGreaterOrEq( K attrVal ) throws Exception
     {
-        return forward.hasGreaterOrEqual( getNormalized( attrVal ) );
+        return forward.hasGreaterOrEqual( attrVal );
     }
 
 
@@ -510,7 +506,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean forwardGreaterOrEq( K attrVal, Long id ) throws Exception
     {
-        return forward.hasGreaterOrEqual( getNormalized( attrVal ), id );
+        return forward.hasGreaterOrEqual( attrVal, id );
     }
 
 
@@ -519,7 +515,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean forwardLessOrEq( K attrVal ) throws Exception
     {
-        return forward.hasLessOrEqual( getNormalized( attrVal ) );
+        return forward.hasLessOrEqual( attrVal );
     }
 
 
@@ -528,7 +524,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean forwardLessOrEq( K attrVal, Long id ) throws Exception
     {
-        return forward.hasLessOrEqual( getNormalized( attrVal ), id );
+        return forward.hasLessOrEqual( attrVal, id );
     }
 
 
@@ -546,7 +542,7 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverseGreaterOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasGreaterOrEqual( id, getNormalized( attrVal ) );
+        return reverse.hasGreaterOrEqual( id, attrVal );
     }
 
 
@@ -564,12 +560,12 @@ public class JdbmIndex<K, O> extends Abs
      */
     public boolean reverseLessOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasLessOrEqual( id, getNormalized( attrVal ) );
+        return reverse.hasLessOrEqual( id, attrVal );
     }
 
 
     // ------------------------------------------------------------------------
-    // Maintenance Methods 
+    // Maintenance Methods
     // ------------------------------------------------------------------------
     /**
      * @see org.apache.directory.server.xdbm.Index#close()
@@ -601,43 +597,6 @@ public class JdbmIndex<K, O> extends Abs
 
 
     /**
-     * TODO I don't think the keyCache is required anymore since the normalizer
-     * will cache values for us.
-     */
-    @SuppressWarnings("unchecked")
-    public K getNormalized( K attrVal ) throws Exception
-    {
-        if ( attrVal instanceof Long )
-        {
-            return attrVal;
-        }
-
-        K normalized = ( K ) keyCache.get( attrVal );
-
-        if ( null == normalized )
-        {
-            if ( attrVal instanceof String )
-            {
-                normalized = ( K ) attributeType.getEquality().getNormalizer().normalize(
( String ) attrVal );
-            }
-            else
-            {
-                normalized = ( K ) attributeType.getEquality().getNormalizer().normalize(
-                    new BinaryValue( ( byte[] ) attrVal ) ).getValue();
-            }
-
-            // Double map it so if we use an already normalized
-            // value we can get back the same normalized value.
-            // and not have to regenerate a second time.
-            keyCache.put( attrVal, normalized );
-            keyCache.put( normalized, normalized );
-        }
-
-        return normalized;
-    }
-
-
-    /**
      * {@inheritDoc}
      */
     public boolean isDupsEnabled()

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=1303043&r1=1303042&r2=1303043&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
Tue Mar 20 17:49:25 2012
@@ -589,7 +589,7 @@ public abstract class AbstractBTreeParti
 
             for ( Value<?> value : objectClass )
             {
-                objectClassIdx.add( value.getString(), id );
+                objectClassIdx.add( (String)value.getNormValue(), id );
             }
 
             if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
@@ -650,7 +650,7 @@ public abstract class AbstractBTreeParti
 
                     for ( Value<?> value : attribute )
                     {
-                        idx.add( value.getValue(), id );
+                        idx.add( value.getNormValue(), id );
                     }
 
                     // Adds only those attributes that are indexed

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java?rev=1303043&r1=1303042&r2=1303043&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Index.java
Tue Mar 20 17:49:25 2012
@@ -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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.xdbm;
 
@@ -113,16 +113,6 @@ public interface Index<K, O, ID>
 
 
     /**
-     * Gets the normalized value for an attribute.
-     *
-     * @param attrVal the user provided value to normalize
-     * @return the normalized value.
-     * @throws Exception if something goes wrong.
-     */
-    K getNormalized( K attrVal ) throws Exception;
-
-
-    /**
      * Gets the total scan count for this index.
      *
      * @return the number of key/value pairs in this index
@@ -132,7 +122,7 @@ public interface Index<K, O, ID>
 
 
     /**
-     * Gets the scan count for the occurrence of a specific attribute value 
+     * Gets the scan count for the occurrence of a specific attribute value
      * within the index.
      *
      * @param attrVal the value of the attribute to get a scan count for
@@ -169,7 +159,7 @@ public interface Index<K, O, ID>
      * Remove all the reference to an entry from the index.
      * <br/>
      * As an entry might be referenced more than once in the forward index,
-     * depending on which index we are dealing with, we need to iterate 
+     * depending on which index we are dealing with, we need to iterate
      * over all the values contained into the reverse index for this entryId.
      * <br/>
      * For instance, considering the ObjectClass index for an entry having
@@ -186,7 +176,7 @@ public interface Index<K, O, ID>
      * </pre>
      * So dropping the entryId means that we must first get all the values from
      * the reverse index (and we will get [top, person, inetOrgPerson]) then to
-     * iterate through all those values to remove entryId from the associated 
+     * iterate through all those values to remove entryId from the associated
      * list of entryIds.
      * 
      * @param entryId The master table entry ID to remove
@@ -196,7 +186,7 @@ public interface Index<K, O, ID>
 
 
     /**
-     * Remove the pair <K,ID> from the index for the given value and id. 
+     * Remove the pair <K,ID> from the index for the given value and id.
      * 
      * @param attrVal The value we want to remove from the index
      * @param id The associated ID
@@ -268,7 +258,7 @@ public interface Index<K, O, ID>
     /**
      * tells whether the Index implementation supports storing duplicate keys
      *
-     * @return true if duplicate keys are allowed false otherwise 
+     * @return true if duplicate keys are allowed false otherwise
      */
     boolean isDupsEnabled();
 }

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java?rev=1303043&r1=1303042&r2=1303043&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/impl/avl/AvlIndex.java
Tue Mar 20 17:49:25 2012
@@ -29,7 +29,6 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.IndexCursor;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.Tuple;
-import org.apache.directory.shared.ldap.model.entry.BinaryValue;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
@@ -87,7 +86,7 @@ public class AvlIndex<K, O> extends Abst
         LdapComparator<K> comp = ( LdapComparator<K> ) mr.getLdapComparator();
 
         /*
-         * The forward key/value map stores attribute values to master table 
+         * The forward key/value map stores attribute values to master table
          * primary keys.  A value for an attribute can occur several times in
          * different entries so the forward map can have more than one value.
          */
@@ -96,7 +95,7 @@ public class AvlIndex<K, O> extends Abst
         /*
          * Now the reverse map stores the primary key into the master table as
          * the key and the values of attributes as the value.  If an attribute
-         * is single valued according to its specification based on a schema 
+         * is single valued according to its specification based on a schema
          * then duplicate keys should not be allowed within the reverse table.
          */
         if ( attributeType.isSingleValued() )
@@ -112,8 +111,8 @@ public class AvlIndex<K, O> extends Abst
 
     public void add( K attrVal, Long id ) throws Exception
     {
-        forward.put( getNormalized( attrVal ), id );
-        reverse.put( id, getNormalized( attrVal ) );
+        forward.put( attrVal, id );
+        reverse.put( id, attrVal );
     }
 
 
@@ -148,7 +147,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public int count( K attrVal ) throws Exception
     {
-        return forward.count( getNormalized( attrVal ) );
+        return forward.count( attrVal );
     }
 
 
@@ -174,8 +173,8 @@ public class AvlIndex<K, O> extends Abst
      */
     public void drop( K attrVal, Long id ) throws Exception
     {
-        forward.remove( getNormalized( attrVal ), id );
-        reverse.remove( id, getNormalized( attrVal ) );
+        forward.remove( attrVal, id );
+        reverse.remove( id, attrVal );
     }
 
 
@@ -184,7 +183,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean forward( K attrVal ) throws Exception
     {
-        return forward.has( getNormalized( attrVal ) );
+        return forward.has( attrVal );
     }
 
 
@@ -193,7 +192,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean forward( K attrVal, Long id ) throws Exception
     {
-        return forward.has( getNormalized( attrVal ), id );
+        return forward.has( attrVal, id );
     }
 
 
@@ -222,7 +221,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean forwardGreaterOrEq( K attrVal ) throws Exception
     {
-        return forward.hasGreaterOrEqual( getNormalized( attrVal ) );
+        return forward.hasGreaterOrEqual( attrVal );
     }
 
 
@@ -231,7 +230,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean forwardGreaterOrEq( K attrVal, Long id ) throws Exception
     {
-        return forward.hasGreaterOrEqual( getNormalized( attrVal ), id );
+        return forward.hasGreaterOrEqual( attrVal, id );
     }
 
 
@@ -240,7 +239,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean forwardLessOrEq( K attrVal ) throws Exception
     {
-        return forward.hasLessOrEqual( getNormalized( attrVal ) );
+        return forward.hasLessOrEqual( attrVal );
     }
 
 
@@ -249,7 +248,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean forwardLessOrEq( K attrVal, Long id ) throws Exception
     {
-        return forward.hasLessOrEqual( getNormalized( attrVal ), id );
+        return forward.hasLessOrEqual( attrVal, id );
     }
 
 
@@ -258,7 +257,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public Long forwardLookup( K attrVal ) throws Exception
     {
-        return forward.get( getNormalized( attrVal ) );
+        return forward.get( attrVal );
     }
 
 
@@ -274,31 +273,9 @@ public class AvlIndex<K, O> extends Abst
     /**
      * {@inheritDoc}
      */
-    @SuppressWarnings("unchecked")
-    public K getNormalized( K attrVal ) throws Exception
-    {
-        if ( attrVal instanceof Long )
-        {
-            return attrVal;
-        }
-
-        if ( attrVal instanceof String )
-        {
-            return ( K ) normalizer.normalize( ( String ) attrVal );
-        }
-        else
-        {
-            return ( K ) normalizer.normalize( new BinaryValue( ( byte[] ) attrVal ) ).getValue();
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     public int greaterThanCount( K attrVal ) throws Exception
     {
-        return forward.greaterThanCount( getNormalized( attrVal ) );
+        return forward.greaterThanCount( attrVal );
     }
 
 
@@ -307,7 +284,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public int lessThanCount( K attrVal ) throws Exception
     {
-        return forward.lessThanCount( getNormalized( attrVal ) );
+        return forward.lessThanCount( attrVal );
     }
 
 
@@ -325,7 +302,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverse( Long id, K attrVal ) throws Exception
     {
-        return reverse.has( id, getNormalized( attrVal ) );
+        return reverse.has( id, attrVal );
     }
 
 
@@ -363,7 +340,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverseGreaterOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasGreaterOrEqual( id, getNormalized( attrVal ) );
+        return reverse.hasGreaterOrEqual( id, attrVal );
     }
 
 
@@ -381,7 +358,7 @@ public class AvlIndex<K, O> extends Abst
      */
     public boolean reverseLessOrEq( Long id, K attrVal ) throws Exception
     {
-        return reverse.hasLessOrEqual( id, getNormalized( attrVal ) );
+        return reverse.hasLessOrEqual( id, attrVal );
     }
 
 

Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/StoreUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/StoreUtils.java?rev=1303043&r1=1303042&r2=1303043&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/StoreUtils.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/StoreUtils.java
Tue Mar 20 17:49:25 2012
@@ -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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.xdbm;
 
@@ -62,108 +62,124 @@ public class StoreUtils
         Dn suffixDn = new Dn( schemaManager, "o=Good Times Co." );
 
         // Entry #1
-        Entry entry = new DefaultEntry( schemaManager, suffixDn );
-        entry.add( "objectClass", "organization" );
-        entry.add( "o", "Good Times Co." );
-        entry.add( "postalCode", "1" );
-        entry.add( "postOfficeBox", "1" );
+        Entry entry = new DefaultEntry( schemaManager, suffixDn,
+            "objectClass: organization",
+            "o: Good Times Co.",
+            "postalCode: 1",
+            "postOfficeBox: 1" );
         injectEntryInStore( store, entry );
 
         // Entry #2
         Dn dn = new Dn( schemaManager, "ou=Sales,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "organizationalUnit" );
-        entry.add( "ou", "Sales" );
-        entry.add( "postalCode", "1" );
-        entry.add( "postOfficeBox", "1" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: organizationalUnit",
+            "ou: Sales",
+            "postalCode: 1",
+            "postOfficeBox: 1" );
         injectEntryInStore( store, entry );
 
         // Entry #3
         dn = new Dn( schemaManager, "ou=Board of Directors,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "organizationalUnit" );
-        entry.add( "ou", "Board of Directors" );
-        entry.add( "postalCode", "1" );
-        entry.add( "postOfficeBox", "1" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: organizationalUnit",
+            "ou: Board of Directors",
+            "postalCode: 1",
+            "postOfficeBox: 1" );
         injectEntryInStore( store, entry );
 
         // Entry #4
         dn = new Dn( schemaManager, "ou=Engineering,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "organizationalUnit" );
-        entry.add( "ou", "Engineering" );
-        entry.add( "postalCode", "2" );
-        entry.add( "postOfficeBox", "2" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: organizationalUnit",
+            "ou: Engineering",
+            "postalCode: 2",
+            "postOfficeBox: 2" );
         injectEntryInStore( store, entry );
 
         // Entry #5
         dn = new Dn( schemaManager, "cn=JOhnny WAlkeR,ou=Sales,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "person", "organizationalPerson" );
-        entry.add( "ou", "Sales" );
-        entry.add( "cn", "JOhnny WAlkeR" );
-        entry.add( "sn", "WAlkeR" );
-        entry.add( "postalCode", "3" );
-        entry.add( "postOfficeBox", "3" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: person",
+            "objectClass: organizationalPerson",
+            "ou: Sales",
+            "cn: JOhnny WAlkeR",
+            "sn: WAlkeR",
+            "postalCode: 3",
+            "postOfficeBox: 3" );
         injectEntryInStore( store, entry );
 
         // Entry #6
         dn = new Dn( schemaManager, "cn=JIM BEAN,ou=Sales,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "person", "organizationalPerson" );
-        entry.add( "ou", "Sales" );
-        entry.add( "cn", "JIM BEAN" );
-        entry.add( "surName", "BEAN" );
-        entry.add( "postalCode", "4" );
-        entry.add( "postOfficeBox", "4" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: person",
+            "objectClass: organizationalPerson",
+            "ou: Sales",
+            "cn: JIM BEAN",
+            "surName: BEAN",
+            "postalCode: 4",
+            "postOfficeBox: 4" );
         injectEntryInStore( store, entry );
 
         // Entry #7
         dn = new Dn( schemaManager, "ou=Apache,ou=Board of Directors,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "organizationalUnit" );
-        entry.add( "ou", "Apache" );
-        entry.add( "postalCode", "5" );
-        entry.add( "postOfficeBox", "5" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: organizationalUnit",
+            "ou: Apache",
+            "postalCode: 5",
+            "postOfficeBox: 5" );
         injectEntryInStore( store, entry );
 
         // Entry #8
         dn = new Dn( schemaManager, "cn=Jack Daniels,ou=Engineering,o=Good Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "person", "organizationalPerson" );
-        entry.add( "ou", "Engineering" );
-        entry.add( "cn", "Jack Daniels" );
-        entry.add( "SN", "Daniels" );
-        entry.add( "postalCode", "6" );
-        entry.add( "postOfficeBox", "6" );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: person",
+            "objectClass: organizationalPerson",
+            "ou: Engineering",
+            "cn: Jack Daniels",
+            "SN: Daniels",
+            "postalCode: 6",
+            "postOfficeBox: 6" );
         injectEntryInStore( store, entry );
 
         // aliases -------------
 
         // Entry #9
         dn = new Dn( schemaManager, "commonName=Jim Bean,ou=Apache,ou=Board of Directors,o=Good
Times Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "alias", "extensibleObject" );
-        entry.add( "ou", "Apache" );
-        entry.add( "commonName", "Jim Bean" );
-        entry.add( "aliasedObjectName", "cn=Jim Bean,ou=Sales,o=Good Times Co." );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: alias",
+            "objectClass: extensibleObject",
+            "ou: Apache",
+            "commonName: Jim Bean",
+            "aliasedObjectName: cn=Jim Bean,ou=Sales,o=Good Times Co." );
         injectEntryInStore( store, entry );
 
         // Entry #10
         dn = new Dn( schemaManager, "commonName=Jim Bean,ou=Board of Directors,o=Good Times
Co." );
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "alias", "extensibleObject" );
-        entry.add( "commonName", "Jim Bean" );
-        entry.add( "aliasedObjectName", "cn=Jim Bean,ou=Sales,o=Good Times Co." );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: alias",
+            "objectClass: extensibleObject",
+            "commonName: Jim Bean",
+            "aliasedObjectName: cn=Jim Bean,ou=Sales,o=Good Times Co." );
         injectEntryInStore( store, entry );
 
         // Entry #11
         dn = new Dn( schemaManager, "2.5.4.3=Johnny Walker,ou=Engineering,o=Good Times Co."
);
-        entry = new DefaultEntry( schemaManager, dn );
-        entry.add( "objectClass", "top", "alias", "extensibleObject" );
-        entry.add( "ou", "Engineering" );
-        entry.add( "2.5.4.3", "Johnny Walker" );
-        entry.add( "aliasedObjectName", "cn=Johnny Walker,ou=Sales,o=Good Times Co." );
+        entry = new DefaultEntry( schemaManager, dn,
+            "objectClass: top",
+            "objectClass: alias",
+            "objectClass: extensibleObject",
+            "ou: Engineering",
+            "2.5.4.3: Johnny Walker",
+            "aliasedObjectName: cn=Johnny Walker,ou=Sales,o=Good Times Co." );
         injectEntryInStore( store, entry );
     }
 

Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java?rev=1303043&r1=1303042&r2=1303043&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
Tue Mar 20 17:49:25 2012
@@ -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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.xdbm.search.impl;
 
@@ -175,7 +175,7 @@ public class NestedFilterTest
         optimizer.annotate( exprNode );
 
         IndexCursor<?, Entry, Long> cursor = cursorBuilder.build( exprNode );
-
+        
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 5, ( long ) cursor.get().getId() );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java?rev=1303043&r1=1303042&r2=1303043&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/FilterParser.java
Tue Mar 20 17:49:25 2012
@@ -25,6 +25,7 @@ import java.text.ParseException;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.model.entry.AttributeUtils;
 import org.apache.directory.shared.ldap.model.entry.BinaryValue;
+import org.apache.directory.shared.ldap.model.entry.StringValue;
 import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
@@ -107,7 +108,7 @@ public class FilterParser
                     pos.start++;
 
                     // Get the assertionValue
-                    node.setValue( parseAssertionValue( filter, pos ) );
+                    node.setValue( parseAssertionValue( schemaManager, attribute, filter,
pos ) );
 
                     return node;
                 }
@@ -122,7 +123,7 @@ public class FilterParser
                         pos.start += 2;
 
                         // Get the assertionValue
-                        node.setValue( parseAssertionValue( filter, pos ) );
+                        node.setValue( parseAssertionValue( schemaManager, attribute, filter,
pos ) );
 
                         return node;
                     }
@@ -169,7 +170,7 @@ public class FilterParser
                     pos.start++;
 
                     // Get the assertionValue
-                    node.setValue( parseAssertionValue( filter, pos ) );
+                    node.setValue( parseAssertionValue( schemaManager, attribute, filter,
pos ) );
 
                     return node;
                 }
@@ -184,7 +185,7 @@ public class FilterParser
                         pos.start += 2;
 
                         // Get the assertionValue
-                        node.setValue( parseAssertionValue( filter, pos ) );
+                        node.setValue( parseAssertionValue( schemaManager, attribute, filter,
pos ) );
 
                         return node;
                     }
@@ -234,7 +235,7 @@ public class FilterParser
      * HEX            = '0'-'9' / 'A'-'F' / 'a'-'f'
      * unicodeSubset     = %x01-27 / %x2B-5B / %x5D-FFFF
      */
-    private static Value<?> parseAssertionValue( byte[] filter, Position pos ) throws
ParseException
+    private static Value<?> parseAssertionValue( SchemaManager schemaManager, String
attribute, byte[] filter, Position pos ) throws ParseException
     {
         byte b = Strings.byteAt( filter, pos.start );
 
@@ -288,11 +289,48 @@ public class FilterParser
             byte[] result = new byte[current];
             System.arraycopy( value, 0, result, 0, current );
 
-            return new BinaryValue( result );
+            if ( schemaManager != null )
+            {
+                AttributeType attributeType = schemaManager.getAttributeType( attribute );
+                
+                if ( attributeType == null )
+                {
+                    return new BinaryValue( result );
+                }
+                
+                if ( attributeType.getSyntax().isHumanReadable() )
+                {
+                    return new StringValue( Strings.utf8ToString( result ) );
+                }
+                else
+                {
+                    return new BinaryValue( result );
+                }
+            }
+            else
+            {
+                return new BinaryValue( result );
+            }
         }
         else
         {
-            return new BinaryValue( ( byte[] ) null );
+            if ( schemaManager != null )
+            {
+                AttributeType attributeType = schemaManager.getAttributeType( attribute );
+                
+                if ( attributeType.getEquality().getSyntax().isHumanReadable() )
+                {
+                    return new StringValue( null );
+                }
+                else
+                {
+                    return new BinaryValue( null );
+                }
+            }
+            else
+            {
+                return new BinaryValue( ( byte[] ) null );
+            }
         }
     }
 
@@ -340,7 +378,7 @@ public class FilterParser
             //
             while ( true )
             {
-                Value<?> assertionValue = parseAssertionValue( filter, pos );
+                Value<?> assertionValue = parseAssertionValue( schemaManager, attribute,
filter, pos );
 
                 // Is there anything else but a ')' after the value ?
                 if ( Strings.isCharASCII( filter, pos.start, ')' ) )
@@ -472,7 +510,7 @@ public class FilterParser
         else
         {
             // A substring or an equality node
-            Value<?> value = parseAssertionValue( filter, pos );
+            Value<?> value = parseAssertionValue( schemaManager, attribute, filter,
pos );
 
             // Is there anything else but a ')' after the value ?
             if ( Strings.isCharASCII( filter, pos.start, ')' ) )
@@ -562,7 +600,7 @@ public class FilterParser
                     // Parse the value and create the node
                     if ( schemaManager == null )
                     {
-                        return new ApproximateNode( attribute, parseAssertionValue( filter,
pos ) );
+                        return new ApproximateNode( attribute, parseAssertionValue( schemaManager,
attribute, filter, pos ) );
                     }
                     else
                     {
@@ -570,7 +608,7 @@ public class FilterParser
 
                         if ( attributeType != null )
                         {
-                            return new ApproximateNode( attributeType, parseAssertionValue(
filter, pos ) );
+                            return new ApproximateNode( attributeType, parseAssertionValue(
schemaManager, attribute, filter, pos ) );
                         }
                         else
                         {
@@ -593,7 +631,7 @@ public class FilterParser
                     // Parse the value and create the node
                     if ( schemaManager == null )
                     {
-                        return new GreaterEqNode( attribute, parseAssertionValue( filter,
pos ) );
+                        return new GreaterEqNode( attribute, parseAssertionValue( schemaManager,
attribute, filter, pos ) );
                     }
                     else
                     {
@@ -601,7 +639,7 @@ public class FilterParser
 
                         if ( attributeType != null )
                         {
-                            return new GreaterEqNode( attributeType, parseAssertionValue(
filter, pos ) );
+                            return new GreaterEqNode( attributeType, parseAssertionValue(
schemaManager, attribute, filter, pos ) );
                         }
                         else
                         {
@@ -624,7 +662,7 @@ public class FilterParser
                     // Parse the value and create the node
                     if ( schemaManager == null )
                     {
-                        return new LessEqNode( attribute, parseAssertionValue( filter, pos
) );
+                        return new LessEqNode( attribute, parseAssertionValue( schemaManager,
attribute, filter, pos ) );
                     }
                     else
                     {
@@ -632,7 +670,7 @@ public class FilterParser
 
                         if ( attributeType != null )
                         {
-                            return new LessEqNode( attributeType, parseAssertionValue( filter,
pos ) );
+                            return new LessEqNode( attributeType, parseAssertionValue( schemaManager,
attribute, filter, pos ) );
                         }
                         else
                         {



Mime
View raw message