tokyocabinet
Class BDBCUR

java.lang.Object
  extended by tokyocabinet.BDBCUR

public class BDBCUR
extends java.lang.Object

Cursor is a mechanism to access each record of B+ tree database in ascending or descending order.


Field Summary
static int CPAFTER
          cursor put mode: after
static int CPBEFORE
          cursor put mode: before
static int CPCURRENT
          cursor put mode: current
 
Constructor Summary
BDBCUR(BDB bdb)
          Create a cursor object.
 
Method Summary
protected  void finalize()
          Release resources.
 boolean first()
          Move the cursor to the first record.
 boolean jump(byte[] key)
          Move the cursor to the front of records corresponding a key.
 boolean jump(java.lang.String key)
          Move the cursor to the front of records corresponding a key.
 byte[] key()
          Get the key of the record where the cursor is.
 java.lang.String key2()
          Get the key of the record where the cursor is.
 boolean last()
          Move the cursor to the last record.
 boolean next()
          Move the cursor to the next record.
 boolean out()
          Remove the record where the cursor is.
 boolean prev()
          Move the cursor to the previous record.
 boolean put(byte[] value, int cpmode)
          Insert a record around the cursor.
 boolean put(java.lang.String value, int cpmode)
          Insert a record around the cursor.
 byte[] val()
          Get the value of the record where the cursor is.
 java.lang.String val2()
          Get the value of the record where the cursor is.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CPAFTER

public static final int CPAFTER
cursor put mode: after

See Also:
Constant Field Values

CPBEFORE

public static final int CPBEFORE
cursor put mode: before

See Also:
Constant Field Values

CPCURRENT

public static final int CPCURRENT
cursor put mode: current

See Also:
Constant Field Values
Constructor Detail

BDBCUR

public BDBCUR(BDB bdb)
Create a cursor object.

Parameters:
bdb - the B+ tree database object.
Note:
The cursor is available only after initialization with the `first' or the `jump' methods and so on. Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor.
Method Detail

finalize

protected void finalize()
Release resources.

Overrides:
finalize in class java.lang.Object

first

public boolean first()
Move the cursor to the first record.

Returns:
If successful, it is true, else, it is false. False is returned if there is no record in the database.

jump

public boolean jump(byte[] key)
Move the cursor to the front of records corresponding a key.

Parameters:
key - the key.
Returns:
If successful, it is true, else, it is false. False is returned if there is no record corresponding the condition.
Note:
The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.

jump

public boolean jump(java.lang.String key)
Move the cursor to the front of records corresponding a key. The same as `open(key.getBytes())'.

See Also:
jump(byte[])

key

public byte[] key()
Get the key of the record where the cursor is.

Returns:
If successful, it is the key, else, it is `null'. 'null' is returned when the cursor is at invalid position.

key2

public java.lang.String key2()
Get the key of the record where the cursor is. The same as `new String(key(), "UTF-8")'.

See Also:
key()

last

public boolean last()
Move the cursor to the last record.

Returns:
If successful, it is true, else, it is false. False is returned if there is no record in the database.

next

public boolean next()
Move the cursor to the next record.

Returns:
If successful, it is true, else, it is false. False is returned if there is no next record.

out

public boolean out()
Remove the record where the cursor is.

Returns:
If successful, it is true, else, it is false. False is returned when the cursor is at invalid position.
Note:
After deletion, the cursor is moved to the next record if possible.

prev

public boolean prev()
Move the cursor to the previous record.

Returns:
If successful, it is true, else, it is false. False is returned if there is no previous record.

put

public boolean put(byte[] value,
                   int cpmode)
Insert a record around the cursor.

Parameters:
value - the value.
cpmode - detail adjustment: `BDBCUR.CPCURRENT', which means that the value of the current record is overwritten, `BDBCUR.CPBEFORE', which means that the new record is inserted before the current record, `BDBCUR.CPAFTER', which means that the new record is inserted after the current record.
Returns:
If successful, it is true, else, it is false. False is returned when the cursor is at invalid position.
Note:
After insertion, the cursor is moved to the inserted record.

put

public boolean put(java.lang.String value,
                   int cpmode)
Insert a record around the cursor. The same as `put(value.getBytes(), cpmode)'.

See Also:
put(byte[], int)

val

public byte[] val()
Get the value of the record where the cursor is.

Returns:
If successful, it is the value, else, it is `null'. 'null' is returned when the cursor is at invalid position.

val2

public java.lang.String val2()
Get the value of the record where the cursor is. The same as `new String(value(), "UTF-8")'.

See Also:
val()