com.sleepycat.collections
Class DataCursor

java.lang.Object
  extended by com.sleepycat.collections.DataCursor
All Implemented Interfaces:
Cloneable

final class DataCursor
extends Object
implements Cloneable

Represents a Berkeley DB cursor and adds support for indices, bindings and key ranges.

This class operates on a view and takes care of reading and updating indices, calling bindings, constraining access to a key range, etc.

Author:
Mark Hayes

Field Summary
(package private) static int REPOS_EOF
          Repositioned failed, no records on or after the key/data pair given.
(package private) static int REPOS_EXACT
          Repositioned exactly to the key/data pair given.
(package private) static int REPOS_NEXT
          Repositioned on a record following the key/data pair given.
 
Constructor Summary
DataCursor(DataView view, boolean writeAllowed)
          Creates a cursor for a given view.
DataCursor(DataView view, boolean writeAllowed, CursorConfig config)
          Creates a cursor for a given view.
DataCursor(DataView view, boolean writeAllowed, Object singleKey)
          Creates a cursor for a given view and single key range.
DataCursor(DataView view, boolean writeAllowed, Object beginKey, boolean beginInclusive, Object endKey, boolean endInclusive)
          Creates a cursor for a given view and key range.
DataCursor(DataView view, DataCursor[] indexCursors, JoinConfig joinConfig, boolean closeIndexCursors)
          Creates a join cursor.
 
Method Summary
(package private)  DataCursor cloneCursor()
          Clones a cursor preserving the current position.
(package private)  void close()
          Closes the associated cursor.
(package private)  int count()
          Calls Cursor.count(), no join cursor allowed.
(package private)  OperationStatus delete()
          Perform an arbitrary database 'delete' operation.
(package private)  OperationStatus findBoth(Object key, Object value, boolean lockForWrite)
          Find the given key and value using getSearchBoth if possible or a sequential scan otherwise, no join cursor allowed.
(package private)  OperationStatus findValue(Object value, boolean findFirst)
          Find the given value using getSearchBoth if possible or a sequential scan otherwise, no join cursor allowed.
(package private)  OperationStatus getCurrent(boolean lockForWrite)
          Binding version of Cursor.getCurrent(), no join cursor allowed.
(package private)  Object getCurrentKey()
          Returns the key object for the last record read.
(package private)  int getCurrentRecordNumber()
          Returns the record number for the last record read.
(package private)  Object getCurrentValue()
          Returns the value object for the last record read.
(package private)  RangeCursor getCursor()
          Returns the internal range cursor.
(package private)  OperationStatus getFirst(boolean lockForWrite)
          Binding version of Cursor.getFirst(), join cursor is allowed.
(package private)  DatabaseEntry getKeyThang()
          Returns the internal key entry.
(package private)  OperationStatus getLast(boolean lockForWrite)
          Binding version of Cursor.getLast(), no join cursor allowed.
(package private)  LockMode getLockMode(boolean lockForWrite)
          Returns the lock mode to use for a getXxx() operation.
(package private)  OperationStatus getNext(boolean lockForWrite)
          Binding version of Cursor.getNext(), join cursor is allowed.
(package private)  OperationStatus getNextDup(boolean lockForWrite)
          Binding version of Cursor.getNextDup(), no join cursor allowed.
(package private)  OperationStatus getNextNoDup(boolean lockForWrite)
          Binding version of Cursor.getNext(), join cursor is allowed.
(package private)  OperationStatus getPrev(boolean lockForWrite)
          Binding version of Cursor.getPrev(), no join cursor allowed.
(package private)  OperationStatus getPrevDup(boolean lockForWrite)
          Binding version of Cursor.getPrevDup(), no join cursor allowed.
(package private)  OperationStatus getPrevNoDup(boolean lockForWrite)
          Binding version of Cursor.getPrevNoDup(), no join cursor allowed.
(package private)  DatabaseEntry getPrimaryKeyThang()
          Returns the internal primary key entry, which is the same object as the key entry if the cursor is not for a secondary database.
(package private)  KeyRange getRange()
          Returns the range for this cursor.
(package private)  OperationStatus getSearchKey(Object key, Object value, boolean lockForWrite)
          Binding version of Cursor.getSearchKey(), no join cursor allowed.
(package private)  OperationStatus getSearchKeyRange(Object key, Object value, boolean lockForWrite)
          Binding version of Cursor.getSearchKeyRange(), no join cursor allowed.
(package private)  DatabaseEntry getValueThang()
          Returns the internal value entry.
(package private)  DataView getView()
          Returns the view for this cursor.
(package private)  boolean hasRecNumAccess()
          Returns whether record number access is allowed.
(package private)  boolean isWriteAllowed()
          Returns whether write is allowed for this cursor, as specified to the constructor.
(package private)  OperationStatus put(Object key, Object value, Object[] oldValue, boolean useCurrentKey)
          Binding version of Cursor.put(), optionally returning the old value and optionally using the current key instead of the key parameter.
(package private)  OperationStatus putAfter(Object value)
          Binding version of Cursor.putAfter().
(package private)  OperationStatus putBefore(Object value)
          Binding version of Cursor.putBefore().
(package private)  OperationStatus putCurrent(Object value)
          Binding version of Cursor.putCurrent().
(package private)  OperationStatus putNoDupData(Object key, Object value, Object[] oldValue, boolean useCurrentKey)
          Binding version of Cursor.putNoDupData(), optionally returning the old value and optionally using the current key instead of the key parameter.
(package private)  OperationStatus putNoOverwrite(Object key, Object value, boolean useCurrentKey)
          Binding version of Cursor.putNoOverwrite(), optionally using the current key instead of the key parameter.
(package private)  boolean repositionExact(byte[] keyBytes, byte[] priKeyBytes, byte[] valueBytes, boolean lockForWrite)
          Repositions to a given raw key/data pair.
(package private)  int repositionRange(byte[] keyBytes, byte[] priKeyBytes, byte[] valueBytes, boolean lockForWrite)
          Repositions to a given raw key/data pair, or just past it if that record has been deleted.
(package private)  void useRangeKey()
          Sets the key entry to the begin key of a single key range, so the next time a putXxx() method is called that key will be used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPOS_EXACT

static final int REPOS_EXACT
Repositioned exactly to the key/data pair given.

See Also:
Constant Field Values

REPOS_NEXT

static final int REPOS_NEXT
Repositioned on a record following the key/data pair given.

See Also:
Constant Field Values

REPOS_EOF

static final int REPOS_EOF
Repositioned failed, no records on or after the key/data pair given.

See Also:
Constant Field Values
Constructor Detail

DataCursor

DataCursor(DataView view,
           boolean writeAllowed)
     throws DatabaseException
Creates a cursor for a given view.

Throws:
DatabaseException

DataCursor

DataCursor(DataView view,
           boolean writeAllowed,
           CursorConfig config)
     throws DatabaseException
Creates a cursor for a given view.

Throws:
DatabaseException

DataCursor

DataCursor(DataView view,
           boolean writeAllowed,
           Object singleKey)
     throws DatabaseException
Creates a cursor for a given view and single key range. Used by unit tests.

Throws:
DatabaseException

DataCursor

DataCursor(DataView view,
           boolean writeAllowed,
           Object beginKey,
           boolean beginInclusive,
           Object endKey,
           boolean endInclusive)
     throws DatabaseException
Creates a cursor for a given view and key range. Used by unit tests.

Throws:
DatabaseException

DataCursor

DataCursor(DataView view,
           DataCursor[] indexCursors,
           JoinConfig joinConfig,
           boolean closeIndexCursors)
     throws DatabaseException
Creates a join cursor.

Throws:
DatabaseException
Method Detail

cloneCursor

DataCursor cloneCursor()
                 throws DatabaseException
Clones a cursor preserving the current position.

Throws:
DatabaseException

getCursor

RangeCursor getCursor()
Returns the internal range cursor.


close

void close()
     throws DatabaseException
Closes the associated cursor.

Throws:
DatabaseException

repositionRange

int repositionRange(byte[] keyBytes,
                    byte[] priKeyBytes,
                    byte[] valueBytes,
                    boolean lockForWrite)
              throws DatabaseException
Repositions to a given raw key/data pair, or just past it if that record has been deleted.

Returns:
REPOS_EXACT, REPOS_NEXT or REPOS_EOF.
Throws:
DatabaseException

repositionExact

boolean repositionExact(byte[] keyBytes,
                        byte[] priKeyBytes,
                        byte[] valueBytes,
                        boolean lockForWrite)
                  throws DatabaseException
Repositions to a given raw key/data pair.

Returns:
whether the search succeeded.
Throws:
IllegalStateException - when the database has unordered keys or unordered duplicates.
DatabaseException

getView

DataView getView()
Returns the view for this cursor.


getRange

KeyRange getRange()
Returns the range for this cursor.


isWriteAllowed

boolean isWriteAllowed()
Returns whether write is allowed for this cursor, as specified to the constructor.


getCurrentKey

Object getCurrentKey()
               throws DatabaseException
Returns the key object for the last record read.

Throws:
DatabaseException

getCurrentValue

Object getCurrentValue()
                 throws DatabaseException
Returns the value object for the last record read.

Throws:
DatabaseException

getKeyThang

DatabaseEntry getKeyThang()
Returns the internal key entry.


getPrimaryKeyThang

DatabaseEntry getPrimaryKeyThang()
Returns the internal primary key entry, which is the same object as the key entry if the cursor is not for a secondary database.


getValueThang

DatabaseEntry getValueThang()
Returns the internal value entry.


hasRecNumAccess

boolean hasRecNumAccess()
Returns whether record number access is allowed.


getCurrentRecordNumber

int getCurrentRecordNumber()
                     throws DatabaseException
Returns the record number for the last record read.

Throws:
DatabaseException

getCurrent

OperationStatus getCurrent(boolean lockForWrite)
                     throws DatabaseException
Binding version of Cursor.getCurrent(), no join cursor allowed.

Throws:
DatabaseException

getFirst

OperationStatus getFirst(boolean lockForWrite)
                   throws DatabaseException
Binding version of Cursor.getFirst(), join cursor is allowed.

Throws:
DatabaseException

getNext

OperationStatus getNext(boolean lockForWrite)
                  throws DatabaseException
Binding version of Cursor.getNext(), join cursor is allowed.

Throws:
DatabaseException

getNextNoDup

OperationStatus getNextNoDup(boolean lockForWrite)
                       throws DatabaseException
Binding version of Cursor.getNext(), join cursor is allowed.

Throws:
DatabaseException

getNextDup

OperationStatus getNextDup(boolean lockForWrite)
                     throws DatabaseException
Binding version of Cursor.getNextDup(), no join cursor allowed.

Throws:
DatabaseException

getLast

OperationStatus getLast(boolean lockForWrite)
                  throws DatabaseException
Binding version of Cursor.getLast(), no join cursor allowed.

Throws:
DatabaseException

getPrev

OperationStatus getPrev(boolean lockForWrite)
                  throws DatabaseException
Binding version of Cursor.getPrev(), no join cursor allowed.

Throws:
DatabaseException

getPrevNoDup

OperationStatus getPrevNoDup(boolean lockForWrite)
                       throws DatabaseException
Binding version of Cursor.getPrevNoDup(), no join cursor allowed.

Throws:
DatabaseException

getPrevDup

OperationStatus getPrevDup(boolean lockForWrite)
                     throws DatabaseException
Binding version of Cursor.getPrevDup(), no join cursor allowed.

Throws:
DatabaseException

getSearchKey

OperationStatus getSearchKey(Object key,
                             Object value,
                             boolean lockForWrite)
                       throws DatabaseException
Binding version of Cursor.getSearchKey(), no join cursor allowed. Searches by record number in a BTREE-RECNO db with RECNO access.

Throws:
DatabaseException

getSearchKeyRange

OperationStatus getSearchKeyRange(Object key,
                                  Object value,
                                  boolean lockForWrite)
                            throws DatabaseException
Binding version of Cursor.getSearchKeyRange(), no join cursor allowed.

Throws:
DatabaseException

findBoth

OperationStatus findBoth(Object key,
                         Object value,
                         boolean lockForWrite)
                   throws DatabaseException
Find the given key and value using getSearchBoth if possible or a sequential scan otherwise, no join cursor allowed.

Throws:
DatabaseException

findValue

OperationStatus findValue(Object value,
                          boolean findFirst)
                    throws DatabaseException
Find the given value using getSearchBoth if possible or a sequential scan otherwise, no join cursor allowed.

Throws:
DatabaseException

count

int count()
    throws DatabaseException
Calls Cursor.count(), no join cursor allowed.

Throws:
DatabaseException

putCurrent

OperationStatus putCurrent(Object value)
                     throws DatabaseException
Binding version of Cursor.putCurrent().

Throws:
DatabaseException

putAfter

OperationStatus putAfter(Object value)
                   throws DatabaseException
Binding version of Cursor.putAfter().

Throws:
DatabaseException

putBefore

OperationStatus putBefore(Object value)
                    throws DatabaseException
Binding version of Cursor.putBefore().

Throws:
DatabaseException

put

OperationStatus put(Object key,
                    Object value,
                    Object[] oldValue,
                    boolean useCurrentKey)
              throws DatabaseException
Binding version of Cursor.put(), optionally returning the old value and optionally using the current key instead of the key parameter.

Throws:
DatabaseException

putNoOverwrite

OperationStatus putNoOverwrite(Object key,
                               Object value,
                               boolean useCurrentKey)
                         throws DatabaseException
Binding version of Cursor.putNoOverwrite(), optionally using the current key instead of the key parameter.

Throws:
DatabaseException

putNoDupData

OperationStatus putNoDupData(Object key,
                             Object value,
                             Object[] oldValue,
                             boolean useCurrentKey)
                       throws DatabaseException
Binding version of Cursor.putNoDupData(), optionally returning the old value and optionally using the current key instead of the key parameter.

Throws:
DatabaseException

useRangeKey

void useRangeKey()
Sets the key entry to the begin key of a single key range, so the next time a putXxx() method is called that key will be used.


delete

OperationStatus delete()
                 throws DatabaseException
Perform an arbitrary database 'delete' operation.

Throws:
DatabaseException

getLockMode

LockMode getLockMode(boolean lockForWrite)
Returns the lock mode to use for a getXxx() operation.



Copyright 2004-2006 Sleepycat, Inc. All Rights Reserved.