You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/08/19 14:18:16 UTC
svn commit: r1159607 - in
/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm:
./ search/impl/
Author: elecharny
Date: Fri Aug 19 12:18:15 2011
New Revision: 1159607
URL: http://svn.apache.org/viewvc?rev=1159607&view=rev
Log:
o Added some missing Javadoc
o Extracted a inner method and made it an external helper class to avoid code duplication
o Some minor refactoring
Added:
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ScanCountComparator.java
Modified:
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
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/EqualityCursor.java
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java Fri Aug 19 12:18:15 2011
@@ -102,7 +102,7 @@ public class ReverseIndexEntry<V, ID> ex
/**
* {@inheritDoc}
*/
- public Tuple<ID, V> getTuple()
+ public Tuple<?, ?> getTuple()
{
return tuple;
}
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java Fri Aug 19 12:18:15 2011
@@ -35,7 +35,10 @@ import org.apache.directory.shared.ldap.
*/
public class AllEntriesCursor<ID extends Comparable<ID>> extends AbstractIndexCursor<ID, Entry, ID>
{
+ /** The index entry we use to return entries one by one. */
private IndexEntry<ID, ID> indexEntry = new ForwardIndexEntry<ID, ID>();
+
+ /** The cursor on the EntryUUID index */
private final IndexCursor<String, Entry, ID> wrapped;
@@ -48,6 +51,11 @@ public class AllEntriesCursor<ID extends
}
+ /**
+ * Creates a new instance of AllEntriesCursor
+ * @param db
+ * @throws Exception
+ */
public AllEntriesCursor( Store<Entry, ID> db ) throws Exception
{
// Get a reverse cursor because we want to sort by ID
@@ -55,12 +63,13 @@ public class AllEntriesCursor<ID extends
}
- /*
- * @see org.apache.directory.server.xdbm.IndexCursor#afterValue(Long, Object)
+ /**
+ * {@inheritDoc}
*/
public void afterValue( ID key, ID value ) throws Exception
{
checkNotClosed( "afterValue()" );
+
wrapped.afterValue( key, null );
}
@@ -71,6 +80,7 @@ public class AllEntriesCursor<ID extends
public void beforeValue( ID id, ID value ) throws Exception
{
checkNotClosed( "beforeValue()" );
+
wrapped.beforeValue( id, null );
}
@@ -81,22 +91,24 @@ public class AllEntriesCursor<ID extends
public void after( IndexEntry<ID, ID> indexEntry ) throws Exception
{
checkNotClosed( "after()" );
+
wrapped.afterValue( indexEntry.getId(), null );
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#afterLast()
+ /**
+ * {@inheritDoc}
*/
public void afterLast() throws Exception
{
checkNotClosed( "afterLast()" );
+
wrapped.afterLast();
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#available()
+ /**
+ * {@inheritDoc}
*/
public boolean available()
{
@@ -104,42 +116,47 @@ public class AllEntriesCursor<ID extends
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#before(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
public void before( IndexEntry<ID, ID> indexEntry ) throws Exception
{
checkNotClosed( "before()" );
+
wrapped.beforeValue( indexEntry.getId(), null );
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#beforeFirst()
+ /**
+ * {@inheritDoc}
*/
public void beforeFirst() throws Exception
{
checkNotClosed( "beforeFirst()" );
+
wrapped.beforeFirst();
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#first()
+ /**
+ * {@inheritDoc}
*/
public boolean first() throws Exception
{
checkNotClosed( "first()" );
+
return wrapped.first();
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#get()
+ /**
+ * {@inheritDoc}
*/
public IndexEntry<ID, ID> get() throws Exception
{
checkNotClosed( "get()" );
+
+ // Create the returned IndexEntry, copying what we get from the wrapped cursor
IndexEntry<String, ID> wrappedEntry = wrapped.get();
indexEntry.setId( wrappedEntry.getId() );
indexEntry.setValue( wrappedEntry.getId() );
@@ -149,48 +166,55 @@ public class AllEntriesCursor<ID extends
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#last()
+ /**
+ * {@inheritDoc}
*/
public boolean last() throws Exception
{
checkNotClosed( "last()" );
+
return wrapped.last();
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#next()
+ /**
+ * {@inheritDoc}
*/
public boolean next() throws Exception
{
checkNotClosed( "next()" );
+
return wrapped.next();
}
- /*
- * @see org.apache.directory.server.core.cursor.Cursor#previous()
+ /**
+ * {@inheritDoc}
*/
public boolean previous() throws Exception
{
checkNotClosed( "previous()" );
+
return wrapped.previous();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void close() throws Exception
{
wrapped.close();
- super.close();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void close( Exception cause ) throws Exception
{
- wrapped.close();
- super.close( cause );
+ wrapped.close( cause );
}
}
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java Fri Aug 19 12:18:15 2011
@@ -22,7 +22,6 @@ package org.apache.directory.server.xdbm
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.apache.directory.server.i18n.I18n;
@@ -42,8 +41,13 @@ import org.apache.directory.shared.ldap.
*/
public class AndCursor<V, ID> extends AbstractIndexCursor<V, Entry, ID>
{
+ /** The message for unsupported operations */
private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_707 );
+
+ /** */
private final IndexCursor<V, Entry, ID> wrapped;
+
+ /** The evaluators used for the members of the And filter */
private final List<Evaluator<? extends ExprNode, Entry, ID>> evaluators;
@@ -183,9 +187,6 @@ public class AndCursor<V, ID> extends Ab
/**
- * TODO - duplicate code from AndEvaluator just make utility for this and
- * for the same code in the OrEvaluator once done.
- *
* Takes a set of Evaluators and copies then sorts them in a new list with
* increasing scan counts on their expression nodes. This is done to have
* the Evaluators with the least scan count which have the highest
@@ -203,32 +204,7 @@ public class AndCursor<V, ID> extends Ab
unoptimized.size() );
optimized.addAll( unoptimized );
- Collections.sort( optimized, new Comparator<Evaluator<?, Entry, ID>>()
- {
- public int compare( Evaluator<?, Entry, ID> e1, Evaluator<?, Entry, ID> e2 )
- {
- long scanCount1 = ( Long ) e1.getExpression().get( "count" );
- long scanCount2 = ( Long ) e2.getExpression().get( "count" );
-
- if ( scanCount1 == scanCount2 )
- {
- return 0;
- }
-
- /*
- * We want the Evaluator with the smallest scan count first
- * since this node has the highest probability of failing, or
- * rather the least probability of succeeding. That way we
- * can short the sub-expression evaluation process.
- */
- if ( scanCount1 < scanCount2 )
- {
- return -1;
- }
-
- return 1;
- }
- } );
+ Collections.sort( optimized, new ScanCountComparator<ID>() );
return optimized;
}
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AndEvaluator.java Fri Aug 19 12:18:15 2011
@@ -22,7 +22,6 @@ package org.apache.directory.server.xdbm
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.apache.directory.server.xdbm.IndexEntry;
@@ -46,6 +45,11 @@ public class AndEvaluator<ID> implements
private final AndNode node;
+ /**
+ * Creates an instance of AndEvaluator
+ * @param node The And Node
+ * @param evaluators The list of evaluators for all the contaned nodes
+ */
public AndEvaluator( AndNode node, List<Evaluator<? extends ExprNode, Entry, ID>> evaluators )
{
this.node = node;
@@ -64,44 +68,22 @@ public class AndEvaluator<ID> implements
* @param unoptimized the unoptimized list of Evaluators
* @return optimized Evaluator list with increasing scan count ordering
*/
- private List<Evaluator<? extends ExprNode, Entry, ID>> optimize(
+ List<Evaluator<? extends ExprNode, Entry, ID>> optimize(
List<Evaluator<? extends ExprNode, Entry, ID>> unoptimized )
{
List<Evaluator<? extends ExprNode, Entry, ID>> optimized = new ArrayList<Evaluator<? extends ExprNode, Entry, ID>>(
unoptimized.size() );
optimized.addAll( unoptimized );
- Collections.sort( optimized, new Comparator<Evaluator<?, Entry, ID>>()
- {
- public int compare( Evaluator<?, Entry, ID> e1, Evaluator<?, Entry, ID> e2 )
- {
- long scanCount1 = ( Long ) e1.getExpression().get( "count" );
- long scanCount2 = ( Long ) e2.getExpression().get( "count" );
-
- if ( scanCount1 == scanCount2 )
- {
- return 0;
- }
-
- /*
- * We want the Evaluator with the smallest scan count first
- * since this node has the highest probability of failing, or
- * rather the least probability of succeeding. That way we
- * can short the sub-expression evaluation process.
- */
- if ( scanCount1 < scanCount2 )
- {
- return -1;
- }
-
- return 1;
- }
- } );
+ Collections.sort( optimized, new ScanCountComparator<ID>() );
return optimized;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean evaluateEntry( Entry entry ) throws Exception
{
for ( Evaluator<?, Entry, ID> evaluator : evaluators )
@@ -116,6 +98,9 @@ public class AndEvaluator<ID> implements
}
+ /**
+ * {@inheritDoc}
+ */
public boolean evaluate( IndexEntry<?, ID> indexEntry ) throws Exception
{
for ( Evaluator<?, Entry, ID> evaluator : evaluators )
@@ -130,6 +115,9 @@ public class AndEvaluator<ID> implements
}
+ /**
+ * {@inheritDoc}
+ */
public AndNode getExpression()
{
return node;
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java Fri Aug 19 12:18:15 2011
@@ -45,6 +45,7 @@ import org.apache.directory.shared.ldap.
*/
public class ApproximateCursor<V, ID extends Comparable<ID>> extends AbstractIndexCursor<V, Entry, ID>
{
+ /** The message for unsupported operations */
private static final String UNSUPPORTED_MSG = "ApproximateCursors only support positioning by element when a user index exists on the asserted attribute.";
/** An approximate evaluator for candidates */
@@ -56,6 +57,12 @@ public class ApproximateCursor<V, ID ext
/** NDN Cursor on all entries in (set when no index on user attribute) */
private final IndexCursor<String, Entry, ID> uuidIdxCursor;
+ /**
+ * Creates a new instance of ApproximateCursor
+ * @param db The Store we want to build a cursor on
+ * @param approximateEvaluator The evaluator
+ * @throws Exception If the creation failed
+ */
@SuppressWarnings("unchecked")
public ApproximateCursor( Store<Entry, ID> db, ApproximateEvaluator<V, ID> approximateEvaluator ) throws Exception
{
@@ -87,6 +94,9 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public boolean available()
{
if ( userIdxCursor != null )
@@ -134,6 +144,9 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public void before( IndexEntry<V, ID> element ) throws Exception
{
checkNotClosed( "before()" );
@@ -168,6 +181,9 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public void beforeFirst() throws Exception
{
checkNotClosed( "beforeFirst()" );
@@ -183,9 +199,13 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public void afterLast() throws Exception
{
checkNotClosed( "afterLast()" );
+
if ( userIdxCursor != null )
{
userIdxCursor.afterLast();
@@ -198,20 +218,31 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public boolean first() throws Exception
{
beforeFirst();
+
return next();
}
+ /**
+ * {@inheritDoc}
+ */
public boolean last() throws Exception
{
afterLast();
+
return previous();
}
+ /**
+ * {@inheritDoc}
+ */
public boolean previous() throws Exception
{
if ( userIdxCursor != null )
@@ -234,6 +265,9 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public boolean next() throws Exception
{
if ( userIdxCursor != null )
@@ -255,11 +289,14 @@ public class ApproximateCursor<V, ID ext
return setAvailable( false );
}
-
+ /**
+ * {@inheritDoc}
+ */
@SuppressWarnings("unchecked")
public IndexEntry<V, ID> get() throws Exception
{
checkNotClosed( "get()" );
+
if ( userIdxCursor != null )
{
return userIdxCursor.get();
@@ -274,6 +311,9 @@ public class ApproximateCursor<V, ID ext
}
+ /**
+ * {@inheritDoc}
+ */
public void close() throws Exception
{
super.close();
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=1159607&r1=1159606&r2=1159607&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 Fri Aug 19 12:18:15 2011
@@ -43,6 +43,13 @@ import org.apache.directory.shared.ldap.
*/
public class ApproximateEvaluator<T, ID extends Comparable<ID>> extends LeafEvaluator<T, ID>
{
+ /**
+ * Creates a new ApproximateEvaluator
+ * @param node The ApproximateNode
+ * @param db The Store
+ * @param schemaManager The SchemaManager
+ * @throws Exception If the creation failed
+ */
public ApproximateEvaluator( ApproximateNode<T> node, Store<Entry, ID> db, SchemaManager schemaManager )
throws Exception
{
@@ -71,12 +78,18 @@ public class ApproximateEvaluator<T, ID
}
+ /**
+ * {@inheritDoc}
+ */
public ApproximateNode<T> getExpression()
{
return (ApproximateNode<T>)node;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean evaluateEntry( Entry entry ) throws Exception
{
// get the attribute
@@ -116,17 +129,9 @@ public class ApproximateEvaluator<T, ID
}
- public boolean evaluateId( ID id ) throws Exception
- {
- if ( idx != null )
- {
- return idx.reverse( id );
- }
-
- return evaluateEntry( db.lookup( id ) );
- }
-
-
+ /**
+ * {@inheritDoc}
+ */
public boolean evaluate( IndexEntry<?, ID> indexEntry ) throws Exception
{
if ( idx != null )
@@ -158,9 +163,8 @@ public class ApproximateEvaluator<T, ID
* appropriate matching rule to perform the check.
*/
- for ( Value value : attribute )
+ for ( Value<?> value : attribute )
{
- //noinspection unchecked
if ( ldapComparator.compare( value.getNormValue(), node.getValue().getNormValue() ) == 0 )
{
return true;
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java Fri Aug 19 12:18:15 2011
@@ -43,10 +43,11 @@ import org.apache.directory.shared.ldap.
*/
public class EqualityCursor<V, ID extends Comparable<ID>> extends AbstractIndexCursor<V, Entry, ID>
{
+ /** The message for unsupported operations */
private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_714 );
/** An equality evaluator for candidates */
- private final EqualityEvaluator equalityEvaluator;
+ private final EqualityEvaluator<V, ID> equalityEvaluator;
/** Cursor over attribute entry matching filter: set when index present */
private final IndexCursor<V, Entry, ID> userIdxCursor;
@@ -55,6 +56,12 @@ public class EqualityCursor<V, ID extend
private final IndexCursor<String, Entry, ID> uuidIdxCursor;
+ /**
+ * Creates a new instance of an EqualityCursor
+ * @param db The store
+ * @param equalityEvaluator The EqualityEvaluator
+ * @throws Exception If the creation failed
+ */
@SuppressWarnings("unchecked")
public EqualityCursor( Store<Entry, ID> db, EqualityEvaluator<V, ID> equalityEvaluator ) throws Exception
{
@@ -238,7 +245,6 @@ public class EqualityCursor<V, ID extend
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
public boolean previous() throws Exception
{
if ( userIdxCursor != null )
@@ -264,7 +270,6 @@ public class EqualityCursor<V, ID extend
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
public boolean next() throws Exception
{
if ( userIdxCursor != null )
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java?rev=1159607&r1=1159606&r2=1159607&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java Fri Aug 19 12:18:15 2011
@@ -62,8 +62,14 @@ public class GreaterEqCursor<V, ID exten
IndexEntry<String, ID> ndnCandidate;
+ /**
+ * Creates a new instance of an GreaterEqCursor
+ * @param db The store
+ * @param equalityEvaluator The GreaterEqEvaluator
+ * @throws Exception If the creation failed
+ */
@SuppressWarnings("unchecked")
- public GreaterEqCursor( Store<Entry, ID> db, GreaterEqEvaluator greaterEqEvaluator ) throws Exception
+ public GreaterEqCursor( Store<Entry, ID> db, GreaterEqEvaluator<V, ID> greaterEqEvaluator ) throws Exception
{
this.greaterEqEvaluator = greaterEqEvaluator;
@@ -231,7 +237,8 @@ public class GreaterEqCursor<V, ID exten
return;
}
- else if ( comparedValue < 0 )
+
+ if ( comparedValue < 0 )
{
beforeFirst();
@@ -249,10 +256,14 @@ public class GreaterEqCursor<V, ID exten
}
+ /**
+ * {@inheritDoc}
+ */
@SuppressWarnings("unchecked")
public void beforeFirst() throws Exception
{
checkNotClosed( "beforeFirst()" );
+
if ( userIdxCursor != null )
{
IndexEntry<V, ID> advanceTo = new ForwardIndexEntry<V, ID>();
@@ -269,9 +280,13 @@ public class GreaterEqCursor<V, ID exten
}
+ /**
+ * {@inheritDoc}
+ */
public void afterLast() throws Exception
{
checkNotClosed( "afterLast()" );
+
if ( userIdxCursor != null )
{
userIdxCursor.afterLast();
@@ -286,24 +301,35 @@ public class GreaterEqCursor<V, ID exten
}
+ /**
+ * {@inheritDoc}
+ */
public boolean first() throws Exception
{
beforeFirst();
+
return next();
}
+ /**
+ * {@inheritDoc}
+ */
public boolean last() throws Exception
{
afterLast();
+
return previous();
}
- @SuppressWarnings("unchecked")
+ /**
+ * {@inheritDoc}
+ */
public boolean previous() throws Exception
{
checkNotClosed( "previous()" );
+
if ( userIdxCursor != null )
{
/*
@@ -340,6 +366,9 @@ public class GreaterEqCursor<V, ID exten
}
+ /**
+ * {@inheritDoc}
+ */
public boolean next() throws Exception
{
checkNotClosed( "next()" );
@@ -368,6 +397,9 @@ public class GreaterEqCursor<V, ID exten
}
+ /**
+ * {@inheritDoc}
+ */
@SuppressWarnings("unchecked")
public IndexEntry<V, ID> get() throws Exception
{
@@ -392,6 +424,9 @@ public class GreaterEqCursor<V, ID exten
}
+ /**
+ * {@inheritDoc}
+ */
public void close() throws Exception
{
super.close();
Added: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ScanCountComparator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ScanCountComparator.java?rev=1159607&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ScanCountComparator.java (added)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ScanCountComparator.java Fri Aug 19 12:18:15 2011
@@ -0,0 +1,63 @@
+/*
+ * 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 java.util.Comparator;
+
+import org.apache.directory.server.xdbm.search.Evaluator;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+
+/**
+ * A helper class used to compare scan counts.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ *
+ * @param <ID> The type of element
+ */
+public class ScanCountComparator<ID> implements Comparator<Evaluator<?, Entry, ID>>
+{
+ /**
+ * Compare two scan counts frpm two evaluators
+ */
+ public int compare( Evaluator<?, Entry, ID> e1, Evaluator<?, Entry, ID> e2 )
+ {
+ long scanCount1 = ( Long ) e1.getExpression().get( "count" );
+ long scanCount2 = ( Long ) e2.getExpression().get( "count" );
+
+ if ( scanCount1 == scanCount2 )
+ {
+ return 0;
+ }
+
+ /*
+ * We want the Evaluator with the smallest scan count first
+ * since this node has the highest probability of failing, or
+ * rather the least probability of succeeding. That way we
+ * can short the sub-expression evaluation process.
+ */
+ if ( scanCount1 < scanCount2 )
+ {
+ return -1;
+ }
+
+ return 1;
+ }
+
+}