com.sun.sgs.impl.service.data.store.db.bdb
Class BdbCursor

java.lang.Object
  extended by com.sun.sgs.impl.service.data.store.db.bdb.BdbCursor
All Implemented Interfaces:
DbCursor

public class BdbCursor
extends Object
implements DbCursor

Provides a cursor implementation using Berkeley DB.


Constructor Summary
BdbCursor(com.sleepycat.db.Database db, com.sleepycat.db.Transaction txn)
          Creates an instance of this class.
 
Method Summary
 void close()
          Closes this cursor, releasing any associated resources.
 boolean findFirst()
          Searches for the first key in the database.
 boolean findLast()
          Searches for the last key in the database.
 boolean findNext()
          Searches for the next key in the database.
 boolean findNext(byte[] key)
          Searches for the first key that is greater than or equal to the specified key.
 byte[] getKey()
          Returns the current key, or null if the cursor has no current key.
 byte[] getValue()
          Returns the current value, or null if the cursor has no current value.
 boolean putNoOverwrite(byte[] key, byte[] value)
          Uses the cursor to set the value associated with a key in the database, if the key does not already have an associated value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BdbCursor

BdbCursor(com.sleepycat.db.Database db,
          com.sleepycat.db.Transaction txn)
Creates an instance of this class.

Parameters:
db - the Berkeley DB database
txn - the Berkeley DB transaction
Throws:
TransactionAbortedException - if the transaction should be aborted due to timeout or conflict
DbDatabaseException - if an unexpected database problem occurs
Method Detail

getKey

public byte[] getKey()
Returns the current key, or null if the cursor has no current key.

Specified by:
getKey in interface DbCursor
Returns:
the current key or null

getValue

public byte[] getValue()
Returns the current value, or null if the cursor has no current value.

Specified by:
getValue in interface DbCursor
Returns:
the current value or null

findFirst

public boolean findFirst()
Searches for the first key in the database. If the result is true, then sets the current key and value to the first key and its associated value.

Specified by:
findFirst in interface DbCursor
Returns:
true if the first key was found, else false

findNext

public boolean findNext()
Searches for the next key in the database. If the cursor has no current key, then searches for the first key. If the result is true, then sets the current key and value to the key found and its associated value.

Specified by:
findNext in interface DbCursor
Returns:
true if the next key was found, else false

findNext

public boolean findNext(byte[] key)
Searches for the first key that is greater than or equal to the specified key. If the result is true, then sets the current key and value to the key found and its associated value.

Specified by:
findNext in interface DbCursor
Parameters:
key - the key at which to start searching
Returns:
true if the next key was found, else false

findLast

public boolean findLast()
Searches for the last key in the database. If the result is true, then sets the current key and value to the last key and its associated value.

Specified by:
findLast in interface DbCursor
Returns:
true if the last key was found, else false

putNoOverwrite

public boolean putNoOverwrite(byte[] key,
                              byte[] value)
Uses the cursor to set the value associated with a key in the database, if the key does not already have an associated value. If the result is true, then sets the current key and value to the newly inserted key and its associated value.

Specified by:
putNoOverwrite in interface DbCursor
Parameters:
key - the key
value - the value
Returns:
true if a value was stored for the key, and false if the key already had a value

close

public void close()
Closes this cursor, releasing any associated resources. This cursor should not be used after this method is called. This method should be called before preparing, committing, or aborting the associated transaction.

Note that the Berkeley DB documentation for prepare doesn't say you need to close cursors, but my testing shows that you do. -tjb@sun.com (12/14/2006)

Specified by:
close in interface DbCursor

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved