public class CursorImpl
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
CursorImpl.KeyChangeStatus
Holder for an OperationStatus and a keyChange flag.
|
static class |
CursorImpl.SearchMode
public for Cursor et al
|
static interface |
CursorImpl.WithCursor
Callback object for traverseDbWithCursor.
|
Modifier and Type | Field and Description |
---|---|
static int |
EXACT_DATA |
static int |
EXACT_KEY |
static int |
FOUND |
static int |
FOUND_LAST |
Constructor and Description |
---|
CursorImpl(DatabaseImpl database,
Locker locker)
Creates a cursor with retainNonTxnLocks=true.
|
CursorImpl(DatabaseImpl databaseImpl,
Locker locker,
boolean retainNonTxnLocks)
Creates a cursor.
|
Modifier and Type | Method and Description |
---|---|
void |
addCursor()
Add to the current cursor.
|
void |
addCursor(BIN bin) |
boolean |
advanceCursor(DatabaseEntry key,
DatabaseEntry data)
Advance a cursor.
|
void |
checkCursorState(boolean mustBeInitialized)
Check that the cursor is open and optionally if it is initialized.
|
void |
checkEnv() |
void |
clearDupBIN(boolean alreadyLatched)
Clear the reference to the dup tree, if any.
|
CursorImpl |
cloneCursor(boolean addCursor)
Shallow copy.
|
CursorImpl |
cloneCursor(boolean addCursor,
CursorImpl usePosition)
Performs a shallow copy.
|
void |
close()
Close a cursor.
|
int |
count(LockType lockType) |
OperationStatus |
delete(ReplicationContext repContext)
Delete the item pointed to by the cursor.
|
OperationStatus |
deleteReplicatedLN(LNLogEntry lnEntry,
ReplicationContext repContext)
Delete the replicated LN.
|
void |
dump()
dump the cursor for debugging purposes.
|
void |
dump(boolean verbose)
Dump the cursor for debugging purposes.
|
java.lang.String |
dumpToString(boolean verbose) |
void |
dumpTree() |
CursorImpl |
dup(boolean samePosition)
Return a new copy of the cursor.
|
void |
evict()
Evict the LN node at the cursor position.
|
void |
evict(boolean alreadyLatched)
Evict the LN node at the cursor position.
|
BIN |
getBIN() |
BIN |
getBINToBeRemoved() |
CacheMode |
getCacheMode() |
OperationStatus |
getCurrent(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType)
Retrieve the current record.
|
OperationStatus |
getCurrentAlreadyLatched(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType,
boolean first)
Retrieve the current record.
|
LN |
getCurrentLN(LockType lockType)
Retrieve the current LN, return with the target bin unlatched.
|
LN |
getCurrentLNAlreadyLatched(LockType lockType)
Retrieve the current LN, assuming the BIN is already latched.
|
DBIN |
getDupBIN() |
DBIN |
getDupBINToBeRemoved() |
int |
getDupIndex() |
OperationStatus |
getFirstDuplicate(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType)
Retrieve the first duplicate at the current cursor position.
|
int |
getIndex() |
DIN |
getLatchedDupRoot(boolean isDBINLatched)
Fetch, latch and return the DIN root of the duplicate tree at the cursor
position.
|
Locker |
getLocker() |
CursorImpl |
getLockerNext() |
CursorImpl |
getLockerPrev() |
LockStats |
getLockStats() |
OperationStatus |
getNext(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType,
boolean forward,
boolean alreadyLatched) |
OperationStatus |
getNextDuplicate(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType,
boolean forward,
boolean alreadyLatched)
Enter with dupBin unlatched.
|
OperationStatus |
getNextNoDup(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType,
boolean forward,
boolean alreadyLatched) |
CursorImpl.KeyChangeStatus |
getNextWithKeyChangeStatus(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType,
boolean forward,
boolean alreadyLatched)
Move the cursor forward and return the next record.
|
int |
hashCode() |
void |
incrementLNCount() |
boolean |
isClosed() |
boolean |
isNotInitialized() |
BIN |
latchBIN() |
void |
latchBINs() |
DBIN |
latchDBIN() |
LockResult |
lockDupCountLN(DIN dupRoot,
LockType lockType)
Locks the DupCountLN for the given duplicate root.
|
void |
lockEofNode(LockType lockType)
Locks the logical EOF node for the databaseImpl.
|
LockResult |
lockLNDeletedAllowed(LN ln,
LockType lockType)
Locks the given LN's node ID; a deleted LN will be locked and returned.
|
void |
lockNextKeyForInsert(DatabaseEntry key,
DatabaseEntry data)
Search for the next key (or duplicate) following the given key (and
datum), and acquire a range insert lock on it.
|
boolean |
positionFirstOrLast(boolean first,
DIN duplicateRoot)
Position the cursor at the first or last record of the databaseImpl.
|
OperationStatus |
put(DatabaseEntry key,
DatabaseEntry data,
DatabaseEntry foundData)
Insert or overwrite the key/data pair.
|
OperationStatus |
putCurrent(DatabaseEntry data,
DatabaseEntry foundKey,
DatabaseEntry foundData,
ReplicationContext repContext)
Modify the current record with this data.
|
OperationStatus |
putLN(byte[] key,
LN ln,
boolean allowDuplicates,
ReplicationContext repContext)
Insert the given LN in the tree or return KEYEXIST if the key is already
present.
|
OperationStatus |
putNoDupData(DatabaseEntry key,
DatabaseEntry data)
Insert the key/data pair as long as no entry for key/data exists yet.
|
OperationStatus |
putNoOverwrite(DatabaseEntry key,
DatabaseEntry data)
Insert the key/data pair in No Overwrite mode.
|
OperationStatus |
putReplicatedLN(LNLogEntry lnEntry,
ReplicationContext repContext)
Insert the replicated LN.
|
void |
releaseBIN() |
void |
releaseBINs() |
void |
releaseDBIN() |
void |
reset()
Reset a cursor to an uninitialized state, but unlike close(), allow it
to be used further.
|
int |
searchAndPosition(DatabaseEntry matchKey,
DatabaseEntry matchData,
CursorImpl.SearchMode searchMode,
LockType lockType)
Position the cursor at the key.
|
void |
setAllowEviction(boolean allowed)
Disables or enables eviction during cursor operations.
|
void |
setBIN(BIN newBin) |
void |
setCacheMode(CacheMode cacheMode) |
static void |
setDbt(DatabaseEntry data,
byte[] bytes)
Helper to return a Data DBT from a BIN.
|
void |
setDupBIN(DBIN newDupBin) |
void |
setDupIndex(int dupIdx) |
void |
setIndex(int idx) |
void |
setLockerNext(CursorImpl n) |
void |
setLockerPrev(CursorImpl p) |
void |
setNonCloning(boolean nonCloning)
Prevents this cursor from being cloned for any reason.
|
void |
setTestHook(TestHook hook) |
void |
setTreeStatsAccumulator(TreeWalkerStatsAccumulator tSA) |
static void |
traverseDbWithCursor(DatabaseImpl db,
LockType lockType,
boolean allowEviction,
CursorImpl.WithCursor withCursor)
Enumerates all records in a databaseImpl non-transactionally and calls
the withCursor method for each record.
|
void |
updateBin(BIN bin,
int index) |
void |
updateDBin(DBIN dupBin,
int dupIndex) |
public static final int FOUND
public static final int EXACT_KEY
public static final int EXACT_DATA
public static final int FOUND_LAST
public CursorImpl(DatabaseImpl database, Locker locker) throws DatabaseException
DatabaseException
public CursorImpl(DatabaseImpl databaseImpl, Locker locker, boolean retainNonTxnLocks) throws DatabaseException
retainNonTxnLocks
- is true if non-transactional locks should be
retained (not released automatically) when the cursor is reset or
closed.DatabaseException
public int hashCode()
hashCode
in class java.lang.Object
public void incrementLNCount()
public void setNonCloning(boolean nonCloning)
public void setAllowEviction(boolean allowed)
public CursorImpl cloneCursor(boolean addCursor) throws DatabaseException
DatabaseException
public CursorImpl cloneCursor(boolean addCursor, CursorImpl usePosition) throws DatabaseException
addCursor
- If true, addCursor() is called to register the new
cursor with the BINs. This is done after the usePosition parameter is
applied, if any. There are two cases where you may not want addCursor()
to be called: 1) When creating a fresh uninitialzed cursor as in when
Cursor.dup(false) is called, or 2) when the caller will call addCursor()
as part of a larger operation.usePosition
- Is null to duplicate the position of this cursor, or
non-null to duplicate the position of the given cursor.DatabaseException
public int getIndex()
public void setIndex(int idx)
public BIN getBIN()
public void setBIN(BIN newBin)
public BIN getBINToBeRemoved()
public int getDupIndex()
public void setDupIndex(int dupIdx)
public DBIN getDupBIN()
public void setDupBIN(DBIN newDupBin)
public DBIN getDupBINToBeRemoved()
public CacheMode getCacheMode()
public void setCacheMode(CacheMode cacheMode)
public void setTreeStatsAccumulator(TreeWalkerStatsAccumulator tSA)
public boolean advanceCursor(DatabaseEntry key, DatabaseEntry data)
key
- on return contains the key if available, or null.data
- on return contains the data if available, or null.public BIN latchBIN() throws DatabaseException
DatabaseException
public void releaseBIN() throws LatchNotHeldException
LatchNotHeldException
public void latchBINs() throws DatabaseException
DatabaseException
public void releaseBINs() throws LatchNotHeldException
LatchNotHeldException
public DBIN latchDBIN() throws DatabaseException
DatabaseException
public void releaseDBIN() throws LatchNotHeldException
LatchNotHeldException
public Locker getLocker()
public void addCursor(BIN bin)
public void addCursor()
public void updateBin(BIN bin, int index) throws DatabaseException
DatabaseException
public void updateDBin(DBIN dupBin, int dupIndex)
public void clearDupBIN(boolean alreadyLatched) throws DatabaseException
DatabaseException
public void dumpTree() throws DatabaseException
DatabaseException
public boolean isClosed()
public boolean isNotInitialized()
public void reset() throws DatabaseException
DatabaseException
public void close() throws DatabaseException
DatabaseException
- if the cursor was previously closed.public int count(LockType lockType) throws DatabaseException
DatabaseException
public OperationStatus delete(ReplicationContext repContext) throws DatabaseException
DatabaseException
public CursorImpl dup(boolean samePosition) throws DatabaseException
samePosition
- If true, position the returned cursor at the same
position as this cursor; if false, return a new uninitialized cursor.DatabaseException
public void evict() throws DatabaseException
DatabaseException
public void evict(boolean alreadyLatched) throws DatabaseException
DatabaseException
public void lockNextKeyForInsert(DatabaseEntry key, DatabaseEntry data) throws DatabaseException
DatabaseException
public OperationStatus putLN(byte[] key, LN ln, boolean allowDuplicates, ReplicationContext repContext) throws DatabaseException
This method is called directly internally for putting tree map LNs and file summary LNs. It should not be used otherwise, and in the future we should find a way to remove this special case.
DatabaseException
public OperationStatus put(DatabaseEntry key, DatabaseEntry data, DatabaseEntry foundData) throws DatabaseException
key
- data
- DatabaseException
public OperationStatus putReplicatedLN(LNLogEntry lnEntry, ReplicationContext repContext) throws DatabaseException
DatabaseException
public OperationStatus deleteReplicatedLN(LNLogEntry lnEntry, ReplicationContext repContext) throws DatabaseException
DatabaseException
public OperationStatus putNoOverwrite(DatabaseEntry key, DatabaseEntry data) throws DatabaseException
key
- data
- DatabaseException
public OperationStatus putNoDupData(DatabaseEntry key, DatabaseEntry data) throws DatabaseException
DatabaseException
public OperationStatus putCurrent(DatabaseEntry data, DatabaseEntry foundKey, DatabaseEntry foundData, ReplicationContext repContext) throws DatabaseException
data
- DatabaseException
public OperationStatus getCurrent(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType) throws DatabaseException
DatabaseException
public OperationStatus getCurrentAlreadyLatched(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType, boolean first) throws DatabaseException
DatabaseException
public LN getCurrentLN(LockType lockType) throws DatabaseException
DatabaseException
public LN getCurrentLNAlreadyLatched(LockType lockType) throws DatabaseException
DatabaseException
public OperationStatus getNext(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType, boolean forward, boolean alreadyLatched) throws DatabaseException
DatabaseException
public CursorImpl.KeyChangeStatus getNextWithKeyChangeStatus(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType, boolean forward, boolean alreadyLatched) throws DatabaseException
foundKey
- DatabaseEntry to use for returning keyfoundData
- DatabaseEntry to use for returning dataforward
- if true, move forward, else move backwardsalreadyLatched
- if true, the bin that we're on is already
latched.DatabaseException
public OperationStatus getNextNoDup(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType, boolean forward, boolean alreadyLatched) throws DatabaseException
DatabaseException
public OperationStatus getFirstDuplicate(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType) throws DatabaseException
DatabaseException
public OperationStatus getNextDuplicate(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType, boolean forward, boolean alreadyLatched) throws DatabaseException
DatabaseException
public boolean positionFirstOrLast(boolean first, DIN duplicateRoot) throws DatabaseException
DatabaseException
public int searchAndPosition(DatabaseEntry matchKey, DatabaseEntry matchData, CursorImpl.SearchMode searchMode, LockType lockType) throws DatabaseException
Note this returns with the BIN latched!
If this method returns without the FOUND bit set, the caller can assume that no match is possible. Otherwise, if the FOUND bit is set, the caller should check the EXACT_KEY and EXACT_DATA bits. If EXACT_KEY is not set (or for BOTH and BOTH_RANGE, if EXACT_DATA is not set), an approximate match was found. In an approximate match, the cursor is always positioned before the target key/data. This allows the caller to perform a 'next' operation to advance to the value that is equal or higher than the target key/data.
Even if the search returns an exact result, the record may be deleted. The caller must therefore check for both an approximate match and for whether the cursor is positioned on a deleted record.
If SET or BOTH is specified, the FOUND bit will only be returned if an exact match is found. However, the record found may be deleted.
There is one special case where this method may be called without checking the EXACT_KEY (and EXACT_DATA) bits and without checking for a deleted record: If SearchMode.SET is specified then only the FOUND bit need be checked. When SET is specified and FOUND is returned, it is guaranteed to be an exact match on a non-deleted record. It is for this case only that this method is public.
If FOUND is set, FOUND_LAST may also be set if the cursor is positioned on the last record in the databaseImpl. Note that this state can only be counted on as long as the BIN is latched, so it is not set if this method must release the latch to lock the record. Therefore, it should only be used for optimizations. If FOUND_LAST is set, the cursor is positioned on the last record and the BIN is latched. If FOUND_LAST is not set, the cursor may or may not be positioned on the last record. Note that exact searches always perform an unlatch and a lock, so FOUND_LAST will only be set for inexact (range) searches.
Be aware that when an approximate match is returned, the index or dupIndex may be set to -1. This is done intentionally so that a 'next' operation will increment it.
DatabaseException
public LockResult lockLNDeletedAllowed(LN ln, LockType lockType) throws DatabaseException
ln
- the LN to be locked.lockType
- the type of lock requested.DatabaseException
public LockResult lockDupCountLN(DIN dupRoot, LockType lockType) throws DatabaseException
dupRoot
- the duplicate root containing the DupCountLN to be
locked.lockType
- the type of lock requested.DatabaseException
public DIN getLatchedDupRoot(boolean isDBINLatched) throws DatabaseException
isDBINLatched
- is true if the DBIN is currently latched.DatabaseException
public static void setDbt(DatabaseEntry data, byte[] bytes)
public void checkCursorState(boolean mustBeInitialized) throws DatabaseException
DatabaseException
public void lockEofNode(LockType lockType) throws DatabaseException
DatabaseException
public void checkEnv() throws RunRecoveryException
RunRecoveryException
- if the underlying environment is invalid.public CursorImpl getLockerPrev()
public CursorImpl getLockerNext()
public void setLockerPrev(CursorImpl p)
public void setLockerNext(CursorImpl n)
public static void traverseDbWithCursor(DatabaseImpl db, LockType lockType, boolean allowEviction, CursorImpl.WithCursor withCursor) throws DatabaseException
db
- DatabaseImpl to traverse.lockType
- non-null LockType for reading records.allowEviction
- should normally be true to evict when performing
multiple operations, but may be false if eviction is disallowed in a
particular context.withCursor
- callback object.DatabaseException
public void dump(boolean verbose)
public void dump()
public java.lang.String dumpToString(boolean verbose)
public LockStats getLockStats() throws DatabaseException
DatabaseException
public void setTestHook(TestHook hook)