Presentation is loading. Please wait.

Presentation is loading. Please wait.

01.11.2007 - BA1 RMS - Record Management System. 01.11.2007 - BA2 Record Store En Record er et bytearray af vilkårlig størrelse En RecordStore er et antal.

Similar presentations


Presentation on theme: "01.11.2007 - BA1 RMS - Record Management System. 01.11.2007 - BA2 Record Store En Record er et bytearray af vilkårlig størrelse En RecordStore er et antal."— Presentation transcript:

1 BA1 RMS - Record Management System

2 BA2 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)

3 BA3 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 }...

4 BA4 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

5 BA5 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.

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

7 BA7 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.

8 BA8 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.

9 Datamapping BA9

10 Datamapping 2 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(); } BA10

11 Datamapping 3 public void fromByteArray(byte[] data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); fromDataStream(din); din.close(); } public byte[] toByteArray() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout); toDataStream(dout); dout.close(); return bout.toByteArray(); } BA11

12 Datamapping 4 public void fromDataStream(DataInputStream din) throws IOException { _firstName = din.readUTF(); _lastName = din.readUTF(); _phoneNumber = din.readUTF(); } public void toDataStream(DataOutputStream dout) throws IOException { dout.writeUTF(getFirstName()); dout.writeUTF(getLastName()); dout.writeUTF(getPhoneNumber()); } BA12

13 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 BA13

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

15 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; } BA15

16 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 BA16

17 BA17 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

18 BA18


Download ppt "01.11.2007 - BA1 RMS - Record Management System. 01.11.2007 - BA2 Record Store En Record er et bytearray af vilkårlig størrelse En RecordStore er et antal."

Similar presentations


Ads by Google