Java Reference
In-Depth Information
• Other MIDlets outside the MIDlet suite of the MIDlet creating the record store
must open the store using
RecordStore.openRecordStore
, passing the name of the
record store, the name of the creating MIDlet suite vendor, and the name of the
MIDlet suite that originally created the store.
Once you're done with a record store, you must close it, signaling to the underlying
MIDP implementation that you're done using the resources consumed by the record
store. You do this by invoking
closeRecordStore
on the instance provided when you
opened the record store.
Removing a Record Store
Although the MIDP removes the record stores associated with a MIDlet suite when the
suite is deleted, sometimes you want to delete a record store yourself. You do this by
invoking the
RecordStore.deleteRecordStore
method, which passes the name of the
record store to delete. The record store must be owned by the MIDlet suite of the MIDlet
making the request, and it may throw an exception if the store is open or any other error
occurs. It can throw the following exceptions:
•
RecordStoreException
: In response to a general error when removing the record
store, such as if the record store is still open
•
RecordStoreNotFoundException
: If the record store you named couldn't be found
As you'll learn in the upcoming section “Accessing Records in the Record Store,” you
can listen for changes to the record store, causing the record store to invoke a method
when changes occur. You should be aware, however, that the record store does not invoke
the method you provide when you delete the record store; in deleting the record store,
the store and its records are irretrievably deleted, and the system invokes no listeners.
Obtaining Information About a Record Store
While you're not privy to the underlying implementation details of the record store, there
are
some details about a specific record store you can access. Of course, you typically
know the
name
of the record store with which you're working. An application that takes a
document-oriented approach to its data—say, one that tracks expense reports—might
choose to represent each document as a record or as a record store. If the latter, then
users may be responsible for naming record stores, such as “Sales Trip London” or “Sun
JavaOne Trip.” Of course, once you open the gates to user-named record stores, you need
a way to determine
what
record stores exist; you do this using the
RecordStore.
listRecordStores
method, which returns an array of
String
objects, each containing the
name of a specific record store belonging to the MIDlet suite. If the suite's MIDlets have
not created any applications, this method will return
null
.