Berkeley DB
version 4.2.52

com.sleepycat.db
Class Dbc

java.lang.Object
  |
  +--com.sleepycat.db.Dbc

public class Dbc
extends Object

The Dbc object is the handle for a cursor into a Berkeley DB database. The handle is not free-threaded. Cursor handles may be used by multiple threads, but only serially, that is, the application must serialize access to the Dbc handle.

If the cursor is to be used to perform operations on behalf of a transaction, the cursor must be opened and closed within the context of that single transaction. Once Dbc.close has been called, the handle may not be accessed again, regardless of the method's return.


Method Summary
 void close()
          The Dbc.close method discards the cursor.
 int count(int flags)
          The Dbc.count method returns a count of the number of data items for the key to which the cursor refers.
 int del(int flags)
          Deprecated. As of Berkeley DB 4.2, replaced by delete(int)
 int delete(int flags)
          The Dbc.delete method deletes the key/data pair to which the cursor refers.
 Dbc dup(int flags)
          The Dbc.dup method creates a new cursor that uses the same transaction and locker ID as the original cursor.
 int get(Dbt key, Dbt pkey, Dbt data, int flags)
          The Dbc.get method retrieves key/data pairs from the database.
 int get(Dbt key, Dbt data, int flags)
          The Dbc.get method retrieves key/data pairs from the database.
 int pget(Dbt key, Dbt pkey, Dbt data, int flags)
          Deprecated. Replaced in Berkeley DB 4.2 by get(Dbt,Dbt,Dbt,int)
 int put(Dbt key, Dbt data, int flags)
          The Dbc.put method stores key/data pairs into the database.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

close

public void close()
           throws DbException
The Dbc.close method discards the cursor.

It is possible for the Dbc.close method to return Db.DB_LOCK_DEADLOCK, signaling that any enclosing transaction should be aborted. If the application is already intending to abort the transaction, this error should be ignored, and the application should proceed.

After Dbc.close has been called, regardless of its return, the cursor handle may not be used again.

Throws:
DbException
DbDeadlockException - If a transactional database environment operation was selected to resolve a deadlock, the Dbc.close method will fail and throw a DbDeadlockException exception.
DbLockNotGrantedException - If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time, the Dbc.close method will fail and throw a DbLockNotGrantedException exception.
IllegalArgumentException - The Dbc.close method will fail and throw a IllegalArgumentException exception if the cursor is already closed; or if an invalid flag value or parameter was specified.

pget

public int pget(Dbt key,
                Dbt pkey,
                Dbt data,
                int flags)
         throws DbException
Deprecated. Replaced in Berkeley DB 4.2 by get(Dbt,Dbt,Dbt,int)

DbException

count

public int count(int flags)
          throws DbException
The Dbc.count method returns a count of the number of data items for the key to which the cursor refers.

Parameters:
flags - currently unused, and must be set to 0.
Returns:
The Dbc.count method throws an exception that encapsulates a non-zero error value on failure.

Throws:
DbException - The Dbc.count method may fail and throw DbException, encapsulating one of the following non-zero errors:
IllegalArgumentException - The Dbc.count method will fail and throw a IllegalArgumentException exception if the cursor has not been initialized; or if an invalid flag value or parameter was specified.

del

public int del(int flags)
        throws DbException
Deprecated. As of Berkeley DB 4.2, replaced by delete(int)

DbException

delete

public int delete(int flags)
           throws DbException
The Dbc.delete method deletes the key/data pair to which the cursor refers.

When called on a cursor opened on a database that has been made into a secondary index using the Db.associate method, the Db.delete method deletes the key/data pair from the primary database and all secondary indices.

The cursor position is unchanged after a delete, and subsequent calls to cursor functions expecting the cursor to refer to an existing key will fail.

Parameters:
flags - currently unused, and must be set to 0.
Returns:
Unless otherwise specified, the Dbc.delete method throws an exception that encapsulates a non-zero error value on failure.

Throws:
DbException - The Dbc.delete method may fail and throw DbException, encapsulating one of the following non-zero errors: An attempt was made to modify a read-only database.
  • Write attempted on read-only cursor when the Db.DB_INIT_CDB flag was specified to DbEnv.open.
    DbDeadlockException - If a transactional database environment operation was selected to resolve a deadlock, the Dbc.delete method will fail and throw a DbDeadlockException exception.
    DbLockNotGrantedException - If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time, the Dbc.delete method will fail and throw a DbLockNotGrantedException exception.
    IllegalArgumentException - The Dbc.delete method will fail and throw a IllegalArgumentException exception if the cursor has not been initialized; or if an invalid flag value or parameter was specified.

  • dup

    public Dbc dup(int flags)
            throws DbException
    The Dbc.dup method creates a new cursor that uses the same transaction and locker ID as the original cursor. This is useful when an application is using locking and requires two or more cursors in the same thread of control.

    Parameters:
    flags - must be set to 0 or by bitwise inclusively OR'ing together one or more of the following values:
    • Db.DB_POSITION

      The newly created cursor is initialized to refer to the same position in the database as the original cursor and hold the same locks. If the Db.DB_POSITION flag is not specified, then the created cursor is uninitialized and will behave like a cursor newly created using Db.cursor.

    Returns:
    The Dbc.dup method throws an exception that encapsulates a non-zero error value on failure.

    Throws:
    DbException - The Dbc.dup method may fail and throw DbException, encapsulating one of the following non-zero errors:
    IllegalArgumentException - The Dbc.dup method will fail and throw a IllegalArgumentException exception if the cursor has not been initialized; or if an invalid flag value or parameter was specified.

    get

    public int get(Dbt key,
                   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.get methods return the key from the secondary index and the data item from the primary database. In addition, the second method signature returns the key from the primary database. In databases that are not secondary indices, the second method signature will always fail.

    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.

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

    Parameters:
    data - The data Dbt operated on.
    flags - must be set to one of the following values:
    • Db.DB_CURRENT

      Return the key/data pair to which the cursor refers.

    • Db.DB_FIRST

      The cursor is set to refer to the first key/data pair of the database, and that pair is returned. If the first key has duplicate values, the first 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 flag will ignore any keys that exist but were never explicitly created by the application, or were created and later deleted.

    • 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 parameters must be matched by the key and data item in the database.

      When used with the second method signature version of this method 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 first method signature version of this method and a cursor that has been opened on a secondary index handle.

    • Db.DB_GET_BOTH_RANGE

      The Db.DB_GET_BOTH_RANGE flag is identical to the Db.DB_GET_BOTH flag, except that, in the case of any database supporting sorted duplicate sets, the returned key/data pair is the smallest data item greater than or equal to the specified data item (as determined by the comparison function), permitting partial matches and range searches in duplicate data sets.

    • Db.DB_GET_RECNO

      Return the record number associated with the cursor. The record number will be returned in data, as described in Dbt. 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.

      When called on a cursor opened on a database that has been made into a secondary index, the Dbc.get method returns the record number of the primary database in data. In addition, the second method signature returns the record number of the secondary index in pkey. If either underlying database is not of type Btree or is not created with the Db.DB_RECNUM flag, the out-of-band record number of 0 is returned.

    • 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_LAST

      The cursor is set to refer to the last key/data pair of the database, and that pair is returned. If the last key has duplicate values, the 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_LAST flag will ignore any keys that exist but were never explicitly created by the application, or were created and later deleted.

    • Db.DB_NEXT

      If the cursor is not yet initialized, Db.DB_NEXT is identical to Db.DB_FIRST. Otherwise, the cursor is moved to the next 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 flag will skip any keys that exist but were never explicitly created by the application, or those that were created and later deleted.

    • Db.DB_NEXT_DUP

      If the next key/data pair of the database is a duplicate data 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.

    • Db.DB_NEXT_NODUP

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

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

    • Db.DB_PREV

      If the cursor is not yet initialized, Db.DB_PREV is identical to Db.DB_LAST. Otherwise, the cursor is moved to the 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_PREV flag will skip any keys that exist but were never explicitly created by the application, or those that were created and later deleted.

    • Db.DB_PREV_NODUP

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

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

    • Db.DB_SET

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

    • Db.DB_SET_RANGE

      The Db.DB_SET_RANGE flag is identical to the Db.DB_SET flag, except that in the case of the Btree access method, the key is returned as well as the data item and the returned key/data pair is the smallest key greater than or equal to the specified key (as determined by the Btree comparison function), 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 flags may be set by bitwise inclusively OR'ing them into the flags parameter:
    • Db.DB_DIRTY_READ

      Read modified but not yet committed data. Silently ignored if the Db.DB_DIRTY_READ flag was not specified when the underlying database was opened.

    • Db.DB_MULTIPLE

      Return multiple data items in the data parameter.

      In the case of Btree or Hash databases, duplicate data items for the current key, starting at the current cursor position, are entered into the buffer. Subsequent calls with both the Db.DB_NEXT_DUP and Db.DB_MULTIPLE flags specified will return additional duplicate data items associated with the current key or Db.DB_NOTFOUND if there are no additional duplicate data items to return. Subsequent calls with both the Db.DB_NEXT and Db.DB_MULTIPLE flags specified will return additional duplicate data items associated with the current key or if there are no additional duplicate data items will return the next key and its data items or Db.DB_NOTFOUND if there are no additional keys in the database.

      In the case of Queue or Recno databases, data items starting at the current cursor position are entered into the buffer. The record number of the first record will be returned in the key parameter. The record number of each subsequent returned record must be calculated from this value. Subsequent calls with the Db.DB_MULTIPLE flag specified will return additional data items or Db.DB_NOTFOUND if there are no additional data items to return.

      The buffer to which the data parameter refers must be provided from user memory (see Db.DB_DBT_USERMEM). The buffer must be at least as large as the page size of the underlying database, aligned for unsigned integer access, and be a multiple of 1024 bytes in size. If the buffer size is insufficient, then upon return from the call the size field of the data parameter will have been set to an estimated buffer size, and a DbMemoryException is thrown. (The size is an estimate as the exact size needed may not be known until all entries are read. It is best to initially provide a relatively large buffer, but applications should be prepared to resize the buffer as necessary and repeatedly call the method.)

      The multiple data items can be iterated over using the DbMultipleDataIterator class.

      The Db.DB_MULTIPLE flag may only be used with the Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH, Db.DB_GET_BOTH_RANGE, 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.

    • Db.DB_MULTIPLE_KEY

      Return multiple key and data pairs in the data parameter.

      Key and data pairs, starting at the current cursor position, are entered into the buffer. Subsequent calls with both the Db.DB_NEXT and Db.DB_MULTIPLE flags specified will return additional key and data pairs or Db.DB_NOTFOUND if there are no additional key and data items to return.

      In the case of Btree or Hash databases, the multiple key and data pairs can be iterated over using the DbMultipleKeyDataIterator class.

      In the case of Queue or Recno databases, the multiple record number and data pairs can be iterated over using the DbMultipleRecnoDataIterator class.

      The buffer to which the data parameter refers must be provided from user memory (see Db.DB_DBT_USERMEM). The buffer must be at least as large as the page size of the underlying database, aligned for unsigned integer access, and be a multiple of 1024 bytes in size. If the buffer size is insufficient, then upon return from the call the size field of the data parameter will have been set to an estimated buffer size, and a DbMemoryException is thrown. (The size is an estimate as the exact size needed may not be known until all entries are read. It is best to initially provide a relatively large buffer, but applications should be prepared to resize the buffer as necessary and repeatedly call the method.)

      The Db.DB_MULTIPLE_KEY flag may only be used with the Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH, Db.DB_GET_BOTH_RANGE, 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_KEY flag may not be used when accessing databases made into secondary indices using the Db.associate method.

    • Db.DB_RMW

      Acquire write locks instead of read locks when doing the retrieval. Setting this flag can eliminate deadlock during a read-modify-write cycle by 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.

    key - The key Dbt operated on.
    Returns:
    Unless otherwise specified, the Dbc.get method throws an exception that encapsulates a non-zero error value on failure.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_NEXT is set and the cursor is already on the last record in the database.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_NEXT_DUP is set and the next key/data pair of the database is not a duplicate data record for the current key/data pair.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_NEXT_NODUP is set and no non-duplicate key/data pairs occur after the cursor position in the database.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_PREV is set and the cursor is already on the first record in the database.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_PREV_NODUP is set and no non-duplicate key/data pairs occur before the cursor position in the database.

    • DB_KEYEMPTY

      The Dbc.get method will return Db.DB_KEYEMPTY if Db.DB_SET is set and 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.

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

    Throws:
    DbException - The Dbc.get method may fail and throw DbException, encapsulating one of the following non-zero errors:
    DbDeadlockException - If a transactional database environment operation was selected to resolve a deadlock, the Dbc.get method will fail and throw a DbDeadlockException exception.
    DbLockNotGrantedException - If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time, the Dbc.get method will fail and throw a DbLockNotGrantedException exception.
    IllegalArgumentException - The Dbc.get method will fail and throw a IllegalArgumentException exception if the Db.DB_CURRENT or Db.DB_NEXT_DUP flags were specified and the cursor has not been initialized; the second method signature was called with a cursor that does not refer to a secondary index; or if an invalid flag value or parameter was specified.
    DbMemoryException - If the requested item could not be returned due to insufficient memory, the Dbc.get method will fail and throw a DbMemoryException exception.

    get

    public int get(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.get methods return the key from the secondary index and the data item from the primary database. In addition, the second method signature returns the key from the primary database. In databases that are not secondary indices, the second method signature will always fail.

    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.

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

    Parameters:
    data - The data Dbt operated on.
    flags - must be set to one of the following values:
    • Db.DB_CURRENT

      Return the key/data pair to which the cursor refers.

    • Db.DB_FIRST

      The cursor is set to refer to the first key/data pair of the database, and that pair is returned. If the first key has duplicate values, the first 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 flag will ignore any keys that exist but were never explicitly created by the application, or were created and later deleted.

    • 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 parameters must be matched by the key and data item in the database.

      When used with the second method signature version of this method 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 first method signature version of this method and a cursor that has been opened on a secondary index handle.

    • Db.DB_GET_BOTH_RANGE

      The Db.DB_GET_BOTH_RANGE flag is identical to the Db.DB_GET_BOTH flag, except that, in the case of any database supporting sorted duplicate sets, the returned key/data pair is the smallest data item greater than or equal to the specified data item (as determined by the comparison function), permitting partial matches and range searches in duplicate data sets.

    • Db.DB_GET_RECNO

      Return the record number associated with the cursor. The record number will be returned in data, as described in Dbt. 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.

      When called on a cursor opened on a database that has been made into a secondary index, the Dbc.get method returns the record number of the primary database in data. In addition, the second method signature returns the record number of the secondary index in pkey. If either underlying database is not of type Btree or is not created with the Db.DB_RECNUM flag, the out-of-band record number of 0 is returned.

    • 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_LAST

      The cursor is set to refer to the last key/data pair of the database, and that pair is returned. If the last key has duplicate values, the 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_LAST flag will ignore any keys that exist but were never explicitly created by the application, or were created and later deleted.

    • Db.DB_NEXT

      If the cursor is not yet initialized, Db.DB_NEXT is identical to Db.DB_FIRST. Otherwise, the cursor is moved to the next 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 flag will skip any keys that exist but were never explicitly created by the application, or those that were created and later deleted.

    • Db.DB_NEXT_DUP

      If the next key/data pair of the database is a duplicate data 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.

    • Db.DB_NEXT_NODUP

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

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

    • Db.DB_PREV

      If the cursor is not yet initialized, Db.DB_PREV is identical to Db.DB_LAST. Otherwise, the cursor is moved to the 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_PREV flag will skip any keys that exist but were never explicitly created by the application, or those that were created and later deleted.

    • Db.DB_PREV_NODUP

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

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

    • Db.DB_SET

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

    • Db.DB_SET_RANGE

      The Db.DB_SET_RANGE flag is identical to the Db.DB_SET flag, except that in the case of the Btree access method, the key is returned as well as the data item and the returned key/data pair is the smallest key greater than or equal to the specified key (as determined by the Btree comparison function), 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 flags may be set by bitwise inclusively OR'ing them into the flags parameter:
    • Db.DB_DIRTY_READ

      Read modified but not yet committed data. Silently ignored if the Db.DB_DIRTY_READ flag was not specified when the underlying database was opened.

    • Db.DB_MULTIPLE

      Return multiple data items in the data parameter.

      In the case of Btree or Hash databases, duplicate data items for the current key, starting at the current cursor position, are entered into the buffer. Subsequent calls with both the Db.DB_NEXT_DUP and Db.DB_MULTIPLE flags specified will return additional duplicate data items associated with the current key or Db.DB_NOTFOUND if there are no additional duplicate data items to return. Subsequent calls with both the Db.DB_NEXT and Db.DB_MULTIPLE flags specified will return additional duplicate data items associated with the current key or if there are no additional duplicate data items will return the next key and its data items or Db.DB_NOTFOUND if there are no additional keys in the database.

      In the case of Queue or Recno databases, data items starting at the current cursor position are entered into the buffer. The record number of the first record will be returned in the key parameter. The record number of each subsequent returned record must be calculated from this value. Subsequent calls with the Db.DB_MULTIPLE flag specified will return additional data items or Db.DB_NOTFOUND if there are no additional data items to return.

      The buffer to which the data parameter refers must be provided from user memory (see Db.DB_DBT_USERMEM). The buffer must be at least as large as the page size of the underlying database, aligned for unsigned integer access, and be a multiple of 1024 bytes in size. If the buffer size is insufficient, then upon return from the call the size field of the data parameter will have been set to an estimated buffer size, and a DbMemoryException is thrown. (The size is an estimate as the exact size needed may not be known until all entries are read. It is best to initially provide a relatively large buffer, but applications should be prepared to resize the buffer as necessary and repeatedly call the method.)

      The multiple data items can be iterated over using the DbMultipleDataIterator class.

      The Db.DB_MULTIPLE flag may only be used with the Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH, Db.DB_GET_BOTH_RANGE, 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.

    • Db.DB_MULTIPLE_KEY

      Return multiple key and data pairs in the data parameter.

      Key and data pairs, starting at the current cursor position, are entered into the buffer. Subsequent calls with both the Db.DB_NEXT and Db.DB_MULTIPLE flags specified will return additional key and data pairs or Db.DB_NOTFOUND if there are no additional key and data items to return.

      In the case of Btree or Hash databases, the multiple key and data pairs can be iterated over using the DbMultipleKeyDataIterator class.

      In the case of Queue or Recno databases, the multiple record number and data pairs can be iterated over using the DbMultipleRecnoDataIterator class.

      The buffer to which the data parameter refers must be provided from user memory (see Db.DB_DBT_USERMEM). The buffer must be at least as large as the page size of the underlying database, aligned for unsigned integer access, and be a multiple of 1024 bytes in size. If the buffer size is insufficient, then upon return from the call the size field of the data parameter will have been set to an estimated buffer size, and a DbMemoryException is thrown. (The size is an estimate as the exact size needed may not be known until all entries are read. It is best to initially provide a relatively large buffer, but applications should be prepared to resize the buffer as necessary and repeatedly call the method.)

      The Db.DB_MULTIPLE_KEY flag may only be used with the Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH, Db.DB_GET_BOTH_RANGE, 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_KEY flag may not be used when accessing databases made into secondary indices using the Db.associate method.

    • Db.DB_RMW

      Acquire write locks instead of read locks when doing the retrieval. Setting this flag can eliminate deadlock during a read-modify-write cycle by 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.

    key - The key Dbt operated on.
    pkey - The secondary index key Dbt operated on.
    Returns:
    Unless otherwise specified, the Dbc.get method throws an exception that encapsulates a non-zero error value on failure.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_NEXT is set and the cursor is already on the last record in the database.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_NEXT_DUP is set and the next key/data pair of the database is not a duplicate data record for the current key/data pair.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_NEXT_NODUP is set and no non-duplicate key/data pairs occur after the cursor position in the database.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_PREV is set and the cursor is already on the first record in the database.

    • DB_NOTFOUND

      The Dbc.get method will return Db.DB_NOTFOUND if Db.DB_PREV_NODUP is set and no non-duplicate key/data pairs occur before the cursor position in the database.

    • DB_KEYEMPTY

      The Dbc.get method will return Db.DB_KEYEMPTY if Db.DB_SET is set and 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.

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

    Throws:
    DbException - The Dbc.get method may fail and throw DbException, encapsulating one of the following non-zero errors:
    DbDeadlockException - If a transactional database environment operation was selected to resolve a deadlock, the Dbc.get method will fail and throw a DbDeadlockException exception.
    DbLockNotGrantedException - If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time, the Dbc.get method will fail and throw a DbLockNotGrantedException exception.
    IllegalArgumentException - The Dbc.get method will fail and throw a IllegalArgumentException exception if the Db.DB_CURRENT or Db.DB_NEXT_DUP flags were specified and the cursor has not been initialized; the second method signature was called with a cursor that does not refer to a secondary index; or if an invalid flag value or parameter was specified.
    DbMemoryException - If the requested item could not be returned due to insufficient memory, the Dbc.get method will fail and throw a DbMemoryException exception.

    put

    public int put(Dbt key,
                   Dbt data,
                   int flags)
            throws DbException
    The Dbc.put method stores key/data pairs into the database.

    If Dbc.put fails for any reason, the state of the cursor will be unchanged. If Dbc.put succeeds and an item is inserted into the database, the cursor is always positioned to refer to the newly inserted item.

    Parameters:
    data - The data Dbt operated on.
    flags - must be set to one of the following values:
    • Db.DB_AFTER

      In the case of the Btree and Hash access methods, insert the data element as a duplicate element of the key to which the cursor refers. The new element appears immediately after the current cursor position. It is an error to specify Db.DB_AFTER if the underlying Btree or Hash database does not support duplicate data items. ignored.

      In the case of the Recno access method, it is an error to specify Db.DB_AFTER if the underlying Recno database was not created with the Db.DB_RENUMBER flag. If the Db.DB_RENUMBER flag was specified, a new key is created, all records after the inserted item are automatically renumbered, and the key of the new record is returned in the structure to which the key parameter refers. The initial value of the key parameter is ignored. See Db.open for more information.

      The Db.DB_AFTER flag may not be specified to the Queue access method.

    • Db.DB_BEFORE

      In the case of the Btree and Hash access methods, insert the data element as a duplicate element of the key to which the cursor refers. The new element appears immediately before the current cursor position. It is an error to specify Db.DB_BEFORE if the underlying Btree or Hash database does not support duplicate data items. ignored.

      In the case of the Recno access method, it is an error to specify Db.DB_BEFORE if the underlying Recno database was not created with the Db.DB_RENUMBER flag. If the Db.DB_RENUMBER flag was specified, a new key is created, the current record and all records after it are automatically renumbered, and the key of the new record is returned in the structure to which the key parameter refers. The initial value of the key parameter is ignored. See Db.open for more information.

      The Db.DB_BEFORE flag may not be specified to the Queue access method.

    • Db.DB_CURRENT

      Overwrite the data of the key/data pair to which the cursor refers with the specified data item. ignored.

    • Db.DB_KEYFIRST

      In the case of the Btree and Hash access methods, insert the specified key/data pair into the database.

      If the underlying database supports duplicate data items, and if the key already exists in the database and a duplicate sort function has been specified, the inserted data item is added in its sorted location. If the key already exists in the database and no duplicate sort function has been specified, the inserted data item is added as the first of the data items for that key.

      The Db.DB_KEYFIRST flag may not be specified to the Queue or Recno access methods.

    • Db.DB_KEYLAST

      In the case of the Btree and Hash access methods, insert the specified key/data pair into the database.

      If the underlying database supports duplicate data items, and if the key already exists in the database and a duplicate sort function has been specified, the inserted data item is added in its sorted location. If the key already exists in the database, and no duplicate sort function has been specified, the inserted data item is added as the last of the data items for that key.

      The Db.DB_KEYLAST flag may not be specified to the Queue or Recno access methods.

    • Db.DB_NODUPDATA

      In the case of the Btree and Hash access methods, insert the specified key/data pair into the database, unless a key/data pair comparing equally to it already exists in the database. If a matching key/data pair already exists in the database, Db.DB_KEYEXIST is returned. The Db.DB_NODUPDATA flag may only be specified if the underlying database has been configured to support sorted duplicate data items.

      The Db.DB_NODUPDATA flag may not be specified to the Queue or Recno access methods.

    key - The key Dbt operated on.
    Returns:
    Unless otherwise specified, the Dbc.put method throws an exception that encapsulates a non-zero error value on failure.

    • DB_NOTFOUND

      The Dbc.put method will return Db.DB_NOTFOUND if the current cursor record has already been deleted and the underlying access method is Hash.

    • DB_NOTFOUND

      The Dbc.put method will return Db.DB_NOTFOUND if the current cursor record has already been deleted and the underlying access method is Hash.

    • DB_NOTFOUND

      The Dbc.put method will return Db.DB_NOTFOUND if the current cursor record has already been deleted and the underlying access method is Hash.

    Throws:
    DbException - The Dbc.put method may fail and throw DbException, encapsulating one of the following non-zero errors:
  • An attempt was made to modify a read-only database. Write attempted on read-only cursor when the Db.DB_INIT_CDB flag was specified to DbEnv.open.
    DbDeadlockException - If a transactional database environment operation was selected to resolve a deadlock, the Dbc.put method will fail and throw a DbDeadlockException exception.
    DbLockNotGrantedException - If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time, the Dbc.put method will fail and throw a DbLockNotGrantedException exception.
    IllegalArgumentException - The Dbc.put method will fail and throw a IllegalArgumentException exception if the Db.DB_AFTER, Db.DB_BEFORE or Db.DB_CURRENT flags were specified and the cursor has not been initialized; the Db.DB_AFTER or Db.DB_BEFORE flags were specified and a duplicate sort function has been specified; the Db.DB_CURRENT flag was specified, a duplicate sort function has been specified, and the data item of the referenced key/data pair does not compare equally to the data parameter; the Db.DB_AFTER or Db.DB_BEFORE flags were specified, and the underlying access method is Queue; an attempt was made to add a record to a fixed-length database that was too large to fit; an attempt was made to add a record to a secondary index; or if an invalid flag value or parameter was specified.

  • Berkeley DB
    version 4.2.52

    Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.