Dbc.get

APIRef

import com.sleepycat.db.*;

public int get(Dbt key, Dbt data, int flags) throws DbException;

Description

The Dbc.get method retrieves key/data pairs from the database. The byte array and length of the key are returned in the object referenced by key (except for the case of the Db.DB_SET flag where the key object is unchanged), and the byte array and length of the data are returned in the object referenced by data.

Modifications to the database during a sequential scan will be reflected in the scan, i.e. records inserted behind a cursor will not be returned while records inserted in front of a cursor will be returned.

In Queue and Recno databases, missing entries (i.e., entries that were never explicitly created or that were created and then deleted), will be skipped during a sequential scan.

If multiple threads or processes insert items into the same database file without using locking, the results are undefined. For more detail, see Cursor stability.

The flags parameter must be set to one of the following values:

Db.DB_CURRENT
Return the key/data pair currently referenced by the cursor.

If the cursor key/data pair was deleted, Dbc.get will return Db.DB_KEYEMPTY.

If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates EINVAL.

Db.DB_FIRST, Db.DB_LAST
The cursor is set to reference the first (last) key/data pair of the database, and that pair is returned. In the presence of duplicate key values, the first (last) data item in the set of duplicates is returned.

If the database is a Queue or Recno database, Dbc.get using the Db.DB_FIRST (Db.DB_LAST) flags will ignore any keys that exist but were never explicitly created by the application or were created and later deleted.

If the database is empty, Dbc.get will return Db.DB_NOTFOUND.

Db.DB_GET_BOTH
The Db.DB_GET_BOTH flag is identical to the Db.DB_SET flag, except that both the key and the data arguments must be matched by the key and data item in the database.

Db.DB_GET_RECNO
Return the record number associated with the cursor. The record number will be returned in data as described in Dbt. The key parameter is ignored.

For Db.DB_GET_RECNO to be specified, the underlying database must be of type Btree and it must have been created with the Db.DB_RECNUM flag.

Db.DB_JOIN_ITEM
Do not use the data value found in all of the cursors as a lookup key for the primary database, but simply return it in the key parameter instead. The data parameter is left unchanged.

For Db.DB_JOIN_ITEM to be specified, the underlying cursor must have been returned from the Db.join method.

Db.DB_NEXT, Db.DB_PREV
If the cursor is not yet initialized, Db.DB_NEXT (Db.DB_PREV) is identical to Db.DB_FIRST (Db.DB_LAST). Otherwise, the cursor is moved to the next (previous) key/data pair of the database, and that pair is returned. In the presence of duplicate key values, the value of the key may not change.

If the database is a Queue or Recno database, Dbc.get using the Db.DB_NEXT (Db.DB_PREV) flag will skip any keys that exist but were never explicitly created by the application or were created and later deleted.

If the cursor is already on the last (first) record in the database, Dbc.get will return Db.DB_NOTFOUND.

Db.DB_NEXT_DUP
If the next key/data pair of the database is a duplicate record for the current key/data pair, the cursor is moved to the next key/data pair of the database, and that pair is returned. Otherwise, Dbc.get will return Db.DB_NOTFOUND.

If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates EINVAL.

Db.DB_NEXT_NODUP, Db.DB_PREV_NODUP
If the cursor is not yet initialized, Db.DB_NEXT_NODUP (Db.DB_PREV_NODUP) is identical to Db.DB_FIRST (Db.DB_LAST). Otherwise, the cursor is moved to the next (previous) non-duplicate key/data pair of the database, and that pair is returned.

If the database is a Queue or Recno database, Dbc.get using the Db.DB_NEXT_NODUP (Db.DB_PREV_NODUP) flags will ignore any keys that exist but were never explicitly created by the application or were created and later deleted.

If no non-duplicate key/data pairs occur after (before) the cursor position in the database, Dbc.get will return Db.DB_NOTFOUND.

Db.DB_SET
Move the cursor to the specified key/data pair of the database, and return the datum associated with the given key.

In the presence of duplicate key values, Dbc.get will return the first data item for the given key.

If the database is a Queue or Recno database and the requested key exists, but was never explicitly created by the application or was later deleted, Dbc.get will return Db.DB_KEYEMPTY.

If no matching keys are found, Dbc.get will return Db.DB_NOTFOUND.

Db.DB_SET_RANGE
The Db.DB_SET_RANGE flag is identical to the Db.DB_SET flag, except that the key is returned as well as the data item, and, in the case of the Btree access method, the returned key/data pair is the smallest key greater than or equal to the specified key (as determined by the comparison method), permitting partial key matches and range searches.

Db.DB_SET_RECNO
Move the cursor to the specific numbered record of the database, and return the associated key/data pair. The data field of the specified key must be a byte array containing a record number, as described in Dbt. This determines the record to be retrieved.

For Db.DB_SET_RECNO to be specified, the underlying database must be of type Btree and it must have been created with the Db.DB_RECNUM flag.

In addition, the following flag may be set by bitwise inclusively OR'ing it into the flags parameter:

Db.DB_RMW
Acquire write locks instead of read locks when doing the retrieval. Setting this flag may decrease the likelihood of deadlock during a read-modify-write cycle by immediately acquiring the write lock during the read part of the cycle so that another thread of control acquiring a read lock for the same item, in its own read-modify-write cycle, will not result in deadlock.

Otherwise, the Dbc.get method throws an exception that encapsulates a non-zero error value on failure.

If Dbc.get fails for any reason, the state of the cursor will be unchanged.

Errors

The Dbc.get method may fail and throw an exception encapsulating a non-zero error for the following conditions:

EINVAL
An invalid flag value or parameter was specified.

The specified cursor was not currently initialized.

If the operation was selected to resolve a deadlock, the Dbc.get method will fail and throw a DbDeadlockException exception.

If the requested item could not be returned due to insufficient memory, the Dbc.get method will fail and throw a DbMemoryException exception.

The Dbc.get method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the Dbc.get method may fail and throw a DbRunRecoveryException, in which case all subsequent Berkeley DB calls will fail in the same way.

Class

Dbc

See Also

Dbc.close, Dbc.count, Dbc.del, Dbc.dup, Dbc.get and Dbc.put.

APIRef

Copyright Sleepycat Software