RMS concept analysis and use guide

xiaoxiao2021-03-06  42

RMS (Record Management System) is a very important subsystem in the MIDP because it is the only way for J2ME applications for persistent storage. Of course, if your system supports JSR75, then you can use FileConnection to operate files, which exceeds the scope of this article. Persistent storage often uses when we write applications, such as a list of records, and records usernames and passwords entered. This article will be introduced primarily from the basic concepts of RMS and the guidelines for the purpose of which are dedicated to readers.

RMS is first proposed in MIDP 1.0, and its package is javax.microedition.rms, including four interfaces, one class, and five exceptions in this package. This shows that the RMS design is very small, which is to meet the resource resource resource resource resource. Let's first figure out a few concepts.

What is a persistent storage? A simple understanding of persistence storage is that the data is not lost due to the exit of the program. Generally, the variables we declared in the program are stored on the Stack or HEAP. After the program exits, this data is cleared to release resources. The data stored in the RMS will not be cleared. Where is RMS data storage? There is no statement in the MIDP specification that RMS must be stored, but it is implemented by the manufacturer. Generally stored in non-volatile memory space. So this is transparent to programmers. What is the minimum capacity of RMS? When the manufacturer implements the RMS in MIDP, the supplied storage space cannot be less than 8KB, such as the RMS space of the author's NOKIA 6108 is 30KB. If the RMS is stored according to Record, is the ID equal to the index? The difference between ID and index is still very large, the ID is counted from 1, which is different from the number of 0 start counts from the array. The ID may be discontinuous, and then the corresponding ID will become invalid after a ID tag of Record is deleted. ID is not reused. Does RMS have specific requirements for storage in the data format stored? The answer is not, as long as the data can be converted to byte [] The data can be stored in the RMS, and it is still byte when the removed is removed. So this requires our developers to depict data, because RMS is only responsible for writing and reading data according to byte []. Can RecordStore be shared in a MIDlet kit? Can the RecordStore in a MIDLET kit can be accessed by another RecordStore? It is not possible in MIDP 1.0, and the sharing mechanism is introduced in MIDP 2.0 and can be implemented by sharing.

The above situation summarizes the basic concepts you need to pay attention to in RMS. Let's take a look at how to use RMS. Generally, beginners will usually be gave to how to get started by their methods, because many ways look very similar. Here I have conducted the following summary, providing some guidance to everyone.

First readers should clear that RecordStore is equivalent to a database, you must create a new database to start using RMS to store read data. New RecordStore is very simple, you can use the following static methods. static RecordStore openRecordStore (String recordStoreName, boolean createIfNecessary) recordStoreName should be noted that not more than 32-bit Unicode characters, case sensitive and in which the MIDlet suite is unique, boolean type createIfNecessary behind said time if the flag is true, Then create it if the RecordStore does not exist. Close RecordStore uses ClosRecordStore (). Another important concept in RMS is RECORD, which is like a line of data in a row in the database. Below we first distinguish the methods in the RecordStore, some are somewhat use of the RecordStore information is used to get Record information. Get RecordStore Information Int getVersion () int getSize () String getName () long getLastModified () Get Record Information INT GetNumRecords () int getNextRecordId () int GETRECORDSIZE (Int Recordid)

Here is how to operate the RECORD, mainly including add, modify, read, and delete.

Read Record BYTE [] GetRecord (int RecordiD) INT GETRECORD (int RecordID, Byte [] Buffer, int offset Add Record Int AddRecord (Byte [] Data, INT Offset, INT Numbytes Update Record SETRECORD (int Recordid, Byte ] NewData, INT Offset, Int NumBytes Delete ReeleteRecord (Int Recordid)

As we mentioned in front of the ID and INDEX, because the ID may not continue, how can we traverse data? Many people may think of using for loops, but because the ID may not be continuous, then this result is unpredictable. The program is likely to fail. It is because of this reason, providing an important interface Recorder in RMS. It can traverse data in the RecordStore. Let's take a look at the way below. RecordEnumeration enumerateRecords (RecordFilter filter, RecordComparator comparator, boolean keepUpdated) In this method also includes two additional interfaces RecordFilter and RecordComparator RMS is, they are used to custom-tailor traversal of the result set, you can decide to implement RecordFilter Put what kind of data is screened and determine the sort of the data by implementing RecordComparator. The last parameter Keepupdated, if set to true, then it will track the data changes in the RecordStore, and will reflect the results of our list, you know this is a very good resource operation, it is recommended to set it to false. Recordenumeration is equivalent to a two-way data linked list. You can keep moving by calling nextRecordID () and PreviouSrecordID (). Other methods about Recordenumeration readers can refer to Java DOC for learning.

The last point needs to be explained is the sharing mechanism, which is the new feature provided in MIDP 2.0. Allows the RecordStore in a kit to be accessible by another, of course, this is to be in an authorized mode. First we look at the schematic if the MIDlet Suite1 is created, the authorization mode is Authmode_any, then other kits may access the RecordStore1, such as MIDlet suite2 in the figure above. Usually such access is accomplished by two steps.

Creating RecordStore, which can be shared, we can implement the following method, you must set the AuthMode to Authmode_any. static RecordStore openRecordStore (String recordStoreName, boolean createIfNecessary, int authmode, boolean writable) access RecordStore if another MIDlet Suite in the MIDlet want to access, then it needs to know MIDlet suite to access the vendorName and suiteName, generally we can from jad file These two data are obtained. I use the following method, Static RecordStore OpenRecordStore (String Vendormename, String vendorname, String Suitename)

转载请注明原文地址:https://www.9cbs.com/read-55993.html

New Post(0)