1 / 15

RMS - Record Management System

RMS - Record Management System. Record Store. En Record er et bytearray af vilkårlig størrelse En RecordStore er et antal Records nummerede 1, 2, 3, ... Når en ny Record indsættes anvendes næste endnu ikke anvendte index (ingen genbrug af indexværdier). Oprette en RecordStore. ...

biana
Download Presentation

RMS - Record Management System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RMS - Record Management System

  2. Record Store • En Record er et bytearray af vilkårlig størrelse • En RecordStore er et antal Records nummerede 1, 2, 3, ... • Når en ny Record indsættes anvendes næste endnu ikke anvendte index (ingen genbrug af indexværdier) ITJEM1/jrt

  3. Oprette en RecordStore ... // Create a record store RecordStore rs = null; try { rs = RecordStore.openRecordStore( "myrs", true ); } catch( RecordStoreException e ){ // couldn't open it or create it } ... ITJEM1/jrt

  4. Indsætte og opdatere Records // Indsætte en ny Record byte[] data = new byte[]{0, 1, 2, 3 }; int recordID; recordID = rs.addRecord(data, 0, data.length); // Opdatere en eksisterende Record int recordID = ...; // some record ID byte[] data = new byte[]{ 0, 10, 20, 30}; rs.setRecord(recordID, data, 1, 2); // replaces all data in record with 10, 20 ITJEM1/jrt

  5. Læse og fjerne Records ... int recordID = .... // some record ID byte[] data = rs.getRecord(recordID); ... ... int recordID = ...; // some record ID rs.deleteRecord(recordID); ... Once a record is deleted, any attempt to use it throws an InvalidRecordIDException. ITJEM1/jrt

  6. Slette en RecordStore ... try { RecordStore.deleteRecordStore("myrs"); } catch(RecordStoreNotFoundException e){ // no such record store } catch(RecordStoreException e){ // somebody has it open } ... ITJEM1/jrt

  7. Flere RecordStore operationer • getLastModified() returns the time of the last modification • getName() returns the name of the record store. • getNumRecords() returns the number of records in the record store. • getSize() returns the total size of the record store, in bytes. • getSizeAvailable() returns the number of bytes available for growth. • getVersion() returns the version number of the record store. ITJEM1/jrt

  8. RMS Exceptions • InvalidRecordIDException is thrown when an operation cannot be performed because the record ID is invalid. • RecordStoreFullException is thrown when no more space is available in the record store. • RecordStoreNotFoundException is thrown when the application tries to open a non-existent record store. • RecordStoreNotOpenException is thrown when an application tries to access a record store that has already been closed. • RecordStoreException is the superclass of the other four, and is thrown for general errors they don't cover. ITJEM1/jrt

  9. Datamapping 1 public void fromByteArray(byte[] data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); _firstName = din.readUTF(); _lastName = din.readUTF(); _phoneNumber = din.readUTF(); din.close(); } public byte[] toByteArray() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout); dout.writeUTF(getFirstName()); dout.writeUTF(getLastName()); dout.writeUTF(getPhoneNumber()); dout.close(); return bout.toByteArray(); } ITJEM1/jrt

  10. Enumerations 1 RecordStore rs = ... // an open record store RecordEnumeration enum = rs.enumerateRecords( filter, comperator, tracking_updates ); ... // use the enumeration here enum.destroy(); // always clean it up! enum.hasNextElement() enum.nextRecordId() enum.nextRecord() osv Rækkefølgen i enum er udefineret ITJEM1/jrt

  11. Enumerations 2 RecordFilter public class MyFilter implements RecordFilter { public boolean matches( byte[] recordData ) { ... // matching code here } } ITJEM1/jrt

  12. Enumerations 3 RecordComparator public class MyComparator implements RecordComparator { public int compare(byte[] r1, byte[] r2){ int salary1 = getSalary(r1); int salary2 = getSalary(r2); if(salary1 < salary2){ return PRECEDES; } else if(salary1 == salary2){ return EQUIVALENT; } else { return FOLLOWS; } } } ITJEM1/jrt

  13. Alternativer • RMS • Filsystem (FileConnection API) • PIM (Personal Information Management API) RMS er tilgængelig på de fleste apparater Filesystem og PIM er ikke så tilgængelige som RMS, og kræver endvidere certificering ITJEM1/jrt

  14. Afsluttende bemærkninger • Alle RMS operationer er trådsikre • Attributten MIDlet-Data-Size (minimumsværdi) bør sættes i såvel jad som manifest filer • Det vil være rart at kunne arbejde på "objektniveau" • Der er behov for at kunne søge effektivt i en RecordStore ITJEM1/jrt

  15. ITJEM1/jrt

More Related