2. • This RecordStore class provides methods for
creating, writing, and reading data from
recordstores.
• A class representing a record store. A record store
consists of a collection of records which will
remain persistent across multiple invocations of
the MIDlet. The platform is responsible for
making its best effort to maintain the integrity of
the MIDlet's record stores throughout the normal
use of the platform, including reboots, battery
changes, etc.
http://improvejava.blogspot.in
5. openRecordStore()
• Open (and possibly create) or create a record
store associated with the given MIDlet suite.
And returns a RecordStore reference.
• If this method is called by a MIDlet when the
record store is already open by a MIDlet in the
MIDlet suite, this method returns a reference
to the same RecordStore object.
http://improvejava.blogspot.in
6. • The openRecordStore() method requires two
parameters. The first parameter is a string
containing the name of the record store.
• The second parameter is a boolean value
indicating whether the record store should be
created if the record store doesn’t exist. A true
value causes the record store to be created
• if the record store isn’t in the MIDlet suite and
also opens the record store.
• A false value does not create the record store if
the record store isn’t located.
http://improvejava.blogspot.in
8. • Parameters:recordStoreName - the MIDlet suite unique
name for the record store, consisting of between one and
32 Unicode characters inclusive.createIfNecessary - if true,
the record store will be created if necessary
• Returns:RecordStore object for the record store
Throws:
• RecordStoreException - if a record store-related exception
occurred
• RecordStoreNotFoundException - if the record store could
not be found
• RecordStoreFullException - if the operation cannot be
completed because the record store is full
• IllegalArgumentException - if recordStoreName is invalid
http://improvejava.blogspot.in
10. addRecord()
• Int addRecord(byte[] data, int offset,
int numBytes)
• Adds a new record to the record store. It
returns int value, which is Record Id , this id is
useful to access the particular record
• Example:
• rec.addRecord(byteOutputData,
0,byteOutputData.length);
http://improvejava.blogspot.in
11. getRecord()
• This method reads a record from the record store. Record Id must be in
the method as a parameter(actual parameter)
• The getRecord() method copies the record from the record store and into
the byteInputData byte array and returns an integer representing the
length of the record.
• Call the getRecord() method of the RecordStore class for each iteration of
the for
loop.
• The getRecord() method returns bytes from the RecordStore, which are
stored in a byte array that you create.
• The getRecord() method requires three parameters. The first parameter is
the record ID,
• The second parameter is the byte array that you create for storing the
record.
• The third parameter is an integer representing the position in the record
from which to begin copying into the byte array.
http://improvejava.blogspot.in
12. • For example, the following code segment reads
the second record from the record store and
copies that record, beginning with the first byte
of the record, from the record store into the byte
array. Typically, the first parameter of the
getRecord() method is the integer of the for loop,
and the third parameter is zero, indicating the
entire record is to be copied into the byte array.
• Example: recordstore.getRecord(2, myByteArray,
0)
http://improvejava.blogspot.in
13. recordstore.getRecord(2, myByteArray,
0)
• three parameters.
• The first is the record ID that is being read,
which is the current value of the for loop
variable.
• The second is the name of the byte array into
which the record is copied.
• The third is the index position of the first byte
that is to be copied into the byte array.
http://improvejava.blogspot.in
15. closeRecordStore()
• This method is called when the MIDlet requests to
have the record store closed. Note that the record
store will not actually be closed until
closeRecordStore() is called as many times as
openRecordStore() was called. In other words, the
MIDlet needs to make a balanced number of close calls
as open calls before the record store is closed.When
the record store is closed, all listeners are removed and
all RecordEnumerations associated with it become
invalid. If the MIDlet attempts to perform operations
on the RecordStore object after it has been closed, the
methods will throw a RecordStoreNotOpenException.
http://improvejava.blogspot.in
16. Syntax of closeRecordStore()
• public void closeRecordStore() throws
RecordStoreNotOpenException,
RecordStoreException
http://improvejava.blogspot.in
17. listRecordStores()
• Returns an array of the names of record stores
owned by the MIDlet suite. Note that if the
MIDlet suite does not have any record stores, this
function will return null. The order of
RecordStore names returned is implementation
dependent.
• Returns:array of the names of record stores
owned by the MIDlet suite. Note that if the
MIDlet suite does not have any record stores, this
function will return null.
http://improvejava.blogspot.in
19. deleteRecordStore()
• Deletes the named record store. MIDlet suites are
only allowed to delete their own record stores. If
the named record store is open (by a MIDlet in
this suite or a MIDlet in a different MIDlet suite)
when this method is called, a
RecordStoreException will be thrown. If the
named record store does not exist a
RecordStoreNotFoundException will be thrown.
Calling this method does NOT result in
recordDeleted calls to any registered listeners of
this RecordStore.
http://improvejava.blogspot.in
22. enumerateRecords()
RecordEnumeration is constructed by calling
enumerateRecords() method.
• RecordEnumeration is a method for retrieving record
from recordStore. It also provides for sorting, searching
of records.
• If u want to sort the records we have to write null as a
1st parameter in enumerateRecords()
• Ex: rec.enumerateRecords(null, com,false);
• If you want to search the records we have to write null
as the 2nd parameter in enumerateRecords() method.
Ie: rec.enumerateRecords(filter,null,false);
• This method is used to call the compare() method
SortRec.java
23. r = rec.enumerateRecords(null, com, false);
Boolean false:
• Means specifies whether or not enumeration
is updated with change in record store
SortRec.java
24. • public RecordEnumeration enumerateRecords(RecordFilter filter,
RecordComparator comparator, boolean keepUpdated) throws
RecordStoreNotOpenException
• r =rec.enumerateRecords(null, null, false);
• RecordFilter: it specifies which records should be included in enumeration.
• RecordComparator: it helps in comparing two records. It is mainly useful in
finding the sort order.
• Boolean: Specifies whether or not enumeration is updated with change in
record store
http://improvejava.blogspot.in
25. • Parameters:filter - if non-null, will be used to determine what subset of
the record store records will be used
• comparator - if non-null, will be used to determine the order in which the
records are returned
• keepUpdated - if true, the enumerator will keep its enumeration current
with any changes in the records of the record store. Use with caution as
there are possible performance consequences. If false the enumeration
will not be kept current and may return record
• Ids for records that have been deleted or miss records that are added
later. It may also return records out of order that have been modified after
the enumeration was built. Note that any changes to records in the record
store are accurately reflected when the record is later retrieved, either
directly or through the enumeration. The thing that is risked by setting this
parameter false is the filtering and sorting order of the enumeration when
records are modified, added, or deleted.
• Returns:an enumeration for traversing a set of records in the record store
in an optionally specified order
http://improvejava.blogspot.in
26. setMode()
• This method is used to set or change the
authorization mode. By setting this mode to
AUTHMODE-ANY, the record store can be
made sharable.
• Syntax:
• Void setMode(int authmode, boolean
writable);
http://improvejava.blogspot.in