+I#Berkeley DB: Dbc.get[P

Dbc.get





import com.sleepycat.db.*;

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





Description



CThe Dbc.get method retrieves key/data pairs from the database. The byte arrayIand length of the key are returned in the object referenced by keyF(except for the case of the DB_SET flag where the key object isunchanged), and theaddressLand length of the data are returned in the object referenced by data.

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

MIn Recno databases, missing entries (i.e., entries that were never explicitlyHcreated or that were created and then deleted), will be skipped during asequential scan.

IIf multiple threads or processes insert items into the same database file1without using locking, the results are undefined.For more detail,@see cursor stability.

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

]

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

6If the database is a Recno database, Dbc.get using the=Db.DB_FIRST flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

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

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

6If the database is a Recno database, Dbc.get using the<Db.DB_LAST flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

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

Db.DB_NEXT
If the cursor is not yet initialized, DB_NEXT is identical to DB_FIRST.

EOtherwise, move the cursor to the next key/data pair of the database,and that pair is returned.MIn the presence of duplicate key values, the value of the key may not change.

6If the database is a Recno database, Dbc.get using the<Db.DB_NEXT flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

DIf the cursor is already on the last record in the database, Dbc.getwill return DB_NOTFOUND.`

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

1If the cursor is not yet initialized, the Dbc.get4method throws an exception that encapsulates EINVAL.[

Db.DB_PREV
If the cursor is not yet initialized, DB_PREV is identical to DB_LAST.

IOtherwise, move the cursor to the previous key/data pair of the database,and that pair is returned.MIn the presence of duplicate key values, the value of the key may not change.

6If the database is a Recno database, Dbc.get using the<Db.DB_PREV flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

EIf the cursor is already on the first record in the database, Dbc.getwill return DB_NOTFOUND.T

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_KEYEMPTY.

1If the cursor is not yet initialized, the Dbc.get4method throws an exception that encapsulates EINVAL.S

Db.DB_SET
Move the cursor to the specified key/data pair of the database,3and 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.

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

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

Db.DB_SET_RANGE
The DB_SET_RANGE flag is identical to the DB_SET flag, except that theGkey is returned as well as the data item, and, in the case of the btreeJaccess 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.c

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

Db.DB_SET_RECNO
Move the cursor to the specific numbered record of the database,(and return the associated key/data pair.1The 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.

DFor DB_SET_RECNO to be specified, the underlying database must be oftype btree and it must have been created with the Db.DB_RECNUM flag.N

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

DFor DB_GET_RECNO to be specified, the underlying database must be oftype btree and it must have been created with the Db.DB_RECNUM flag.



RIn addition, the following value may be set by logically OR'ing it into theflags parameter:

T

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


Otherwise, the Dbc.getHmethod throws an exception that encapsulates an errno on failure.

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



Errors

OIf a fatal error occurs in Berkeley DB, the Dbc.get method may fail and throw a}DbRunRecoveryException, at which point all subsequent database%calls will also fail in the same way.

The Dbc.get&method may fail and throw an exceptionKfor any of the errors specified for the following Berkeley DB and C library functions:__account_page(3), abort(3),dbenv->db_paniccall(3),dbp->dup_compare(3), fflush(3), fprintf(3),free(3),func(3),hcp->dbc->dbp->h_hash(3),>DbLockTab.get,8DbLock.put,>DbLockTab.vec,6DbLog.put, malloc(3), memcmp(3), memcpy(3), memmove(3),dBDbMpoolFile.get,BDbMpoolFile.put,BDbMpoolFile.set, memset(3), realloc(3),h strerror(3), vfprintf(3),ande vsnprintf(3).

In addition, the Dbc.get&method may fail and throw an exceptionencapsulating errnofor the following conditions:e

t

(

EAGAIN
A lock was unavailable.
m

d

B

EINVAL
An invalid flag value or parameter was specified.

3The specified cursor was not currently initialized.a

rThe Db.DB_THREAD flag was specified to Db.open and neitherQthe Db.DB_DBT_MALLOC or Db.DB_DBT_USERMEM flags were set in the Dbt.r

e

t

Class

/Dbcd



See Also

k6Dbc.close,2Dbc.del,Dbc.getiand 2Dbc.put.
,h.ef/txn/stability.html">cursor stability.

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

]

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

6If the database is a Recno database, Dbc.get using the