Dbt |
import com.sleepycat.db.*;public class Dbt extends Object { public Dbt(byte[] data); public Dbt(byte[] data, int off, int len);
public void set_data(byte[] data); public byte[] get_data();
public void set_offset(int off); public int get_offset();
public int get_size(); public void set_size(int size);
public int get_ulen(); public void set_ulen(int ulen);
public int get_dlen(); public void set_dlen(int dlen);
public int get_doff(); public void set_doff(int doff);
public int get_flags(); public void set_flags(int flags);
public void set_recno_key_data(int recno); public int get_recno_key_data(); }
This manual page describes the specific details of the Dbt class, used to encode keys and data items in a database.
Storage and retrieval for the Db access methods are based on key/data pairs. Both key and data items are represented by Dbt objects. Key and data byte strings may reference strings of zero length up to strings of essentially unlimited length. See Database limits for more information.
The Dbt class provides simple access to an underlying data structure, whose elements can be examined or changed using the set_ or get_ methods. The remainder of the manual page sometimes refers to these accesses using the underlying name, e.g., simply ulen instead of Dbt.get_ulen and Dbt.set_ulen. Dbt can be subclassed, providing a way to associate with it additional data, or references to other structures.
The constructors set all elements of the underlying structure to zero. The constructor with one argument has the effect of setting all elements to zero except for the specified data and size elements. The constructor with three arguments has has the additional effect of only using the portion of the array specified by the size and offset.
In the case where the flags structure element is 0, when being provided a key or data item by the application, the Berkeley DB package expects the data object to be set to a byte array of size bytes. When returning a key/data item to the application, the Berkeley DB package will store into the data object a byte array of size bytes. During a get operation, one of the Db.DB_DBT_MALLOC, Db.DB_DBT_REALLOC or Db.DB_DBT_USERMEM flags must be specified.
The elements of the structure underlying the Dbt class are defined as follows:
Note that applications can determine the length of a record by setting the ulen to 0 and checking the return value found in size. See the Db.DB_DBT_USERMEM flag for more information.
This element is accessed using Dbt.get_ulen and Dbt.set_ulen.
The flags value must be set by bitwise inclusively OR'ing together one or more of the following values.
If Db.DB_DBT_MALLOC is specified, Berkeley DB allocates a properly sized byte array to contain the data. This can be convenient if you know little about the nature of the data, specifically the size of data in the database. However, if your application makes repeated calls to retrieve keys or data, you may notice increased garbage collection due to this allocation. If you know the maximum size of data you are retrieving, you might decrease the memory burden and speed your application by allocating your own byte array and using Db.DB_DBT_USERMEM. Even if you don't know the maximum size, you can use this option and reallocate your array whenever your retrieval API call throws a DbMemoryException.
It is an error to specify more than one of Db.DB_DBT_MALLOC, Db.DB_DBT_REALLOC and Db.DB_DBT_USERMEM.
It is an error to specify more than one of Db.DB_DBT_MALLOC, Db.DB_DBT_REALLOC and Db.DB_DBT_USERMEM.
If Db.DB_DBT_USERMEM is specified, the data field of the Dbt must be set to an appropriately sized byte array.
It is an error to specify more than one of Db.DB_DBT_MALLOC, Db.DB_DBT_REALLOC and Db.DB_DBT_USERMEM.
If Db.DB_DBT_MALLOC or Db.DB_DBT_REALLOC is specified, Berkeley DB allocates a properly sized byte array to contain the data. This can be convenient if you know little about the nature of the data, specifically the size of data in the database. However, if your application makes repeated calls to retrieve keys or data, you may notice increased garbage collection due to this allocation. If you know the maximum size of data you are retrieving, you might decrease the memory burden and speed your application by allocating your own byte array and using Db.DB_DBT_USERMEM. Even if you don't know the maximum size, you can use this option and reallocate your array whenever your retrieval API call throws a DbMemoryException.
For example, if the data portion of a retrieved record was 100 bytes, and a partial retrieval was done using a Dbt having a dlen field of 20 and a doff field of 85, the get call would succeed, the data field would reference the last 15 bytes of the record, and the size field would be set to 15.
If the calling application is doing a put, the dlen bytes starting doff bytes from the beginning of the specified key's data record are replaced by the data specified by the data and size objects. If dlen is smaller than size, the record will grow, and if dlen is larger than size, the record will shrink. If the specified bytes do not exist, the record will be extended using nul bytes as necessary, and the put call will succeed.
It is an error to attempt a partial put using the Db.put method in a database that supports duplicate records. Partial puts in databases supporting duplicate records must be done using a Dbc method.
It is an error to attempt a partial put with differing dlen and size values in Queue or Recno databases with fixed-length records.
For example, if the data portion of a retrieved record was 100 bytes, and a partial put was done using a Dbt having a dlen field of 20, a doff field of 85, and a size field of 30, the resulting record would be 115 bytes in length, where the last 30 bytes would be those specified by the put call.
Although Java normally maintains proper alignment of byte arrays, the set_offset method can be used to specify unaligned addresses. Unaligned address accesses that are not supported by the underlying hardware may be reported as an exception, or may stop the running Java program.
In all cases for the Queue and Recno access methods, and when calling the Db.get and Dbc.get functions with the Db.DB_SET_RECNO flag specified, the data field of the key must be a four byte array, large enough to store an int. The Dbt.set_recno_key_data method can be used to set the value of the array. An int is a 32-bit type, (which limits the number of logical records in a Queue or Recno database, and the maximum logical record which may be directly retrieved from a Btree database, to 4,294,967,296). The size field of the key should be the size of that type, i.e., 4.
Logical record numbers are 1-based, not 0-based, i.e., the first record in the database is record number 1.