Outline-session 9 (09-April-2009) <ul><li>>> J2ME Record Management System </li></ul><ul><li>-Introduction </li></ul><ul><...
Introduction <ul><li>Just like ordinary desktop-based programs, MIDlets need a facility to store data permanently.  </li><...
RMS(Record Management System) <ul><li>RMS is a system for managing records.  </li></ul><ul><li>A record is an individual d...
Where are the fields? <ul><li>Don't be  confused by the term record. The answer is simple:  </li></ul><ul><ul><li>In RMS a...
Record Stores <ul><li>A record store is an ordered collection of records.  </li></ul><ul><li>E ach  record  must belong to...
Record Stores <ul><li>When a record is created, the record store assigns it a unique identifier, an integer called the rec...
Record Stores-MIDlet <ul><li>A MIDlet can have any number of record stores (including none) </li></ul><ul><li>Each record ...
Record Stores-Scope <ul><li>Within &quot;MIDlet Suite One,&quot; MIDlet #1 and MIDlet #2 can access all four record stores...
Record Stores-Two attribute <ul><li>>> There are two values maintained by a record store that may be helpful for tracking ...
Record Store API <ul><li>>> This class is the heart of the RMS. Through this class we create, update, query and delete rec...
Record Store API <ul><li>>> This class is the heart of the RMS. Through this class we create, update, query and delete rec...
Manage Record Store <ul><li>To open a record store, you simply need to  call the  openRecordStore  method.   </li></ul><ul...
Manage Record Store <ul><li>closeRecordStore () method  closes a n open record.  </li></ul><ul><ul><li>rs. closeRecordStor...
Adding records <ul><li>The MIDlet invokes the  addRecord () method of RecordStore class to insert a new record into the re...
Manage Record Store <ul><li>closeRecordStore () method  closes a n open record.  </li></ul><ul><ul><li>rs. closeRecordStor...
Retrieving Record <ul><li>There are two versions to retrieve a record: </li></ul><ul><ul><li>public int getRecord(int reco...
Update Record <ul><li>To update  a record  use the method  setRecord : </li></ul><ul><ul><li>public void setRecord(int rec...
Deleting Record <ul><li>The MIDlet invokes the deleteRecord() method to delete a record from the record store. </li></ul><...
Record Enumeration <ul><li>The RecordEnumeration (A.K.A enumerator) class provides methods for moving forward and back thr...
Record Enumeration <ul><li>Key Methods in enumeration </li></ul><ul><li>>> nextRecord() to move forward </li></ul><ul><li>...
Record Enumeration-API
Upcoming SlideShare
Loading in...5
×

Session9 J2ME Record Management System

4,735

Published on

J2ME Record Management System

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,735
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
142
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Session9 J2ME Record Management System

  1. 1. Outline-session 9 (09-April-2009) <ul><li>>> J2ME Record Management System </li></ul><ul><li>-Introduction </li></ul><ul><li>-RMS </li></ul><ul><li>-Record Store </li></ul><ul><li>-Record Store-MIDlet </li></ul><ul><li>-Record Store –Scope </li></ul><ul><li>-Record Store –Two attribute </li></ul><ul><li>-Record Store –API </li></ul><ul><li>-Record Enumeration </li></ul>
  2. 2. Introduction <ul><li>Just like ordinary desktop-based programs, MIDlets need a facility to store data permanently. </li></ul><ul><li>C ell phones and other mobile devices are quite limited when compared to desktop systems. </li></ul><ul><li>NO file system nor relational database in a MIDP-based environment. </li></ul><ul><li>MIDP provides the persistence storage package javax.microedition.rms for storing data . </li></ul><ul><li>The package is called Record Management System ( RMS ) provides a simple record-oriented database. </li></ul>
  3. 3. RMS(Record Management System) <ul><li>RMS is a system for managing records. </li></ul><ul><li>A record is an individual data item. </li></ul><ul><li>No data type. A record is represented by an array of bytes . </li></ul><ul><li>A record can contain a number, a string, an array, an image -- anything that a sequence of bytes can represent. </li></ul><ul><li>Manipulating byte array is difficult. </li></ul><ul><li>A simple way is to use String as it has a rich API to manipulate and convert it to and from byte array is simple. </li></ul>
  4. 4. Where are the fields? <ul><li>Don't be confused by the term record. The answer is simple: </li></ul><ul><ul><li>In RMS a record doesn't have any fields. </li></ul></ul><ul><li>A record consists of a n array of single binary field of variable size identified by a record Id . </li></ul><ul><li>This keeps RMS small and flexible -- important attributes for a MIDP subsystem. </li></ul><ul><li>The programmer has to handle type conversion, comparison, etc. </li></ul>
  5. 5. Record Stores <ul><li>A record store is an ordered collection of records. </li></ul><ul><li>E ach record must belong to a record store, and all record access occurs through the record store. </li></ul><ul><li>In fact, the record store guarantees that records are read and written atomically, with no possibility of data corruption. </li></ul>
  6. 6. Record Stores <ul><li>When a record is created, the record store assigns it a unique identifier, an integer called the record ID. </li></ul><ul><li>The first record added to a record store has a record ID of 1, the second a record ID of 2, and so on. </li></ul>
  7. 7. Record Stores-MIDlet <ul><li>A MIDlet can have any number of record stores (including none) </li></ul><ul><li>Each record store is uniquely identified by its name </li></ul><ul><li>MIDlet is part of MIDlet suite, record store names must also be unique within the suite </li></ul><ul><li>MIDlets that are packaged within a suite can access not only the record stores they create, but also those of other MIDlets in the suite </li></ul>
  8. 8. Record Stores-Scope <ul><li>Within &quot;MIDlet Suite One,&quot; MIDlet #1 and MIDlet #2 can access all four record stores available as part of the suite. </li></ul><ul><li>MIDlets in Suite One cannot access the record stores of Suite Two. </li></ul>
  9. 9. Record Stores-Two attribute <ul><li>>> There are two values maintained by a record store that may be helpful for tracking database usage </li></ul><ul><li>Version Number: </li></ul><ul><ul><li> Version number is an integer value. </li></ul></ul><ul><ul><li>the starting value when creating a new record is not defined by the API </li></ul></ul><ul><ul><li>If you need to track version numbers, you can query the </li></ul></ul><ul><ul><li>record store immediately after creation using getVersion() to determine the starting value. </li></ul></ul><ul><li>Date and Timestamp: </li></ul><ul><ul><li>is a long integer that represents the number of milliseconds since </li></ul></ul><ul><ul><li>midnight January 1st, 1970. You can query this value by calling getLastModified(). </li></ul></ul>
  10. 10. Record Store API <ul><li>>> This class is the heart of the RMS. Through this class we create, update, query and delete record stores </li></ul>
  11. 11. Record Store API <ul><li>>> This class is the heart of the RMS. Through this class we create, update, query and delete record stores </li></ul>
  12. 12. Manage Record Store <ul><li>To open a record store, you simply need to call the openRecordStore method. </li></ul><ul><ul><li>public static RecordStore openRecordStore( String recordStoreName, boolean createIfNecessary) throws RecordStoreException, RecordStoreFullException, RecordStoreNotFoundException </li></ul></ul><ul><li>createIfNecessary determines whether the record store , if not existed, will be created or a RecordStoreNotFoundException will be thrown . </li></ul><ul><li>The following opens a record store named &quot;Address.&quot; </li></ul><ul><li>RecordStore rs = RecordStore.openRecordStore(&quot;Address&quot;, true); </li></ul><ul><li>The record store will be created if it does not exist. </li></ul>
  13. 13. Manage Record Store <ul><li>closeRecordStore () method closes a n open record. </li></ul><ul><ul><li>rs. closeRecordStore() ; </li></ul></ul><ul><li>Remember to clean up after yourself as much as possible. </li></ul><ul><li>T o delete a record store and its contained records, call the static deleteRecordStore () method. </li></ul><ul><li>RecordStore.deleteRecordStore(&quot;Address&quot;); </li></ul><ul><li>To find out all the record stores available to a particular MIDlet suite, call the listRecordStores () method: </li></ul><ul><ul><li>public static String[] listRecordStores() </li></ul></ul>
  14. 14. Adding records <ul><li>The MIDlet invokes the addRecord () method of RecordStore class to insert a new record into the record store. </li></ul><ul><ul><li>public int addRecord(byte[] data, int offset, int numBytes) </li></ul></ul><ul><ul><li>inserts a record represented by an array of bytes data with offset as its starting index and numBytes as its length. </li></ul></ul><ul><ul><li>String brand = &quot;Honda&quot;; </li></ul></ul><ul><ul><li>byte bytes[] = brand .getBytes(); </li></ul></ul><ul><ul><li>int recID = rs .addRecord (bytes,0,bytes.length); </li></ul></ul>
  15. 15. Manage Record Store <ul><li>closeRecordStore () method closes a n open record. </li></ul><ul><ul><li>rs. closeRecordStore() ; </li></ul></ul><ul><li>Remember to clean up after yourself as much as possible. </li></ul><ul><li>T o delete a record store and its contained records, call the static deleteRecordStore () method. </li></ul><ul><li>RecordStore.deleteRecordStore(&quot;Address&quot;); </li></ul><ul><li>To find out all the record stores available to a particular MIDlet suite, call the listRecordStores () method: </li></ul><ul><ul><li>public static String[] listRecordStores() </li></ul></ul>
  16. 16. Retrieving Record <ul><li>There are two versions to retrieve a record: </li></ul><ul><ul><li>public int getRecord(int recordId, byte[] buffer, int offset) </li></ul></ul><ul><ul><li>copies the data stored in the given record to the byte array represented by buffer. </li></ul></ul><ul><ul><li>public byte[] getRecord(int record I d) </li></ul></ul><ul><ul><li>returns a new copy of the data represented by recordId. </li></ul></ul>byte[] retrieved = new byte[rs.getRecordSize( recID )]; rs.getRecord(id, retrieved, 0); String retrievedString = new String(retrieved); byte[] retrieved = rs.getRecord( recID ); String retrievedString = new String(retrieved);
  17. 17. Update Record <ul><li>To update a record use the method setRecord : </li></ul><ul><ul><li>public void setRecord(int recordId, byte[] newData, int offset, int numBytes) </li></ul></ul><ul><ul><li>sets new information, a stream of bytes (newData) with offset as its starting index and numBytes as its length, at the record location represented by recordId. </li></ul></ul>String brand = &quot;Toyota&quot;; byte data[] = newappt.getBytes(); r s.setRecord( recID , data, 0, data.length());
  18. 18. Deleting Record <ul><li>The MIDlet invokes the deleteRecord() method to delete a record from the record store. </li></ul><ul><li>public void deleteRecord(int recordId) </li></ul><ul><ul><li>deletes the record represented by recordId. The recordId is not reused. </li></ul></ul>rs .deleteRecord(1);
  19. 19. Record Enumeration <ul><li>The RecordEnumeration (A.K.A enumerator) class provides methods for moving forward and back through a record store. </li></ul><ul><li>you might prefer to enumerate through the records, sorting alphabetically </li></ul><ul><li>Enumeration Implementation </li></ul><ul><li>RecordEnumeration re = rs.enumerateRecords(null,null,false); </li></ul><ul><li>while (re.hasNextElement()) </li></ul><ul><li>{ </li></ul><ul><li>// Get the next record into a String </li></ul><ul><li>String str = new String(re.nextRecord()); </li></ul><ul><li>... do something ... </li></ul><ul><li>} </li></ul>
  20. 20. Record Enumeration <ul><li>Key Methods in enumeration </li></ul><ul><li>>> nextRecord() to move forward </li></ul><ul><li>>>previousRecord() to move back </li></ul><ul><li>>>previousRecord(), whichh will return the last record </li></ul><ul><li>An enumerator maintains in internal index of the record store </li></ul><ul><li>You can make calls to reindex() whenever you update, delete or add a record. </li></ul><ul><li>A record listener can be established to notify you of changes to the record store </li></ul><ul><li>Whenever a change occurs, the listener will call one of three methods, depending on whether the change was an add, delete or update </li></ul>
  21. 21. Record Enumeration-API
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×