Author: elecharny Date: Tue Jul 13 15:59:10 2010 New Revision: 963773 URL: http://svn.apache.org/viewvc?rev=963773&view=rev Log: Created an Abstract SimpleEvaluator class to gather some common informations Added: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SimpleEvaluator.java Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java?rev=963773&r1=963772&r2=963773&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java Tue Jul 13 15:59:10 2010 @@ -26,15 +26,12 @@ import org.apache.directory.server.i18n. import org.apache.directory.server.xdbm.Index; import org.apache.directory.server.xdbm.IndexEntry; import org.apache.directory.server.xdbm.Store; -import org.apache.directory.server.xdbm.search.Evaluator; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.filter.ApproximateNode; import org.apache.directory.shared.ldap.schema.AttributeType; -import org.apache.directory.shared.ldap.schema.LdapComparator; import org.apache.directory.shared.ldap.schema.MatchingRule; -import org.apache.directory.shared.ldap.schema.Normalizer; import org.apache.directory.shared.ldap.schema.SchemaManager; @@ -44,39 +41,13 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -public class ApproximateEvaluator> implements Evaluator, Entry, ID> +public class ApproximateEvaluator> extends SimpleEvaluator { - /** The ExprNode to evaluate */ - private final ApproximateNode node; - - /** The backend */ - private final Store db; - - /** The SchemaManager instance */ - private final SchemaManager schemaManager; - - /** The AttributeType we will use for the evaluation */ - private final AttributeType attributeType; - - /** The associated normalizer */ - private final Normalizer normalizer; - - /** The associated comparator */ - private final LdapComparator ldapComparator; - - /** The index to use if any */ - private final Index idx; - - - @SuppressWarnings("unchecked") public ApproximateEvaluator( ApproximateNode node, Store db, SchemaManager schemaManager ) throws Exception { - this.db = db; - this.node = node; - this.schemaManager = schemaManager; - this.attributeType = node.getAttributeType(); - + super( node, db, schemaManager ); + if ( db.hasIndexOn( attributeType ) ) { idx = ( Index ) db.getIndex( attributeType ); @@ -102,7 +73,7 @@ public class ApproximateEvaluator getExpression() { - return node; + return (ApproximateNode)node; } Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java?rev=963773&r1=963772&r2=963773&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java Tue Jul 13 15:59:10 2010 @@ -26,15 +26,12 @@ import java.util.Iterator; import org.apache.directory.server.xdbm.Index; import org.apache.directory.server.xdbm.IndexEntry; import org.apache.directory.server.xdbm.Store; -import org.apache.directory.server.xdbm.search.Evaluator; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.filter.EqualityNode; import org.apache.directory.shared.ldap.schema.AttributeType; -import org.apache.directory.shared.ldap.schema.LdapComparator; import org.apache.directory.shared.ldap.schema.MatchingRule; -import org.apache.directory.shared.ldap.schema.Normalizer; import org.apache.directory.shared.ldap.schema.SchemaManager; import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator; import org.apache.directory.shared.ldap.schema.comparators.StringComparator; @@ -48,50 +45,26 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -public class EqualityEvaluator> implements Evaluator, Entry, ID> +public class EqualityEvaluator> extends SimpleEvaluator { - /** The ExprNode to evaluate */ - private final EqualityNode node; - - /** The backend */ - private final Store db; - - /** The SchemaManager instance */ - private final SchemaManager schemaManager; - - /** The AttributeType we will use for the evaluation */ - private final AttributeType attributeType; - - /** The associated normalizer */ - private final Normalizer normalizer; - - /** The comparator to use */ - private final LdapComparator comparator; - /** The default byte[] comparator if no comparator has been defined */ private static final Comparator BINARY_COMPARATOR = new ByteArrayComparator( null ); /** The default String comparator if no comparator has been defined */ private static final Comparator STRING_COMPARATOR = new StringComparator( null ); - /** The index to use if any */ - private final Index idx; - @SuppressWarnings("unchecked") public EqualityEvaluator( EqualityNode node, Store db, SchemaManager schemaManager ) throws Exception { - this.db = db; - this.node = node; - this.schemaManager = schemaManager; - this.attributeType = node.getAttributeType(); + super( node, db, schemaManager ); if ( db.hasIndexOn( attributeType ) ) { idx = ( Index ) db.getIndex( attributeType ); normalizer = null; - comparator = null; + ldapComparator = null; } else { @@ -102,12 +75,12 @@ public class EqualityEvaluator getExpression() { - return node; + return (EqualityNode)node; } @@ -210,9 +183,9 @@ public class EqualityEvaluator ) value ).getNormalizedValue(); byte[] nodeValue = ( ( Value ) node.getValue() ).getNormalizedValue(); - if ( comparator != null ) + if ( ldapComparator != null ) { - if ( ( ( ( LdapComparator ) comparator ).compare( serverValue, nodeValue ) == 0 ) ) + if ( ldapComparator.compare( (Object)serverValue, (Object)nodeValue ) == 0 ) { return true; } @@ -240,9 +213,9 @@ public class EqualityEvaluator ) node.getValue() ).getNormalizedValue(); } - if ( comparator != null ) + if ( ldapComparator != null ) { - if ( ( ( LdapComparator ) comparator ).compare( serverValue, nodeValue ) == 0 ) + if ( ldapComparator.compare( serverValue, nodeValue ) == 0 ) { return true; } Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java?rev=963773&r1=963772&r2=963773&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java Tue Jul 13 15:59:10 2010 @@ -20,21 +20,18 @@ package org.apache.directory.server.xdbm.search.impl; -import java.util.Comparator; import java.util.Iterator; import org.apache.directory.server.i18n.I18n; import org.apache.directory.server.xdbm.Index; import org.apache.directory.server.xdbm.IndexEntry; import org.apache.directory.server.xdbm.Store; -import org.apache.directory.server.xdbm.search.Evaluator; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.filter.GreaterEqNode; import org.apache.directory.shared.ldap.schema.AttributeType; import org.apache.directory.shared.ldap.schema.MatchingRule; -import org.apache.directory.shared.ldap.schema.Normalizer; import org.apache.directory.shared.ldap.schema.SchemaManager; @@ -44,42 +41,17 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -public class GreaterEqEvaluator> implements Evaluator, Entry, ID> +public class GreaterEqEvaluator> extends SimpleEvaluator { - /** The ExprNode to evaluate */ - private final GreaterEqNode node; - - /** The backend */ - private final Store db; - - /** The SchemaManager instance */ - private final SchemaManager schemaManager; - - /** The AttributeType we will use for the evaluation */ - private final AttributeType attributeType; - - /** The associated normalizer */ - private final Normalizer normalizer; - - /** The associated comparator */ - private final Comparator comparator; - - /** The index to use if any */ - private final Index idx; - - @SuppressWarnings("unchecked") public GreaterEqEvaluator( GreaterEqNode node, Store db, SchemaManager schemaManager ) throws Exception { - this.db = db; - this.node = node; - this.schemaManager = schemaManager; - this.attributeType = node.getAttributeType(); + super( node, db, schemaManager ); if ( db.hasIndexOn( node.getAttributeType() ) ) { - idx = ( Index ) db.getIndex( attributeType ); + idx = ( Index ) db.getIndex( attributeType ); } else { @@ -105,31 +77,13 @@ public class GreaterEqEvaluator= 0 ) + if ( ldapComparator.compare( value.getNormalizedValue(), node.getValue().getNormalizedValue() ) >= 0 ) { if ( indexEntry != null ) { Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java?rev=963773&r1=963772&r2=963773&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java Tue Jul 13 15:59:10 2010 @@ -110,7 +110,7 @@ public class LessEqCursor 0 ) @@ -154,7 +154,7 @@ public class LessEqCursor 0 ) @@ -185,7 +185,7 @@ public class LessEqCursor candidate = userIdxCursor.get(); - if ( lessEqEvaluator.getLdapComparator().compare( candidate.getValue(), + if ( lessEqEvaluator.getComparator().compare( candidate.getValue(), lessEqEvaluator.getExpression().getValue().get() ) <= 0 ) { return available = true; Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java?rev=963773&r1=963772&r2=963773&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java Tue Jul 13 15:59:10 2010 @@ -26,15 +26,12 @@ import org.apache.directory.server.i18n. import org.apache.directory.server.xdbm.Index; import org.apache.directory.server.xdbm.IndexEntry; import org.apache.directory.server.xdbm.Store; -import org.apache.directory.server.xdbm.search.Evaluator; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.filter.LessEqNode; import org.apache.directory.shared.ldap.schema.AttributeType; -import org.apache.directory.shared.ldap.schema.LdapComparator; import org.apache.directory.shared.ldap.schema.MatchingRule; -import org.apache.directory.shared.ldap.schema.Normalizer; import org.apache.directory.shared.ldap.schema.SchemaManager; @@ -44,38 +41,13 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -public class LessEqEvaluator> implements Evaluator, Entry, ID> +public class LessEqEvaluator> extends SimpleEvaluator { - /** The ExprNode to evaluate */ - private final LessEqNode node; - - /** The backend */ - private final Store db; - - /** The SchemaManager instance */ - private final SchemaManager schemaManager; - - /** The AttributeType we will use for the evaluation */ - private final AttributeType attributeType; - - /** The associated normalizer */ - private final Normalizer normalizer; - - /** The associated comparator */ - private final LdapComparator ldapComparator; - - /** The index to use if any */ - private final Index idx; - - @SuppressWarnings("unchecked") public LessEqEvaluator( LessEqNode node, Store db, SchemaManager schemaManager ) throws Exception { - this.db = db; - this.node = node; - this.schemaManager = schemaManager; - this.attributeType = node.getAttributeType(); + super( node, db, schemaManager ); if ( db.hasIndexOn( attributeType ) ) { @@ -111,25 +83,7 @@ public class LessEqEvaluator getExpression() { - return node; - } - - - public AttributeType getAttributeType() - { - return attributeType; - } - - - public Normalizer getNormalizer() - { - return normalizer; - } - - - public LdapComparator getLdapComparator() - { - return ldapComparator; + return (LessEqNode)node; } Added: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SimpleEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SimpleEvaluator.java?rev=963773&view=auto ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SimpleEvaluator.java (added) +++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SimpleEvaluator.java Tue Jul 13 15:59:10 2010 @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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; + +import org.apache.directory.server.xdbm.Index; +import org.apache.directory.server.xdbm.Store; +import org.apache.directory.server.xdbm.search.Evaluator; +import org.apache.directory.shared.ldap.entry.Entry; +import org.apache.directory.shared.ldap.filter.SimpleNode; +import org.apache.directory.shared.ldap.schema.AttributeType; +import org.apache.directory.shared.ldap.schema.LdapComparator; +import org.apache.directory.shared.ldap.schema.Normalizer; +import org.apache.directory.shared.ldap.schema.SchemaManager; + +/** + * An abstract evaluator to store the common fileds for the Simple node evaluators + * (ApproximateEvaluator, EqualityEvaluator, GreaterEqEvluator and LessEqEvluator) + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public abstract class SimpleEvaluator> implements Evaluator, Entry, ID> +{ + /** The ExprNode to evaluate */ + protected final SimpleNode node; + + /** The backend */ + protected final Store db; + + /** The SchemaManager instance */ + protected final SchemaManager schemaManager; + + /** The AttributeType we will use for the evaluation */ + protected final AttributeType attributeType; + + /** The associated normalizer */ + protected Normalizer normalizer; + + /** The associated comparator */ + protected LdapComparator ldapComparator; + + /** The index to use if any */ + protected Index idx; + + @SuppressWarnings("unchecked") + public SimpleEvaluator( SimpleNode node, Store db, SchemaManager schemaManager ) + throws Exception + { + this.db = db; + this.node = node; + this.schemaManager = schemaManager; + this.attributeType = node.getAttributeType(); + } + + + /** + * @return The AttributeType + */ + public AttributeType getAttributeType() + { + return attributeType; + } + + + /** + * @return The Normalizer associated with the AttributeType + */ + public Normalizer getNormalizer() + { + return normalizer; + } + + + /** + * @return The LdapComparator associated with the AttributeType + */ + public LdapComparator getComparator() + { + return ldapComparator; + } +} Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java?rev=963773&r1=963772&r2=963773&view=diff ============================================================================== --- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java (original) +++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java Tue Jul 13 15:59:10 2010 @@ -583,7 +583,7 @@ public class LessEqTest assertEquals( node, evaluator.getExpression() ); assertEquals( SchemaConstants.POSTALCODE_AT_OID, evaluator.getAttributeType().getOid() ); assertNotNull( evaluator.getNormalizer() ); - assertNotNull( evaluator.getLdapComparator() ); + assertNotNull( evaluator.getComparator() ); indexEntry.setId( 1L ); assertTrue( evaluator.evaluate( indexEntry ) ); @@ -629,7 +629,7 @@ public class LessEqTest assertEquals( node, evaluator.getExpression() ); assertEquals( SchemaConstants.STREET_AT_OID, evaluator.getAttributeType().getOid() ); assertNotNull( evaluator.getNormalizer() ); - assertNotNull( evaluator.getLdapComparator() ); + assertNotNull( evaluator.getComparator() ); DN dn = new DN( "cn=jane doe,o=good times co." ); dn.normalize( schemaManager.getNormalizerMapping() ); @@ -658,7 +658,7 @@ public class LessEqTest assertEquals( node, evaluator.getExpression() ); assertEquals( SchemaConstants.C_POSTALCODE_AT_OID, evaluator.getAttributeType().getOid() ); assertNotNull( evaluator.getNormalizer() ); - assertNotNull( evaluator.getLdapComparator() ); + assertNotNull( evaluator.getComparator() ); indexEntry.setId( 1L ); assertFalse( evaluator.evaluate( indexEntry ) ); @@ -676,7 +676,7 @@ public class LessEqTest assertEquals( node, evaluator.getExpression() ); assertEquals( SchemaConstants.POSTOFFICEBOX_AT_OID, evaluator.getAttributeType().getOid() ); assertNotNull( evaluator.getNormalizer() ); - assertNotNull( evaluator.getLdapComparator() ); + assertNotNull( evaluator.getComparator() ); indexEntry.setId( 1L ); assertTrue( evaluator.evaluate( indexEntry ) );