Introduction
The original MIDP specification defined a persistent, record-based storage facility called the Record Management Store (RMS). A MIDlet suite can use RMS to create one or more record stores, each identified by a unique name. You'll find the necessary classes and interfaces in the In MIDP 1.0 each store is private to the MIDlet suite that creates it. The MIDP 2.0 specification adds a very useful new capability to the RMS package: It enables one MIDlet suite to share a record store with other MIDlet suites. The Why
Duplicating data in multiple record stores raises serious synchronization issues. If an item is created, updated, or deleted in one store, the same transaction must be executed in all similar stores on the same device. Because a MIDP 2.0-based application suite can give other MIDlet suites access to any of its record stores, you can consolidate data at a single location. By eliminating data duplication, not only do you avoid synchronization problems, but you simplify management, and use more efficiently the limited storage common in MIDP-enabled devices. To make a record store visible to other MIDlet suites, the suite that owns it must share it explictly, specifying either read-only or read-write access. The MIDP standard does not define other access privileges or restrictions. If a record store is exported, it is exported to all MIDlet suites, and all of them have the same access mode. Note that a store created using the MIDP 1.0 RMS package is not shared, which is not surprising: the MIDP 2.0 RMS package is backward-compatible with the MIDP 1.0 version. Unrestricted sharing of a record store raises trust issues. The store is accessible to any MIDlet that can generate its name. Furthermore, if it's shared writable, any MIDlet can change or delete its data. If you don't want shared data to be quite so freely accessible, here are some possible tactics to consider:
The How
Sharing an RMS record store requires two or more parties: an owner and one or more consumers. The owner is responsible for creating and naming the store and establishing its authorization mode – sharable or not – and its access mode – writable or not. Consumers gain access to the record store using its name. As you'd expect, they can't access a store that isn't sharable, or modify one that's not writable. A shared RMS is identified by the tuple (Vendor name, MIDlet suite name, Record store name) where:
To support sharing, the MIDP 2.0 standard adds two fields and three methods to the
The first new method opens an existing record store, or creates a new one and sets its authorization and
static RecordStore
openRecordStore( String recordStoreName, boolean create,
int authmode, boolean writable );
The parameters are:
Given the last three parameters and the possibility that the store already exists, there are 16 possible combinations of starting conditions. Eight of the cases reduce to a common outcome: If the record store already exists the method simply ignores the The method a consumer uses to open a shared record store is:
static RecordStore
openRecordStore( String recordStoreName, String vendorName,
String suiteName );
where:
The method opens the specified record store successfully only if it exists and the owner has set its
Note that The last new method is:
void
setMode( int authmode, boolean writable );
where:
Only the owning MIDlet suite may change the An Example
The sample application consists of two MIDlet suites that share a collection of URLs, which might be used to identify different access points to a corporate network. The interesting bits of the
import java.io.*;
public class URL {
private String protocol;
private String path;
public URL( byte[] data ) throws ... {
fromByteArray( data );
}
public URL( String p, String f ) {
protocol = p;
path = f;
}
public String getProtocol() {
return protocol;
}
public String getPath() {
return path;
}
public byte[] toByteArray() throws ... {
byte[] data;
...
return data;
}
private void fromByteArray( byte[] array ) throws ... {
...
}
}
The collection of URLs is managed by the
import java.io.*;
import javax.microedition.rms.*;
public class URLdb {
RecordStore rs;
public URLdb( String name ) throws ... { // Owner
rs = RecordStore.openRecordStore( name, true,
RecordStore.AUTHMODE_ANY, false );
}
public URLdb( String recordStoreName, String vendorName,
String suiteName ) throws ... { // Consumer
rs = RecordStore.openRecordStore( recordStoreName,
vendorName, suiteName );
}
public void close() throws ... {
rs.closeRecordStore();
}
public int add( String protocol, String path ) throws ... {
URL url = new URL( protocol, path );
byte[] data;
data = url.toByteArray();
return rs.addRecord( data, 0, data.length );
}
public URL getURL( int recordID ) throws ... {
byte[] data = rs.getRecord( recordID );
return new URL( data );
}
public void delete( int recordId ) throws ... {
rs.deleteRecord( recordId );
}
public int RecordCount() {
return rs.recordCount();
}
public RecordEnumeration enumerate()
throws RecordStoreNotOpenException {
return rs.enumerateRecords( null, null, true );
}
}
The owning MIDlet, called
The consumer MIDlet, called Conclusion
The MIDP RMS package provides persistent, record-based storage for MIDlets. The MIDP 2.0 specification adds a highly useful capability: One MIDlet suite can share a record store with others, granting them read-only or read-write access, depending on application requirements. By centralizing common data at a single location, a shared record store can simplify management, reduce on-device storage requirements, and avoid the synchronization problems that can arise when data is duplicated in multiple record stores. Where to Go from Here
| ||||||||||||||
|
| ||||||||||||