com.funambol.storage
Class BlackberryRecordStore

java.lang.Object
  extended by com.funambol.storage.AbstractRecordStore
      extended by com.funambol.storage.BlackberryRecordStore

public class BlackberryRecordStore
extends AbstractRecordStore


Nested Class Summary
 class BlackberryRecordStore.IntByteArrayPair
          Used to keep key-object pairs together when sorting.
 
Method Summary
 int addRecord(byte[] data, int offset, int numBytes)
          Adds a new record to the record store.
 void closeRecordStore()
           
 void deleteRecord(int recordId)
          Deletes a record from the record store.
static void deleteRecordStore(java.lang.String recordStoreName)
          Deletes the named record store.
 javax.microedition.rms.RecordEnumeration enumerateRecords(javax.microedition.rms.RecordFilter filter, javax.microedition.rms.RecordComparator comparator, boolean keepUpdated)
           
 net.rim.device.api.util.IntVector filterAndSort(javax.microedition.rms.RecordFilter filter, javax.microedition.rms.RecordComparator comparator)
           
 java.lang.String getName()
           
 int getNextRecordID()
          Returns the recordId that will be assigned to the next object added to the store.
 int getNumRecords()
          Returns the number of records currently in the store
 byte[] getRecord(int recordId)
          Returns a copy of the data stored in the given record.
 int getRecord(int recordId, byte[] buffer, int offset)
          Returns a copy of the data stored in the given record.
 int getRecordSize(int recordId)
          Returns the size in bytes of the data available for the given recordId.
 int getSize()
          Gets the size in bytes of the current store.
 int getSizeAvailable()
          Returns the amount of additional space in bytes this store can hold
static void init(ObjectWrapperHandler owh)
          Initialize the store for blackberry with the default store key and the implemented ObjectWrapperHandler
static void init(ObjectWrapperHandler owh, java.lang.String key)
          Initialize the store for blackberry with custom store key and implemented ObjectWrapperHandler
static java.lang.String[] listRecordStores()
          Obtains the names of contained BlackberryRecordStore objects.
 void notifyListeners(int operation, int recordId)
          Notifies associated enumerator objects and other listeners that may be added
static AbstractRecordStore openRecordStore(java.lang.String recordStoreName, boolean createIfNecessary)
          Open and possibly create a record store.
 void setRecord(int recordId, byte[] newData, int offset, int numBytes)
          Sets the data in the given record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public static void init(ObjectWrapperHandler owh,
                        java.lang.String key)
Initialize the store for blackberry with custom store key and implemented ObjectWrapperHandler

Parameters:
owh - the ObjectWrapperHandler to be used with this store
key - the key of the store to be used

init

public static void init(ObjectWrapperHandler owh)
Initialize the store for blackberry with the default store key and the implemented ObjectWrapperHandler

Parameters:
owh - the ObjectWrapperHandler to be used with this store

deleteRecordStore

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

Parameters:
recordStoreName - Name of the record store to delete
Throws:
javax.microedition.rms.RecordStoreNotFoundException - If the record store could not be found
javax.microedition.rms.RecordStoreException - If the record store could not be found

listRecordStores

public static java.lang.String[] listRecordStores()
Obtains the names of contained BlackberryRecordStore objects.

Returns:
Array of strings containing the names of stores

openRecordStore

public static AbstractRecordStore openRecordStore(java.lang.String recordStoreName,
                                                  boolean createIfNecessary)
                                           throws javax.microedition.rms.RecordStoreException,
                                                  javax.microedition.rms.RecordStoreFullException,
                                                  javax.microedition.rms.RecordStoreNotFoundException
Open and possibly create a record store.

Parameters:
recordStoreName - The name of the record store to open
createIfNecessary - Whether or not we create the store if it does not exist
Returns:
A store object
Throws:
javax.microedition.rms.RecordStoreException - If a record store related exception occured
javax.microedition.rms.RecordStoreFullException - - If the record store is full
javax.microedition.rms.RecordStoreNotFoundException - - If the record store could not be found

addRecord

public int addRecord(byte[] data,
                     int offset,
                     int numBytes)
              throws javax.microedition.rms.RecordStoreNotOpenException,
                     javax.microedition.rms.RecordStoreException,
                     javax.microedition.rms.RecordStoreFullException
Adds a new record to the record store. The recordId assigned to the inserted record is returne to the user. This method needs to be able to accept empty (null) records.

Specified by:
addRecord in class AbstractRecordStore
Parameters:
data - Byte array to store
offset - Starting offset of the passed byte array
numBytes - Number of bytes from the offset to save
Returns:
The recordId for the new record
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is not open
javax.microedition.rms.RecordStoreFullException - If the operation cannot be completed because the record store is full
javax.microedition.rms.RecordStoreException - If any record store related exception occurs.

closeRecordStore

public void closeRecordStore()
                      throws javax.microedition.rms.RecordStoreNotOpenException,
                             javax.microedition.rms.RecordStoreException
Specified by:
closeRecordStore in class AbstractRecordStore
Throws:
javax.microedition.rms.RecordStoreNotOpenException
javax.microedition.rms.RecordStoreException

deleteRecord

public void deleteRecord(int recordId)
                  throws javax.microedition.rms.RecordStoreNotOpenException,
                         javax.microedition.rms.InvalidRecordIDException,
                         javax.microedition.rms.RecordStoreException
Deletes a record from the record store.

Specified by:
deleteRecord in class AbstractRecordStore
Parameters:
recordId - The recordId to be removed from the store
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is closed
javax.microedition.rms.InvalidRecordIDException - If the recordId does not exist
javax.microedition.rms.RecordStoreException - Any other error

enumerateRecords

public javax.microedition.rms.RecordEnumeration enumerateRecords(javax.microedition.rms.RecordFilter filter,
                                                                 javax.microedition.rms.RecordComparator comparator,
                                                                 boolean keepUpdated)
                                                          throws javax.microedition.rms.RecordStoreNotOpenException
Specified by:
enumerateRecords in class AbstractRecordStore
Throws:
javax.microedition.rms.RecordStoreNotOpenException

filterAndSort

public net.rim.device.api.util.IntVector filterAndSort(javax.microedition.rms.RecordFilter filter,
                                                       javax.microedition.rms.RecordComparator comparator)
                                                throws javax.microedition.rms.RecordStoreNotOpenException
Throws:
javax.microedition.rms.RecordStoreNotOpenException

getName

public java.lang.String getName()
                         throws javax.microedition.rms.RecordStoreNotOpenException
Specified by:
getName in class AbstractRecordStore
Throws:
javax.microedition.rms.RecordStoreNotOpenException

getNextRecordID

public int getNextRecordID()
                    throws javax.microedition.rms.RecordStoreNotOpenException,
                           javax.microedition.rms.RecordStoreException
Returns the recordId that will be assigned to the next object added to the store. According to the spec for javax.rms.RecordStore, this should start at 1.

Specified by:
getNextRecordID in class AbstractRecordStore
Returns:
RecordId of the next object to be added to the store
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is not open
javax.microedition.rms.RecordStoreException - If any other record store related exception occurs.

getNumRecords

public int getNumRecords()
                  throws javax.microedition.rms.RecordStoreNotOpenException
Returns the number of records currently in the store

Specified by:
getNumRecords in class AbstractRecordStore
Returns:
The number of records in the store.
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is not open

getRecord

public byte[] getRecord(int recordId)
                 throws javax.microedition.rms.RecordStoreNotOpenException,
                        javax.microedition.rms.InvalidRecordIDException,
                        javax.microedition.rms.RecordStoreException
Returns a copy of the data stored in the given record. If data is 0 length, return null.

Specified by:
getRecord in class AbstractRecordStore
Parameters:
recordId - The ID of the record to use in this operation
Returns:
Byte array of the data stored in the given record
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is not open
javax.microedition.rms.InvalidRecordIDException - If the recordId is invalid
javax.microedition.rms.RecordStoreException - if a general record store exception occurs

getRecord

public int getRecord(int recordId,
                     byte[] buffer,
                     int offset)
              throws javax.microedition.rms.RecordStoreNotOpenException,
                     javax.microedition.rms.InvalidRecordIDException,
                     javax.microedition.rms.RecordStoreException,
                     java.lang.ArrayIndexOutOfBoundsException
Returns a copy of the data stored in the given record. If data is 0 length, return null.

Specified by:
getRecord in class AbstractRecordStore
Parameters:
recordId - The ID of the record to use in this operation
buffer - The byte array in which to copy the data
offset - The index into the buffer in which to start copying
Returns:
Byte array of the data stored in the given record
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is not open
javax.microedition.rms.InvalidRecordIDException - If the recordId is invalid
javax.microedition.rms.RecordStoreException - if a general record store exception occurs
java.lang.ArrayIndexOutOfBoundsException

getRecordSize

public int getRecordSize(int recordId)
                  throws javax.microedition.rms.RecordStoreNotOpenException,
                         javax.microedition.rms.InvalidRecordIDException,
                         javax.microedition.rms.RecordStoreException
Returns the size in bytes of the data available for the given recordId. If data is 0 length, return null.

Specified by:
getRecordSize in class AbstractRecordStore
Parameters:
recordId - RecordId to find the size of
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is closed
javax.microedition.rms.InvalidRecordIDException - If the recordId does not exist
javax.microedition.rms.RecordStoreException - Any oher record store exception

getSize

public int getSize()
            throws javax.microedition.rms.RecordStoreNotOpenException
Gets the size in bytes of the current store.

Specified by:
getSize in class AbstractRecordStore
Returns:
The size in bytes of data in the store.
Throws:
javax.microedition.rms.RecordStoreNotOpenException - If the record store is not open

getSizeAvailable

public int getSizeAvailable()
                     throws javax.microedition.rms.RecordStoreNotOpenException
Returns the amount of additional space in bytes this store can hold

Specified by:
getSizeAvailable in class AbstractRecordStore
Returns:
Free ram
Throws:
javax.microedition.rms.RecordStoreNotOpenException - if the record store is not open

notifyListeners

public void notifyListeners(int operation,
                            int recordId)
Notifies associated enumerator objects and other listeners that may be added

Parameters:
operation - Integer constant corresponding to the action being performed
recordId - RecordID of the record being manipulated.

setRecord

public void setRecord(int recordId,
                      byte[] newData,
                      int offset,
                      int numBytes)
               throws javax.microedition.rms.RecordStoreNotOpenException,
                      javax.microedition.rms.InvalidRecordIDException,
                      javax.microedition.rms.RecordStoreException,
                      javax.microedition.rms.RecordStoreFullException
Sets the data in the given record.

Specified by:
setRecord in class AbstractRecordStore
Throws:
javax.microedition.rms.RecordStoreNotOpenException
javax.microedition.rms.InvalidRecordIDException
javax.microedition.rms.RecordStoreException
javax.microedition.rms.RecordStoreFullException


Copyright © 2001-2009 Funambol.