com.sleepycat.util.keyrange
Class RangeCursor

java.lang.Object
  extended by com.sleepycat.util.keyrange.RangeCursor
All Implemented Interfaces:
java.lang.Cloneable

public class RangeCursor
extends java.lang.Object
implements java.lang.Cloneable

A cursor-like interface that enforces a key range. The method signatures are actually those of SecondaryCursor, but the pKey parameter may be null. It was done this way to avoid doubling the number of methods.

This is not a fully general implementation of a range cursor and should not be used directly by applications; however, it may evolve into a generally useful range cursor some day.


Constructor Summary
RangeCursor(KeyRange range, KeyRange pkRange, boolean sortedDups, Cursor cursor)
          Creates a range cursor with a duplicate range.
 
Method Summary
protected  boolean checkRecordNumber()
          If the database is a RECNO or QUEUE database, we know its keys are record numbers.
 void close()
           
protected  void closeCursor(Cursor cursor)
          Closes the given cursor.
 int count()
           
 OperationStatus delete()
           
 RangeCursor dup(boolean samePosition)
          Create a cloned range cursor.
protected  Cursor dupCursor(Cursor cursor, boolean samePosition)
          Dups the given cursor.
 OperationStatus getCurrent(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 Cursor getCursor()
          Returns the underlying cursor.
 OperationStatus getFirst(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getLast(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getNext(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getNextDup(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getNextNoDup(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getPrev(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getPrevDup(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getPrevNoDup(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getSearchBoth(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getSearchBothRange(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getSearchKey(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getSearchKeyRange(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 OperationStatus getSearchRecordNumber(DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
 boolean isInitialized()
          Returns whether the cursor is initialized at a valid position.
 OperationStatus put(DatabaseEntry key, DatabaseEntry data)
           
 OperationStatus putAfter(DatabaseEntry key, DatabaseEntry data)
           
 OperationStatus putBefore(DatabaseEntry key, DatabaseEntry data)
           
 OperationStatus putCurrent(DatabaseEntry data)
           
 OperationStatus putNoDupData(DatabaseEntry key, DatabaseEntry data)
           
 OperationStatus putNoOverwrite(DatabaseEntry key, DatabaseEntry data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangeCursor

public RangeCursor(KeyRange range,
                   KeyRange pkRange,
                   boolean sortedDups,
                   Cursor cursor)
            throws DatabaseException
Creates a range cursor with a duplicate range.

Throws:
DatabaseException
Method Detail

dup

public RangeCursor dup(boolean samePosition)
                throws DatabaseException
Create a cloned range cursor. The caller must clone the underlying cursor before using this constructor, because cursor open/close is handled specially for CDS cursors outside this class.

Throws:
DatabaseException

isInitialized

public boolean isInitialized()
Returns whether the cursor is initialized at a valid position.


getCursor

public Cursor getCursor()
Returns the underlying cursor. Used for cloning.


getFirst

public OperationStatus getFirst(DatabaseEntry key,
                                DatabaseEntry pKey,
                                DatabaseEntry data,
                                LockMode lockMode)
                         throws DatabaseException
Throws:
DatabaseException

getLast

public OperationStatus getLast(DatabaseEntry key,
                               DatabaseEntry pKey,
                               DatabaseEntry data,
                               LockMode lockMode)
                        throws DatabaseException
Throws:
DatabaseException

getNext

public OperationStatus getNext(DatabaseEntry key,
                               DatabaseEntry pKey,
                               DatabaseEntry data,
                               LockMode lockMode)
                        throws DatabaseException
Throws:
DatabaseException

getNextNoDup

public OperationStatus getNextNoDup(DatabaseEntry key,
                                    DatabaseEntry pKey,
                                    DatabaseEntry data,
                                    LockMode lockMode)
                             throws DatabaseException
Throws:
DatabaseException

getPrev

public OperationStatus getPrev(DatabaseEntry key,
                               DatabaseEntry pKey,
                               DatabaseEntry data,
                               LockMode lockMode)
                        throws DatabaseException
Throws:
DatabaseException

getPrevNoDup

public OperationStatus getPrevNoDup(DatabaseEntry key,
                                    DatabaseEntry pKey,
                                    DatabaseEntry data,
                                    LockMode lockMode)
                             throws DatabaseException
Throws:
DatabaseException

getSearchKey

public OperationStatus getSearchKey(DatabaseEntry key,
                                    DatabaseEntry pKey,
                                    DatabaseEntry data,
                                    LockMode lockMode)
                             throws DatabaseException
Throws:
DatabaseException

getSearchBoth

public OperationStatus getSearchBoth(DatabaseEntry key,
                                     DatabaseEntry pKey,
                                     DatabaseEntry data,
                                     LockMode lockMode)
                              throws DatabaseException
Throws:
DatabaseException

getSearchKeyRange

public OperationStatus getSearchKeyRange(DatabaseEntry key,
                                         DatabaseEntry pKey,
                                         DatabaseEntry data,
                                         LockMode lockMode)
                                  throws DatabaseException
Throws:
DatabaseException

getSearchBothRange

public OperationStatus getSearchBothRange(DatabaseEntry key,
                                          DatabaseEntry pKey,
                                          DatabaseEntry data,
                                          LockMode lockMode)
                                   throws DatabaseException
Throws:
DatabaseException

getSearchRecordNumber

public OperationStatus getSearchRecordNumber(DatabaseEntry key,
                                             DatabaseEntry pKey,
                                             DatabaseEntry data,
                                             LockMode lockMode)
                                      throws DatabaseException
Throws:
DatabaseException

getNextDup

public OperationStatus getNextDup(DatabaseEntry key,
                                  DatabaseEntry pKey,
                                  DatabaseEntry data,
                                  LockMode lockMode)
                           throws DatabaseException
Throws:
DatabaseException

getPrevDup

public OperationStatus getPrevDup(DatabaseEntry key,
                                  DatabaseEntry pKey,
                                  DatabaseEntry data,
                                  LockMode lockMode)
                           throws DatabaseException
Throws:
DatabaseException

getCurrent

public OperationStatus getCurrent(DatabaseEntry key,
                                  DatabaseEntry pKey,
                                  DatabaseEntry data,
                                  LockMode lockMode)
                           throws DatabaseException
Throws:
DatabaseException

close

public void close()
           throws DatabaseException
Throws:
DatabaseException

count

public int count()
          throws DatabaseException
Throws:
DatabaseException

delete

public OperationStatus delete()
                       throws DatabaseException
Throws:
DatabaseException

put

public OperationStatus put(DatabaseEntry key,
                           DatabaseEntry data)
                    throws DatabaseException
Throws:
DatabaseException

putNoOverwrite

public OperationStatus putNoOverwrite(DatabaseEntry key,
                                      DatabaseEntry data)
                               throws DatabaseException
Throws:
DatabaseException

putNoDupData

public OperationStatus putNoDupData(DatabaseEntry key,
                                    DatabaseEntry data)
                             throws DatabaseException
Throws:
DatabaseException

putCurrent

public OperationStatus putCurrent(DatabaseEntry data)
                           throws DatabaseException
Throws:
DatabaseException

putAfter

public OperationStatus putAfter(DatabaseEntry key,
                                DatabaseEntry data)
                         throws DatabaseException
Throws:
DatabaseException

putBefore

public OperationStatus putBefore(DatabaseEntry key,
                                 DatabaseEntry data)
                          throws DatabaseException
Throws:
DatabaseException

dupCursor

protected Cursor dupCursor(Cursor cursor,
                           boolean samePosition)
                    throws DatabaseException
Dups the given cursor.

Throws:
DatabaseException

closeCursor

protected void closeCursor(Cursor cursor)
                    throws DatabaseException
Closes the given cursor.

Throws:
DatabaseException

checkRecordNumber

protected boolean checkRecordNumber()
If the database is a RECNO or QUEUE database, we know its keys are record numbers. We treat a non-positive record number as out of bounds, that is, we return NOTFOUND rather than throwing IllegalArgumentException as would happen if we passed a non-positive record number into the DB cursor. This behavior is required by the collections interface.