com.ibm.mobileservices.isync.midp
Class FastRecordStore

java.lang.Object
  |
  +--com.ibm.mobileservices.isync.midp.FastRecordStore

public class FastRecordStore
extends java.lang.Object

A class that builds on top of the basic RecordStore class to provide performance improvements for writes (by providing a write buffer) as well as update, delete and find by primary key methods.

See Also:
FastRecordEnumeration, Index, IndexException

Method Summary
 void closeRecordStore()
          Writes out meta data to the first row of the RMS table before it closes itself down.
static void deleteRecordStore(java.lang.String recordStoreName)
          Deletes the RecordStore
 com.ibm.mobileservices.isync.midp.FastRecordEnumeration enumerateRecords(javax.microedition.rms.RecordFilter filter, javax.microedition.rms.RecordComparator comparator, boolean keepUpdated)
          Return a new enumeration over the current FastRecordStore instance.
 long getLastModified()
          Return the time the record store was last modified
 java.lang.String getName()
          Get the name of this record store
 short getNextRecordID()
          Return the next available record ID, if one is inserted.
 int getNumRecords()
          Get the number of records in this store
 byte[] getRecord(int recordId)
           Returns a copy of the data stored in targetRecord, creating a new byte array each time.
 int getRecord(int targetRecord, byte[] buffer, int offset)
           Returns a row from the record store.
 int getRecordSize(int recordId)
           Returns the size (in bytes) of a record, used by the MIDLet to ensure that a byte[] is large enough to hold the row when using getRecord(int, byte[], int).
 int getSizeAvailable()
          Get the number of bytes available for this record store to grow.
static com.ibm.mobileservices.isync.midp.FastRecordStore openRecordStore(java.lang.String recordStoreName, boolean createIfNecessary)
          Returns an instance of FastRecordStore.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNextRecordID

public short getNextRecordID()
Return the next available record ID, if one is inserted.

Returns:
next available unused id.

getRecordSize

public int getRecordSize(int recordId)
                  throws javax.microedition.rms.RecordStoreNotOpenException,
                         javax.microedition.rms.InvalidRecordIDException,
                         javax.microedition.rms.RecordStoreException,
                         java.io.IOException

Returns the size (in bytes) of a record, used by the MIDLet to ensure that a byte[] is large enough to hold the row when using getRecord(int, byte[], int).

Parameters:
recordId - The record whose size we want
Returns:
the size of the record
Throws:
javax.microedition.rms.InvalidRecordIDException - if there are no more records to return
javax.microedition.rms.RecordStoreNotOpenException - if the record store is not open.
javax.microedition.rms.RecordStoreException - general exception
java.io.IOException - internal error processing row

getRecord

public byte[] getRecord(int recordId)
                 throws javax.microedition.rms.RecordStoreNotOpenException,
                        javax.microedition.rms.InvalidRecordIDException,
                        javax.microedition.rms.RecordStoreException,
                        java.io.IOException

Returns a copy of the data stored in targetRecord, creating a new byte array each time. More efficient to use getRecord( int, byte[], int) and reuse the byte array.

Parameters:
recordId - the record of interest
Returns:
A byte array containing the row data.
Throws:
javax.microedition.rms.InvalidRecordIDException - if there are no more records to return
javax.microedition.rms.RecordStoreNotOpenException - if the record store is not open.
javax.microedition.rms.RecordStoreException - general exception
java.io.IOException - internal error reading row data

getRecord

public int getRecord(int targetRecord,
                     byte[] buffer,
                     int offset)
              throws javax.microedition.rms.RecordStoreNotOpenException,
                     javax.microedition.rms.InvalidRecordIDException,
                     javax.microedition.rms.RecordStoreException

Returns a row from the record store.

Parameters:
targetRecord - Record of interest.
buffer - In which to put the bytes, must be large enough
offset - ignored
Returns:
The record size of the record read
Throws:
javax.microedition.rms.InvalidRecordIDException - if there are no more records to return
javax.microedition.rms.RecordStoreNotOpenException - if the record store is not open.
javax.microedition.rms.RecordStoreException - general exception

openRecordStore

public static com.ibm.mobileservices.isync.midp.FastRecordStore openRecordStore(java.lang.String recordStoreName,
                                                                                boolean createIfNecessary)
                                                                         throws javax.microedition.rms.RecordStoreException,
                                                                                javax.microedition.rms.RecordStoreFullException,
                                                                                javax.microedition.rms.RecordStoreNotFoundException,
                                                                                java.lang.Exception
Returns an instance of FastRecordStore. Usage the same as for RecordStore.openRecordStore(...);

Returns:
FastRecordStore instance.
Throws:
javax.microedition.rms.InvalidRecordIDException - if there are no more records to return
javax.microedition.rms.RecordStoreFullException - no more space to create a new record store.
javax.microedition.rms.RecordStoreNotFoundException - if createIfNecessary is false, and the record store is not found.
javax.microedition.rms.RecordStoreException - general exception
java.lang.Exception - internal error

deleteRecordStore

public static void deleteRecordStore(java.lang.String recordStoreName)
                              throws javax.microedition.rms.RecordStoreException,
                                     javax.microedition.rms.RecordStoreNotFoundException
Deletes the RecordStore

Parameters:
recordStoreName - The name of the record store to delete.
Throws:
javax.microedition.rms.RecordStoreNotFoundException - if the record store is not open.
javax.microedition.rms.RecordStoreException - general exception
See Also:
Index.delete(String)

getLastModified

public long getLastModified()
                     throws javax.microedition.rms.RecordStoreNotOpenException
Return the time the record store was last modified

Returns:
time in millis.
Throws:
javax.microedition.rms.RecordStoreNotOpenException - if the record store is not open.

closeRecordStore

public void closeRecordStore()
                      throws javax.microedition.rms.RecordStoreException,
                             javax.microedition.rms.RecordStoreNotOpenException
Writes out meta data to the first row of the RMS table before it closes itself down. Important info kept here includes the nextRecordID.

Throws:
javax.microedition.rms.RecordStoreNotOpenException - if the record store is not open.
javax.microedition.rms.RecordStoreException - general exception

enumerateRecords

public com.ibm.mobileservices.isync.midp.FastRecordEnumeration enumerateRecords(javax.microedition.rms.RecordFilter filter,
                                                                                javax.microedition.rms.RecordComparator comparator,
                                                                                boolean keepUpdated)
Return a new enumeration over the current FastRecordStore instance.

Parameters:
filter - ignored
comparator - ignored
keepUpdated - ignored
Returns:
new enumeration

getSizeAvailable

public int getSizeAvailable()
                     throws javax.microedition.rms.RecordStoreException
Get the number of bytes available for this record store to grow.

Returns:
bytes available
javax.microedition.rms.RecordStoreException

getNumRecords

public int getNumRecords()
Get the number of records in this store

Returns:
number of records.

getName

public java.lang.String getName()
Get the name of this record store

Returns:
record store name


(c) Copyright IBM Corp. 2001, 2002, 2003. All Rights Reserved.