Sie sind auf Seite 1von 18

Record Store Management

javax.microedition.midlet.rms

For Queries Contact Prof.


Rinku Shah 9892422456

A record store is a small database that


contains pieces of data called records
Record stores are represented by
instances of
javax.microedition.rms.RecordStore.
The scope of a record store can either be
limited to a single MIDlet suite or be
shared between MIDlet suites.

For Queries Contact Prof.


Rinku Shah 9892422456

The RecordStore class serves


two purposes

It defines an API for manipulating


individual records and for managing
record stores.

For Queries Contact Prof.


Rinku Shah 9892422456

Opening, Closing, and


Removing Record Stores

public static RecordStore


openRecordStore(String
recordStoreName, boolean
createIfNecessary) throws
RecordStoreException,RecordStoreFullEx
ception, RecordStoreNotFoundException

For Queries Contact Prof.


Rinku Shah 9892422456

The following code opens a record store


named Address:
RecordStore rs =
RecordStore.openRecordStore("Address"
, true);
..
closeRecordStore()
For Queries Contact Prof.
Rinku Shah 9892422456

To find out all the record stores available to


a particular MIDlet suite
public static String[] listRecordStores()
To delete the record store and its contained
records
deleteRecordStore()
For Queries Contact Prof.
Rinku Shah 9892422456

Sharing Record Stores

public static RecordStore


openRecordStore(String
recordStoreName,
boolean createIfNecessary, byte
authMode, boolean writable) throws
RecordStoreException,
RecordStoreFullException,
RecordStoreNotFoundException
For Queries Contact Prof.
Rinku Shah 9892422456

The authMode and writable parameters are


only used if the record store is created, which
implies that the record store doesnt exist and
createIfNecessary is true.
You can change the authorization mode and
writable flag of an open record store using the
following method:
public void setMode(byte authmode, boolean
writable) throws RecordStoreException
For Queries Contact Prof.
Rinku Shah 9892422456

The default authorization mode is


AUTHMODE_PRIVATE i.e. a record store
is only accessible from MIDlets in the
MIDlet suite that created the record store

AUTHMODE_ANY means that any other


MIDlet on the device can access the
record store
For Queries Contact Prof.
Rinku Shah 9892422456

Open a shared record store

public static RecordStore


openRecordStore(String
recordStoreName,
String vendorName, String suiteName)
throws RecordStoreException,
RecordStoreNotFoundException

For Queries Contact Prof.


Rinku Shah 9892422456

To get record store size


public int getSize()

To get available space in a record


store
public int getSizeAvailable()

For Queries Contact Prof.


Rinku Shah 9892422456

Adding records
public int addRecord(byte[] data, int
offset, int numBytes)
throws RecordStoreNotOpenException,
RecordStoreException,
RecordStoreFullException
The added record will be numBytes long,
taken from the data array starting at
offset. The new records ID is returned

For Queries Contact Prof.


Rinku Shah 9892422456

Adding a new record to a record


store named rs
String record = "This is a record";
byte[] data = record.getBytes();
int id = rs.addRecord(data, 0, data.length);

It creates a byte array from a String, and


then writes the entire byte array into a
new record
For Queries Contact Prof.
Rinku Shah 9892422456

Retrieving Records

public byte[] getRecord(int recordId)


throws RecordStoreNotOpenException,
InvalidRecordIDException,
RecordStoreException

public int getRecord(int recordId, byte[] buffer,


int offset) throws
RecordStoreNotOpenException,
InvalidRecordIDException,
For Queries Contact Prof.
RecordStoreException
Rinku Shah 9892422456

Given a RecordStore rs and a


record ID id, retrieve data
record:

byte[] retrieved = new


byte[rs.getRecordSize(id)];
rs.getRecord(id, retrieved, 0);
String retrievedString = new
String(retrieved);

For Queries Contact Prof.


Rinku Shah 9892422456

If memory usage or speed is


not a concern

byte[] retrieved = rs.getRecord(id);

For Queries Contact Prof.


Rinku Shah 9892422456

Replacing records
public void setRecord(int recordId, byte[]
newData, int offset, int numBytes)
throws RecordStoreNotOpenException,
InvalidRecordIDException,
RecordStoreException,
RecordStoreFullException

For Queries Contact Prof.


Rinku Shah 9892422456

Deleting records

You can remove a record by passing its


ID to

deleteRecord()

For Queries Contact Prof.


Rinku Shah 9892422456

Das könnte Ihnen auch gefallen