Java Reference
In-Depth Information
Opening and Closing a Record Store
Given the name of a record store, opening one is easy: simply invoke the RecordStore.
openRecordStore method, passing the name of the store and stating whether the store
should be created if it doesn't exist. This method returns an instance of RecordStore you
use to access records in the open store. For example,
RecordStore.openRecordStore("Weather", true);
creates the record store named Weather for the current MIDlet and returns an instance
of RecordStore . This method can throw one of the following exceptions, so you best be
prepared to handle it:
RecordStoreException : The method throws this exception in response to a general
error creating or opening the record store.
RecordStoreNotFoundException : The method throws this exception if it can't find the
record store you named and the creation flag is false .
RecordStoreFullException : The method throws this exception if the record store
is full.
IllegalArgumentException : The method throws this exception if the name is invalid.
Other RecordStore.openRecordStore methods take additional arguments that you
must use if you want to share your record store with multiple applications. In addition to
specifying the name of the record store and whether or not it should be created, you pass
an access mode ( AUTHMODE_PRIVATE or AUTHMODE_ANY , meaning that any MIDlet can access
the record store) and a final argument indicating whether the store should be available
for read-only access ( false ) or read and write access ( true ) to other MIDlets. This inter-
face lets you create a shared record store; the final overloaded RecordStore.
openRecordStore method lets you open a shared record store from a different MIDlet. It
takes three arguments: the name of the store, the name of the MIDlet suite vendor
exporting the record store, and the name of the MIDlet suite exporting the record store.
As a result, for two MIDlets to share record stores, all of the following must occur:
• The MIDlet creating the record store to share must create it using
RecordStore.openRecordStore , passing true to create the record store, AUTHMODE_ANY
to permit other MIDlets to access the record store, and true if the shared record
store is to be writable by other applications.
• The author of the MIDlet creating the record store to share must publicize the for-
mat of records in the record store (ideally through a class that client applications
can use to access the store directly) as well as the vendor name and MIDlet suite
name used by the MIDlet creating the record store.
 
Search WWH ::




Custom Search