Java Reference
In-Depth Information
An instance of the RecordStore class, representing a single record store, can be obtained via the
static method openRecordStore() . The method call requires two parameters: the name of the
RecordStore and a flag specifying whether the RecordStore should be created if it does not
exist yet. The name of the record store should be a String consisting of no more than 32 Unicode
characters. The names are case sensitive, so Foo, foo, and FOO would denote different record stores.
The following line opens the record store named myRecords and creates it if it does not exist yet:
RecordStore myRecords = RecordStore.openRecordStore("myRecords",
true);
Other general static methods are provided for listing all record stores of a MIDlet suite and deleting a
record store. Because these methods are static, it is possible to use them without obtaining an instance
of RecordStore first. These general methods are listed in Table 5.1 . To use all other
RecordStore access methods, you must create a RecordStore instance by calling
openRecordStore() .
Note
MIDP 2.0 introduces two additional openRecordStore() methods to share
RecordStores across multiple MIDlet suites. An additional setMode() method allows you to change
the access mode of a RecordStore later.
The first new openRecordStore() method requires four parameters. The first two parameters are
identical to the existing openRecordStore() method and define the name of the record store and
whether the store should be created as if it does not yet exist. The third parameter defines the access
mode. The constant RecordStore.AUTHMODE_PRIVATE indicates that only MIDlets in the same
MIDlet suite can access the RecordStore. RecordStore.AUTHMODE_ANY enables any MIDlet to
access the RecordStore. The fourth parameter is a boolean specifying whether the RecordStore is
writable by other MIDlet suites in the AUTHMODE_ANY case.
The second new openRecordStore() method takes only three String parameters. Again, the first
parameter defines the name of the RecordStore. The second and third parameter define a vendor and a
MIDlet suite name required to get access to the RecordStore.
The authentication mode of a record store can be changed after creation using the setMode() method.
This method takes the previously described authentication mode and the write flag as parameters.
All three methods can throw a SecurityException if the desired operation is not permitted.
For closing a record store, the API provides the method closeRecordStore() . At the latest, any
open record store owned by an application should be closed when the application is terminated. Please
note that the number of calls to close a certain record store must match the calls to
openRecordStore() . Calling closeRecordStore() allows the system to free resources
associated with a record store.
Table 5.1. Static RecordSt o re Methods
Method Name
Purpose
String[] listRecordStores()
Returns all record stores in a String
array that are available in the current
MIDlet suite.
RecordStore openRecordStore (String
recordStoreName, boolean
Opens a record store.
 
Search WWH ::




Custom Search