You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/05/13 07:52:40 UTC
svn commit: r655742 - in /directory/apacheds/branches/bigbang:
btree-base/src/main/java/org/apache/directory/server/xdbm/search/
xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/
xdbm-search/src/test/java/org/apache/directory/serv...
Author: akarasulu
Date: Mon May 12 22:52:40 2008
New Revision: 655742
URL: http://svn.apache.org/viewvc?rev=655742&view=rev
Log:
adding overloads for Evaluator interface evaluate method
Added:
directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java (contents, props changed)
- copied, changed from r655574, directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java
Removed:
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java
Modified:
directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EvaluatorBuilder.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java
directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
Copied: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java (from r655574, directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java?p2=directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java&p1=directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java&r1=655574&r2=655742&rev=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java (original)
+++ directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java Mon May 12 22:52:40 2008
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.directory.server.xdbm.search.impl;
+package org.apache.directory.server.xdbm.search;
import org.apache.directory.shared.ldap.filter.ExprNode;
@@ -26,6 +26,25 @@
/**
* Evaluates candidate entries to see if they match a filter expression.
+ *
+ * Evaluators contain various overloads to the evaluate method. Often a
+ * developer working in this region of the code may wonder when to use one
+ * override verses another. The overload taking an IndexEntry argument is
+ * specifically suited for use when there is the possibility of multiple entry
+ * lookups from the master table. If the same candidate in the form of an
+ * IndexEntry is evaluated more then this overload is more efficient since it
+ * stores the looked up entry in the IndexEntry preventing multiple lookups.
+ *
+ * If the index entry is already populated with an entry object, and some
+ * evaluation is required then it is preferrable to use the overload that
+ * takes a Long id instead. Likewise if it is known in advance that the
+ * expression is a leaf node built on an indexed attribute then the overload
+ * with the Long id argument is also preferrable unless an IndexEntry already
+ * exists in which case it makes no difference.
+ *
+ * The overload taking the ServerEntry itself is a last resort option and ok
+ * to use when it is known that no index exists for the attributes of
+ * Evaluators based on leaf expressions.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
@@ -34,15 +53,42 @@
{
/**
* Evaluates a candidate to determine if a filter expression selects it.
+ * If an IndexEntry does has a null reference to the entry object, this
+ * Evaluator may set it if it has to access the full entry within the
+ * master table of the store. Subsequent evaluations on the IndexEntry
+ * then need not access the store to retreive the entry if they need to
+ * access it's attributes.
*
* @param entry the index record of the entry to evaluate
* @return true if filter selects the candidate false otherwise
- * @throws Exception if there are database faults during evaluation
+ * @throws Exception if there are faults during evaluation
*/
boolean evaluate( IndexEntry<?,E> entry ) throws Exception;
/**
+ * Evaluates whether or not a candidate, specified by an id, satisfies the
+ * expression associated with this Evaluator .
+ *
+ * @param id the identifier for the candidate entry
+ * @return true if filter selects the candidate false otherwise
+ * @throws Exception if there are faults during evaluation
+ */
+ boolean evaluate( Long id ) throws Exception;
+
+
+ /**
+ * Evaluates whether or not a candidate, satisfies the expression
+ * associated with this Evaluator .
+ *
+ * @param entry the candidate entry
+ * @return true if filter selects the candidate false otherwise
+ * @throws Exception if there are faults during evaluation
+ */
+ boolean evaluate( E entry ) throws Exception;
+
+
+ /**
* Gets the expression used by this expression Evaluator.
*
* @return the AST for the expression
Propchange: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/Evaluator.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May 12 22:52:40 2008
@@ -0,0 +1,4 @@
+Rev
+Revision
+Date
+Id
Modified: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java (original)
+++ directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java Mon May 12 22:52:40 2008
@@ -26,6 +26,7 @@
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.entry.ServerEntry;
import javax.naming.directory.SearchControls;
@@ -84,19 +85,18 @@
* @return enumeration over SearchResults
* @throws Exception if the search fails
*/
- Cursor<IndexEntry<?,E>> search( LdapDN base,
- AliasDerefMode aliasDerefMode,
- ExprNode filter,
- SearchControls searchCtls ) throws Exception;
+ Cursor<IndexEntry<?,E>> cursor( LdapDN base,
+ AliasDerefMode aliasDerefMode,
+ ExprNode filter,
+ SearchControls searchCtls ) throws Exception;
/**
- * Evaluates a filter on an entry with a id.
+ * Builds an Evaluator for a filter expression.
*
* @param filter the filter root AST node
- * @param id the id of the entry to test
* @return true if the filter passes the entry, false otherwise
* @throws Exception if something goes wrong while accessing the db
*/
- boolean evaluate( ExprNode filter, Long id ) throws Exception;
+ Evaluator<? extends ExprNode, ServerEntry> evaluator( ExprNode filter ) throws Exception;
}
\ No newline at end of file
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java Mon May 12 22:52:40 2008
@@ -21,6 +21,7 @@
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.core.cursor.AbstractCursor;
import org.apache.directory.server.core.cursor.Cursor;
import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java Mon May 12 22:52:40 2008
@@ -23,6 +23,7 @@
import org.apache.directory.shared.ldap.filter.AndNode;
import org.apache.directory.shared.ldap.filter.ExprNode;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.core.entry.ServerEntry;
import java.util.List;
@@ -99,6 +100,34 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ for ( Evaluator<?,ServerEntry> evaluator : evaluators )
+ {
+ if ( ! evaluator.evaluate( id ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
+ for ( Evaluator<?,ServerEntry> evaluator : evaluators )
+ {
+ if ( ! evaluator.evaluate( entry ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
public boolean evaluate( IndexEntry<?, ServerEntry> indexEntry ) throws Exception
{
for ( Evaluator<?,ServerEntry> evaluator : evaluators )
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateEvaluator.java Mon May 12 22:52:40 2008
@@ -28,6 +28,7 @@
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
@@ -94,22 +95,8 @@
}
- public boolean evaluate( IndexEntry<?,ServerEntry> indexEntry ) throws Exception
+ public boolean evaluate( ServerEntry entry ) throws Exception
{
- if ( idx != null )
- {
- return idx.forward( ( Number ) indexEntry.getValue(), indexEntry.getId() );
- }
-
- ServerEntry entry = indexEntry.getObject();
-
- // resuscitate the entry if it has not been and set entry in IndexEntry
- if ( null == entry )
- {
- entry = db.lookup( indexEntry.getId() );
- indexEntry.setObject( entry );
- }
-
// get the attribute
ServerAttribute attr = ( ServerAttribute ) entry.get( type );
@@ -148,6 +135,37 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ if ( idx != null )
+ {
+ return idx.reverse( id );
+ }
+
+ return evaluate( db.lookup( id ) );
+ }
+
+
+ public boolean evaluate( IndexEntry<?,ServerEntry> indexEntry ) throws Exception
+ {
+ if ( idx != null )
+ {
+ return idx.forward( ( Number ) indexEntry.getValue(), indexEntry.getId() );
+ }
+
+ ServerEntry entry = indexEntry.getObject();
+
+ // resuscitate the entry if it has not been and set entry in IndexEntry
+ if ( null == entry )
+ {
+ entry = db.lookup( indexEntry.getId() );
+ indexEntry.setObject( entry );
+ }
+
+ return evaluate( entry );
+ }
+
+
// TODO - determine if comaparator and index entry should have the Value
// wrapper or the raw normalized value
private boolean evaluate( ServerAttribute attribute ) throws Exception
@@ -163,6 +181,7 @@
{
value.normalize( normalizer );
+ //noinspection unchecked
if ( comparator.compare( value.getNormalizedValue(), node.getValue().getNormalizedValue() ) == 0 )
{
return true;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java Mon May 12 22:52:40 2008
@@ -27,6 +27,7 @@
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.server.core.cursor.Cursor;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.shared.ldap.NotImplementedException;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java Mon May 12 22:52:40 2008
@@ -31,6 +31,7 @@
import org.apache.directory.server.xdbm.*;
import org.apache.directory.server.xdbm.search.Optimizer;
import org.apache.directory.server.xdbm.search.SearchEngine;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.core.cursor.Cursor;
import org.apache.directory.server.core.entry.ServerEntry;
@@ -47,33 +48,33 @@
/** the Optimizer used by this DefaultSearchEngine */
private final Optimizer optimizer;
/** the Database this DefaultSearchEngine operates on */
- private Store<ServerEntry> db;
- /** Evaluator flyweight used for filter expression assertions */
- private Evaluator<? extends ExprNode, ServerEntry> evaluator;
- /** CursorBuilder flyweight that creates enumerations on filter expressions */
- private CursorBuilder cursorBuilder;
+ private final Store<ServerEntry> db;
+ /** creates Cursors over entries satisfying filter expressions */
+ private final CursorBuilder cursorBuilder;
+ /** creates evaluators which check to see if candidates satisfy a filter expression */
+ private final EvaluatorBuilder evaluatorBuilder;
// ------------------------------------------------------------------------
// C O N S T R U C T O R S
// ------------------------------------------------------------------------
+
/**
* Creates a DefaultSearchEngine for searching a Database without setting
* up the database.
* @param db the btree based partition
- * @param cursorBuilder an expression cursorBuilder
- * @param evaluator an expression evaluator
+ * @param cursorBuilder an expression cursor builder
+ * @param evaluatorBuilder an expression evaluator builder
* @param optimizer an optimizer to use during search
*/
public DefaultSearchEngine( Store<ServerEntry> db,
- Evaluator<? extends ExprNode, ServerEntry> evaluator,
- CursorBuilder cursorBuilder, Optimizer optimizer )
+ CursorBuilder cursorBuilder, EvaluatorBuilder evaluatorBuilder, Optimizer optimizer )
{
this.db = db;
- this.evaluator = evaluator;
- this.cursorBuilder = cursorBuilder;
this.optimizer = optimizer;
+ this.cursorBuilder = cursorBuilder;
+ this.evaluatorBuilder = evaluatorBuilder;
}
@@ -88,8 +89,11 @@
}
- public Cursor<IndexEntry<?,ServerEntry>> search( LdapDN base, AliasDerefMode aliasDerefMode, ExprNode filter, SearchControls searchCtls )
- throws Exception
+ /**
+ * @see SearchEngine#cursor(LdapDN, AliasDerefMode, ExprNode, SearchControls)
+ */
+ public Cursor<IndexEntry<?,ServerEntry>> cursor( LdapDN base, AliasDerefMode aliasDerefMode, ExprNode filter,
+ SearchControls searchCtls ) throws Exception
{
LdapDN effectiveBase;
Long baseId = db.getEntryId( base.toString() );
@@ -132,12 +136,11 @@
/**
- * @see SearchEngine#evaluate(ExprNode, Long)
+ * @see SearchEngine#evaluator(ExprNode)
*/
- public boolean evaluate( ExprNode filter, Long id ) throws Exception
+ public Evaluator<? extends ExprNode, ServerEntry> evaluator( ExprNode filter )
+ throws Exception
{
- IndexEntry<?,ServerEntry> rec = new ForwardIndexEntry<Object,ServerEntry>();
- rec.setId( id );
- return evaluator.evaluate( rec );
+ return evaluatorBuilder.build( filter );
}
}
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java Mon May 12 22:52:40 2008
@@ -28,6 +28,7 @@
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
@@ -110,6 +111,12 @@
indexEntry.setObject( entry );
}
+ return evaluate( entry );
+ }
+
+
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
// get the attribute
ServerAttribute attr = ( ServerAttribute ) entry.get( type );
@@ -148,6 +155,17 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ if ( idx != null )
+ {
+ return idx.reverse( id );
+ }
+
+ return evaluate ( db.lookup( id ) );
+ }
+
+
// TODO - determine if comaparator and index entry should have the Value
// wrapper or the raw normalized value
private boolean evaluate( ServerAttribute attribute ) throws Exception
@@ -162,6 +180,7 @@
{
value.normalize( normalizer );
+ //noinspection unchecked
if ( comparator.compare( value.getNormalizedValue(), node.getValue().getNormalizedValue() ) == 0 )
{
return true;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EvaluatorBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EvaluatorBuilder.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EvaluatorBuilder.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EvaluatorBuilder.java Mon May 12 22:52:40 2008
@@ -20,11 +20,11 @@
package org.apache.directory.server.xdbm.search.impl;
-import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.shared.ldap.filter.*;
import org.apache.directory.shared.ldap.NotImplementedException;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java Mon May 12 22:52:40 2008
@@ -28,6 +28,7 @@
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
@@ -136,10 +137,19 @@
indexEntry.setObject( entry );
}
+ /*
+ * The code below could have been replaced by a call to
+ * evaluate( ServerEntry ) but it was not because we wanted to make
+ * sure the call to evaluate with the attribute was made using a
+ * non-null IndexEntry parameter. This is to make sure the call to
+ * evaluate with the attribute will set the value on the IndexEntry.
+ */
+
// get the attribute
ServerAttribute attr = ( ServerAttribute ) entry.get( type );
// if the attribute exists and has a greater than or equal value return true
+ //noinspection unchecked
if ( attr != null && evaluate( ( IndexEntry<Object,ServerEntry> ) indexEntry, attr ) )
{
return true;
@@ -162,6 +172,7 @@
attr = ( ServerAttribute ) entry.get( descendant );
+ //noinspection unchecked
if ( attr != null && evaluate( ( IndexEntry<Object, ServerEntry> ) indexEntry, attr ) )
{
return true;
@@ -174,6 +185,57 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ if ( idx != null )
+ {
+ return idx.reverseGreaterOrEq( id, node.getValue().get() );
+ }
+
+ return evaluate ( db.lookup( id ) );
+ }
+
+
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
+ // get the attribute
+ ServerAttribute attr = ( ServerAttribute ) entry.get( type );
+
+ // if the attribute exists and has a greater than or equal value return true
+ if ( attr != null && evaluate( null, attr ) )
+ {
+ return true;
+ }
+
+ // If we do not have the attribute, loop through the sub classes of
+ // the attributeType. Perhaps the entry has an attribute value of a
+ // subtype (descendant) that will produce a match
+ if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() ) )
+ {
+ // TODO check to see if descendant handling is necessary for the
+ // index so we can match properly even when for example a name
+ // attribute is used instead of more specific commonName
+ Iterator<AttributeType> descendants =
+ registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+ while ( descendants.hasNext() )
+ {
+ AttributeType descendant = descendants.next();
+
+ attr = ( ServerAttribute ) entry.get( descendant );
+
+ if ( attr != null && evaluate( null, attr ) )
+ {
+ return true;
+ }
+ }
+ }
+
+ // we fell through so a match was not found - assertion was false.
+ return false;
+ }
+
+
// TODO - determine if comaparator and index entry should have the Value
// wrapper or the raw normalized value
private boolean evaluate( IndexEntry<Object,ServerEntry> indexEntry, ServerAttribute attribute ) throws Exception
@@ -188,9 +250,13 @@
{
value.normalize( normalizer );
+ //noinspection unchecked
if ( comparator.compare( value.getNormalizedValue(), node.getValue().getNormalizedValue() ) >= 0 )
{
- indexEntry.setValue( value.getNormalizedValue() );
+ if ( indexEntry != null )
+ {
+ indexEntry.setValue( value.getNormalizedValue() );
+ }
return true;
}
}
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java Mon May 12 22:52:40 2008
@@ -28,6 +28,7 @@
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
@@ -120,6 +121,17 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ if ( idx != null )
+ {
+ return idx.reverseLessOrEq( id, node.getValue().get() );
+ }
+
+ return evaluate( db.lookup( id ) );
+ }
+
+
public boolean evaluate( IndexEntry<?,ServerEntry> indexEntry ) throws Exception
{
if ( idx != null )
@@ -140,6 +152,7 @@
ServerAttribute attr = ( ServerAttribute ) entry.get( type );
// if the attribute does not exist just return false
+ //noinspection unchecked
if ( attr != null && evaluate( ( IndexEntry<Object,ServerEntry> ) indexEntry, attr ) )
{
return true;
@@ -162,6 +175,7 @@
attr = ( ServerAttribute ) entry.get( descendant );
+ //noinspection unchecked
if ( attr != null && evaluate( ( IndexEntry<Object,ServerEntry> ) indexEntry, attr ) )
{
return true;
@@ -174,6 +188,46 @@
}
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
+ // get the attribute
+ ServerAttribute attr = ( ServerAttribute ) entry.get( type );
+
+ // if the attribute does not exist just return false
+ if ( attr != null && evaluate( null, attr ) )
+ {
+ return true;
+ }
+
+ // If we do not have the attribute, loop through the sub classes of
+ // the attributeType. Perhaps the entry has an attribute value of a
+ // subtype (descendant) that will produce a match
+ if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() ) )
+ {
+ // TODO check to see if descendant handling is necessary for the
+ // index so we can match properly even when for example a name
+ // attribute is used instead of more specific commonName
+ Iterator<AttributeType> descendants =
+ registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+ while ( descendants.hasNext() )
+ {
+ AttributeType descendant = descendants.next();
+
+ attr = ( ServerAttribute ) entry.get( descendant );
+
+ if ( attr != null && evaluate( null, attr ) )
+ {
+ return true;
+ }
+ }
+ }
+
+ // we fell through so a match was not found - assertion was false.
+ return false;
+ }
+
+
// TODO - determine if comaparator and index entry should have the Value
// wrapper or the raw normalized value
private boolean evaluate( IndexEntry<Object,ServerEntry> indexEntry, ServerAttribute attribute ) throws Exception
@@ -188,9 +242,13 @@
{
value.normalize( normalizer );
+ //noinspection unchecked
if ( comparator.compare( value.getNormalizedValue(), node.getValue().getNormalizedValue() ) <= 0 )
{
- indexEntry.setValue( value.getNormalizedValue() );
+ if ( indexEntry != null )
+ {
+ indexEntry.setValue( value.getNormalizedValue() );
+ }
return true;
}
}
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java Mon May 12 22:52:40 2008
@@ -22,6 +22,7 @@
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.server.core.cursor.AbstractCursor;
import org.apache.directory.server.core.cursor.Cursor;
import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotEvaluator.java Mon May 12 22:52:40 2008
@@ -23,6 +23,7 @@
import org.apache.directory.shared.ldap.filter.NotNode;
import org.apache.directory.shared.ldap.filter.ExprNode;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.core.entry.ServerEntry;
@@ -45,6 +46,18 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ return ! childEvaluator.evaluate( id );
+ }
+
+
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
+ return ! childEvaluator.evaluate( entry );
+ }
+
+
public boolean evaluate( IndexEntry<?, ServerEntry> indexEntry ) throws Exception
{
return ! childEvaluator.evaluate( indexEntry );
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java Mon May 12 22:52:40 2008
@@ -25,6 +25,7 @@
import org.apache.directory.shared.ldap.filter.ScopeNode;
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.search.Evaluator;
/**
@@ -78,7 +79,78 @@
* @param candidate the candidate to assert
* @return true if the candidate is within one level scope
* @throws Exception if db lookups fail
- * @see Evaluator#evaluate(IndexEntry)
+ * @see org.apache.directory.server.xdbm.search.Evaluator#evaluate(IndexEntry)
+ */
+ public boolean evaluate( Long candidate ) throws Exception
+ {
+ boolean isChild = db.getOneLevelIndex().forward( baseId, candidate );
+
+ /*
+ * The candidate id could be any entry in the db. If search
+ * dereferencing is not enabled then we return the results of the child
+ * test.
+ */
+ if ( ! dereferencing )
+ {
+ return isChild;
+ }
+
+ /*
+ * From here down alias dereferencing is enabled. We determine if the
+ * candidate id is an alias, if so we reject it since aliases should
+ * not be returned.
+ */
+ if ( null != db.getAliasIndex().reverseLookup( candidate ) )
+ {
+ return false;
+ }
+
+ /*
+ * The candidate is NOT an alias at this point. So if it is a child we
+ * just return true since it is in normal one level scope.
+ */
+ if ( isChild )
+ {
+ return true;
+ }
+
+ /*
+ * At this point the candidate is not a child and it is not an alias.
+ * We need to check if the candidate is in extended one level scope by
+ * performing a lookup on the one level alias index. This index stores
+ * a tuple mapping the baseId to the id of objects brought into the
+ * one level scope of the base by an alias: ( baseId, aliasedObjId )
+ * If the candidate id is an object brought into one level scope then
+ * the lookup returns true accepting the candidate. Otherwise the
+ * candidate is rejected with a false return because it is not in scope.
+ */
+ return db.getOneAliasIndex().forward( baseId, candidate );
+ }
+
+
+ /**
+ * Asserts whether or not a candidate has one level scope while taking
+ * alias dereferencing into account.
+ *
+ * TODO - terribly inefficient - would benefit from exposing the id of an
+ * entry within the ServerEntry
+ *
+ * @see Evaluator#evaluate(Object)
+ */
+ public boolean evaluate( E candidate ) throws Exception
+ {
+ throw new UnsupportedOperationException( "This is too inefficient without getId() on ServerEntry" );
+ }
+
+
+ /**
+ * Asserts whether or not a candidate has one level scope while taking
+ * alias dereferencing into account.
+ *
+ * @param candidate the candidate to assert
+ * @return true if the candidate is within one level scope
+ * @throws Exception if db lookups fail
+ * @see org.apache.directory.server.xdbm.search.Evaluator#evaluate(IndexEntry)
*/
public boolean evaluate( IndexEntry<?,E> candidate ) throws Exception
{
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java Mon May 12 22:52:40 2008
@@ -25,6 +25,7 @@
import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.shared.ldap.filter.ExprNode;
import java.util.*;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrEvaluator.java Mon May 12 22:52:40 2008
@@ -23,6 +23,7 @@
import org.apache.directory.shared.ldap.filter.OrNode;
import org.apache.directory.shared.ldap.filter.ExprNode;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.core.entry.ServerEntry;
import java.util.List;
@@ -113,6 +114,34 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+ for ( Evaluator<?,ServerEntry> evaluator : evaluators )
+ {
+ if ( evaluator.evaluate( id ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
+ for ( Evaluator<?,ServerEntry> evaluator : evaluators )
+ {
+ if ( evaluator.evaluate( entry ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
public OrNode getExpression()
{
return node;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java Mon May 12 22:52:40 2008
@@ -25,6 +25,7 @@
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
@@ -97,6 +98,27 @@
indexEntry.setObject( entry );
}
+ return evaluate( entry );
+ }
+
+
+ // TODO - determine if comaparator and index entry should have the Value
+ // wrapper or the raw normalized value
+ public boolean evaluate( Long id ) throws Exception
+ {
+ if ( idx != null )
+ {
+ return idx.forward( type.getOid(), id );
+ }
+
+ return evaluate( db.lookup( id ) );
+ }
+
+
+ // TODO - determine if comaparator and index entry should have the Value
+ // wrapper or the raw normalized value
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
// get the attribute
ServerAttribute attr = ( ServerAttribute ) entry.get( type );
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java Mon May 12 22:52:40 2008
@@ -27,6 +27,7 @@
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.server.core.cursor.Cursor;
import org.apache.directory.server.core.entry.ServerEntry;
import org.apache.directory.server.core.entry.ServerAttribute;
@@ -128,6 +129,36 @@
}
+ public boolean evaluate( Long id ) throws Exception
+ {
+
+ if ( idx == null )
+ {
+ //noinspection unchecked
+ return evaluateWithoutIndex( id );
+ }
+ else
+ {
+ return evaluateWithIndex( id );
+ }
+ }
+
+
+ public boolean evaluate( ServerEntry entry ) throws Exception
+ {
+
+ if ( idx == null )
+ {
+ //noinspection unchecked
+ return evaluateWithoutIndex( entry );
+ }
+ else
+ {
+ return evaluateWithIndex( entry );
+ }
+ }
+
+
public Pattern getPattern()
{
return regex;
@@ -168,6 +199,127 @@
}
+ @SuppressWarnings( { "UnusedDeclaration" } )
+ private boolean evaluateWithIndex( ServerEntry entry ) throws Exception
+ {
+ throw new UnsupportedOperationException( "This is too inefficient without getId() on ServerEntry" );
+ }
+
+
+ private boolean evaluateWithIndex( Long id ) throws Exception
+ {
+ /*
+ * Note that this is using the reverse half of the index giving a
+ * considerable performance improvement on this kind of operation.
+ * Otherwise we would have to scan the entire index if there were
+ * no reverse lookups.
+ */
+ Cursor<IndexEntry<String,ServerEntry>> entries = idx.reverseCursor( id );
+
+ // cycle through the attribute values testing for a match
+ while ( entries.next() )
+ {
+ IndexEntry rec = entries.get();
+
+ // once match is found cleanup and return true
+ if ( regex.matcher( ( String ) rec.getValue() ).matches() )
+ {
+ entries.close();
+ return true;
+ }
+ }
+
+ // we fell through so a match was not found - assertion was false.
+ return false;
+ }
+
+
+ // TODO - determine if comaparator and index entry should have the Value
+ // wrapper or the raw normalized value
+ private boolean evaluateWithoutIndex( Long id ) throws Exception
+ {
+ return evaluateWithoutIndex ( db.lookup( id ) );
+ }
+
+
+ // TODO - determine if comaparator and index entry should have the Value
+ // wrapper or the raw normalized value
+ private boolean evaluateWithoutIndex( ServerEntry entry ) throws Exception
+ {
+ // get the attribute
+ ServerAttribute attr = ( ServerAttribute ) entry.get( type );
+
+ // if the attribute exists and the pattern matches return true
+ if ( attr != null )
+ {
+ /*
+ * Cycle through the attribute values testing normalized version
+ * obtained from using the substring matching rule's normalizer.
+ * The test uses the comparator obtained from the appropriate
+ * substring matching rule.
+ */
+ for ( Value value : attr )
+ {
+ value.normalize( normalizer );
+ String strValue = ( String ) value.getNormalizedValue();
+
+ // Once match is found cleanup and return true
+ if ( regex.matcher( strValue ).matches() )
+ {
+ return true;
+ }
+ }
+
+ // Fall through as we didn't find any matching value for this attribute.
+ // We will have to check in the potential descendant, if any.
+ }
+
+ // If we do not have the attribute, loop through the descendant
+ // May be the node Attribute has descendant ?
+ if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() ) )
+ {
+ // TODO check to see if descendant handling is necessary for the
+ // index so we can match properly even when for example a name
+ // attribute is used instead of more specific commonName
+ Iterator<AttributeType> descendants =
+ registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+ while ( descendants.hasNext() )
+ {
+ AttributeType descendant = descendants.next();
+
+ attr = ( ServerAttribute ) entry.get( descendant );
+
+ if ( null != attr )
+ {
+
+
+ /*
+ * Cycle through the attribute values testing normalized version
+ * obtained from using the substring matching rule's normalizer.
+ * The test uses the comparator obtained from the appropriate
+ * substring matching rule.
+ */
+ for ( Value value : attr )
+ {
+ value.normalize( normalizer );
+ String strValue = ( String ) value.getNormalizedValue();
+
+ // Once match is found cleanup and return true
+ if ( regex.matcher( strValue ).matches() )
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ // we fell through so a match was not found - assertion was false.
+ return false;
+ }
+
+
// TODO - determine if comaparator and index entry should have the Value
// wrapper or the raw normalized value
private boolean evaluateWithoutIndex( IndexEntry<String,ServerEntry> indexEntry ) throws Exception
@@ -181,6 +333,12 @@
indexEntry.setObject( entry );
}
+ /*
+ * Don't make a call here to evaluateWithoutIndex( ServerEntry ) for
+ * code reuse since we do want to set the value on the indexEntry on
+ * matches.
+ */
+
// get the attribute
ServerAttribute attr = ( ServerAttribute ) entry.get( type );
@@ -217,7 +375,7 @@
{
// TODO check to see if descendant handling is necessary for the
// index so we can match properly even when for example a name
- // attribute is used instead of more specific commonName
+ // attribute is used instead of more specific commonName
Iterator<AttributeType> descendants =
registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java Mon May 12 22:52:40 2008
@@ -23,6 +23,7 @@
import org.apache.directory.shared.ldap.filter.ScopeNode;
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.search.Evaluator;
import javax.naming.directory.SearchControls;
@@ -132,6 +133,82 @@
}
+ /**
+ * Asserts whether or not a candidate has one level scope while taking
+ * alias dereferencing into account.
+ *
+ * @param id the id of the entry tested to see if it is in subtree scope
+ * @return true if the candidate is within one level scope whether or not
+ * alias dereferencing is enabled.
+ * @throws Exception if the index lookups fail.
+ * @see Evaluator#evaluate(org.apache.directory.server.xdbm.IndexEntry)
+ */
+ public boolean evaluate( Long id ) throws Exception
+ {
+ boolean isDescendant = db.getSubLevelIndex().forward( baseId, id );
+
+ /*
+ * The candidate id could be any entry in the db. If search
+ * dereferencing is not enabled then we return the results of the
+ * descendant test.
+ */
+ if ( ! isDereferencing() )
+ {
+ return isDescendant;
+ }
+
+ /*
+ * From here down alias dereferencing is enabled. We determine if the
+ * candidate id is an alias, if so we reject it since aliases should
+ * not be returned.
+ */
+ if ( null != db.getAliasIndex().reverseLookup( id ) )
+ {
+ return false;
+ }
+
+ /*
+ * The candidate is NOT an alias at this point. So if it is a
+ * descendant we just return true since it is in normal subtree scope.
+ */
+ if ( isDescendant )
+ {
+ return true;
+ }
+
+ /*
+ * At this point the candidate is not a descendant and it is not an
+ * alias. We need to check if the candidate is in extended subtree
+ * scope by performing a lookup on the subtree alias index. This index
+ * stores a tuple mapping the baseId to the ids of objects brought
+ * into subtree scope of the base by an alias:
+ *
+ * ( baseId, aliasedObjId )
+ *
+ * If the candidate id is an object brought into subtree scope then
+ * the lookup returns true accepting the candidate. Otherwise the
+ * candidate is rejected with a false return because it is not in scope.
+ */
+ return db.getSubAliasIndex().forward( baseId, id );
+ }
+
+
+ /**
+ * Asserts whether or not a candidate has one level scope while taking
+ * alias dereferencing into account.
+ *
+ * @param candidate the entry tested to see if it is in subtree scope
+ * @return true if the candidate is within one level scope whether or not
+ * alias dereferencing is enabled.
+ * @throws Exception if the index lookups fail.
+ * @see Evaluator#evaluate(org.apache.directory.server.xdbm.IndexEntry)
+ */
+ public boolean evaluate( E candidate ) throws Exception
+ {
+ throw new UnsupportedOperationException( "This is too inefficient without getId() on ServerEntry" );
+ }
+
+
public ScopeNode getExpression()
{
return node;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java Mon May 12 22:52:40 2008
@@ -50,6 +50,7 @@
import org.apache.directory.server.xdbm.ForwardIndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.search.Evaluator;
import org.apache.directory.server.xdbm.tools.StoreUtils;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.filter.AndNode;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java Mon May 12 22:52:40 2008
@@ -48,6 +48,7 @@
import org.apache.directory.server.xdbm.ForwardIndexEntry;
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.server.xdbm.tools.StoreUtils;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.filter.ExprNode;
Modified: directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java?rev=655742&r1=655741&r2=655742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java (original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java Mon May 12 22:52:40 2008
@@ -49,6 +49,7 @@
import org.apache.directory.server.xdbm.ForwardIndexEntry;
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.server.xdbm.tools.StoreUtils;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.filter.ExprNode;