12.3 The IBM DB2e FastRecordStoreIBM DB2e (v8.1) provides a FastRecordStore class over the MIDP standard RMS record store. FastRecordStore packs several database rows into one RMS record and supports indexes for fast lookup. This results in much improved performance over the linear RMS record store.To create a database table in a FastRecordStore, we have to first create the table in a DB2e backend database. Then, we synchronize the table to the MIDP device using IBM DB2e Sync. After the synchronization, a FastRecordStore with the same name as the backend table is created. We can now read or update data in the FastRecordStore via the TableMetaData class. All the changes we make on the MIDP client will be sent back to the backend table upon the next synchronization operation. For more information about database synchronization and the IBM Sync, please refer to Chapter 13, Section 13.3.2. NoteWe cannot start with record stores on the MIDP client first, as they will be deleted on the first synchronization.In the FastRecordStore, each table row is packed into a byte array. Developers are required to manipulate those raw arrays manually. All rows start with a dirty byte and are followed by data in each column according to the following rules.If the column is not nullable, the data for the column is present.If the column is nullable there is a 1-byte boolean null indicator. If the indicator is true, no data follows. Otherwise, the column data follows.To illustrate the above points, the SQL INSERT statement in Listing 12.3 can be interpreted as the Java code in Listing 12.4. Listing 12.3. SQL script for a sample table
Listing 12.4. Java code for the INSERT statement in Listing 12.3
The following code (Listing 12.5) demonstrates how to iterate through rows, delete a row, and read out data in a FastRecordStore. Listing 12.5. Browse the FastRecordStore
|