Dbc.get |
import com.sleepycat.db.*;public int get(Dbt key, Dbt data, int flags) throws DbException; public int pget(Dbt key, Dbt pkey, Dbt data, int flags) throws DbException;
The Dbc.get method retrieves key/data pairs from the database. The byte array and length of the key are returned in the object to which key refers (except for the case of the Db.DB_SET flag, in which the key object is unchanged), and the byte array and length of the data are returned in the object to which data refers.
When called on a cursor opened on a database that has been made into a secondary index using the Db.associate method, the Dbc.get and Dbc.pget methods return the key from the secondary index and the data item from the primary database. In addition, the Dbc.pget method returns the key from the primary database. In databases that are not secondary indices, the Dbc.pget interface will always fail and return EINVAL.
Modifications to the database during a sequential scan will be reflected in the scan; that is, 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 (that is, entries that were never explicitly created or that were created and then deleted) will be skipped during a sequential scan.
The flags value must be set to one of the following values:
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.
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.
When used with the Dbc.pget version of this interface on a secondary index handle, both the secondary and primary keys must be matched by the secondary and primary key item in the database. It is an error to use the Db.DB_GET_BOTH flag with the Dbc.get version of this interface and a cursor that has been opened on a secondary index handle.
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.
For Db.DB_JOIN_ITEM to be specified, the underlying cursor must have been returned from the Db.join method.
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 those that 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.
If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates EINVAL.
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 those that 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.
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 specified 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.
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 flags may be set by bitwise inclusively OR'ing them into the flags parameter:
If Db.DB_MULTIPLE is specified for the Queue and Recno access methods, the buffer will be filled with as many data records as possible. The record number of the first record will be returned in the key argument. The record number of each subsequent returned record must be calculated from this value.
The buffer to which the data argument refers should be large relative to the page size of the underlying database, aligned for unsigned integer access, and be a multiple of 1024 bytes in size.
The Db.DB_MULTIPLE flag may only be used with the Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH, Db.DB_NEXT, Db.DB_NEXT_DUP, Db.DB_NEXT_NODUP, Db.DB_SET, Db.DB_SET_RANGE, and Db.DB_SET_RECNO options.
The Db.DB_MULTIPLE flag may not be used when accessing databases made into secondary indices using the Db.associate method.
See DbMultipleDataIterator for more information.
The buffer to which the data argument refers should be large relative to the page size of the underlying database, aligned for unsigned integer access, and be a multiple of 1024 bytes in size.
The Db.DB_MULTIPLE_KEY flag may only be used with the Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH, Db.DB_NEXT, Db.DB_NEXT_NODUP, Db.DB_SET, Db.DB_SET_RANGE, and Db.DB_SET_RECNO options. The Db.DB_MULTIPLE_KEY flag may not be used when accessing databases made into secondary indices using the Db.associate method.
See DbMultipleKeyDataIterator for more information.
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.
The Dbc.get method may fail and throw an exception encapsulating a non-zero error for the following conditions:
The specified cursor was not currently initialized.
The Dbc.pget interface was called with a cursor that does not refer to a secondary index.
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.