从网上搜集的RMS知识

1083阅读 0评论2010-04-16 SmileWolf9623
分类:

RMS(Record Management System)MIDP中一个非常重要的子系统,因为它是J2ME应用程序进行持久性存储的唯一途径。在这个包里面总共包 括四个接口、一个类和五个异常。

    RecordStore就相当于一个数据库,必须新建一个这样的数据库才可以开始使用RMS进行存储读取数据。可以使用下面的静态方法static RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary) 

关闭RecordStore使用closeRecordStore()

           (1),获得RecordStore信息

           int getVersion()
           int getSize()
           String getName()
          long getLastModified()

    (2),获得Record信息
         int getNumRecords()
         int getNextRecordID()
         int getRecordSize(int recordId)

    (3),读取记录
           byte[] getRecord(int recordId)
            int getRecord(int recordId, byte[] buffer, int offset)

      (4),添加记录
             int addRecord(byte[] data, int offset, int numBytes)

       (5),更新记录
             setRecord(int recordId, byte[] newData, int offset, int numBytes)

       (6),删除记录
             deleteRecord(int recordId)

         (7),遍历表RecordEnumeration,它可以遍历RecordStore中的数据。
                   RecordEnumeration enumerateRecords(RecordFilter filter, RecordComparator comparator, boolean keepUpdated)

         RecordFilterRecordComparator,用来控制遍历的结果集,可以实现RecordFilter来决定要把什么样的数据筛选出来,通过实现RecordComparator来决定数据的排序。最后的参数keepUpdated,如果设置为true的话,那么它会跟踪RecordStore中的数据变化,建议设置为falseRecordEnumeration相当于一个双向的数据链表。你可以通过调用nextRecordId()previousRecordId()来不停的移动。

 

             (8), 创建可以被共享的RecordStore
static RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary, int authmode, boolean writable)
authmode设置为
     
(9)访问RecordStore
static RecordStore openRecordStore(String recordStoreName, String vendorName, String suiteName) 

       如果另外一个MIDlet Suite中的MIDlet想访问的话,那么它需要知道要访问的MIDlet suitevendorNamesuiteName,一般可以从jad文件中得到这 两个数据。

上一篇:使用工具,还是被工具驱使?
下一篇:学习精减用户界面之法