网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计下载 > 其他类别 > 正文

手机数据库平台的开发Thedevelopmentofmobiledatabaseplatform-其它

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

目   录
1  引言 1
1.1  J2ME的发展 1
1.2  J2ME开发的可行性 1
2  移动数据库的市场 2
2.1  市场调研 2
2.2  市场价值在J2ME中的体现 3
3 移动数据库的总体设计 3
3.1 界面方面 3
3.2   功能技术方面 5
4 移动数据库的具体实现 7
4.1  界面实现 7
4.2  主要功能实现 9
4.3  主要类说明 10
5  部分成果最终展示 14
5.1  界面部分展示 15
5.2  功能部分演示 16
6  项目测试 17
6.1  测试项目 17
6.2  测试内容 17
6.3  测试结果 19
7  设计过程中的问题及解决 19
7.1  在CANVAS中 19
7.2  在记录存储中 20
结论 21
致谢 22
参考文献 23
什么是移动数据库呢?简单地说,数据并不是纯粹地存储在服务器或PC机上的,也可以存放在内存和处理性能受限的移动设备上。这些安装在移动设备上,用来管理和操作数据的系统就是所谓的移动数据库。很多情况下都需要在移动设备上储存一些数据。在移动数据库还没有诞生前,所有的数据都是存放在文件中,当数据量比较大时,对数据进行检索、删除等操作的效率是非常低下的。现在很多公司考虑到移动设备的多样性,普遍使用XML来保存数据,虽然XML是一种和平台无关的文档标准,但是因为当前移动设备的处理能力限制,因此解析一个包含较多数据的XML文件时,其性能的开销是无法满足实际的需求的。而移动数据库之所以能够称为数据库,就是指移动数据库可以包含的数据量可以达到相当程度的规模,而并非少量的数据(几十或几百条记录)可以比拟的。
关键词  移动数据库,移动设备,存储,规模  
 
毕业设计说明书(论文)外文摘要 Title                  The Design of Mobile Database                                           ——The Design of Data Memory                                          Abstract
What is a Mobile Database?Generally specking, the data is really not that memory displacement upper , also being able to store in memory and process a function to be limited in server or PC machine equipment is upper pure. These are assembled on moving equipment, the system being used to manage and handle a data is a so-called mobile data base. Need to store up a few data on moving equipment under many condition. All data all are deposition in the document before the displacement data base does not come into being, think that carrying out the efficiency handling such as search that , deleting on the data is very low when the data amount is comparatively big. Many companies thinks to the diversity moving equipment now , is put into use commonly coming to preserve a data XML, the treatment ability moving equipment because of present although XML is the document standard that one kind and platform are unconcerned with, restricts , whose function expense is to have no way to satisfy actual need''s when therefore analytical one contains more data XML document. But a mobile data base being able to be called a data base, the data amount containing being point to displacement that the data base is not bad can reach the scale being commensurate to degree , not a few data (several tens or several hundreds take notes) can be parallel but.
Keywords  Mobile Database, Move equipment, Memory, Scale
 

4.2  主要功能实现

4.2.1  功能综述

N
开始
管理员登陆
密码正确?
报错
功能界面
各个功能
取消/返回?
上一层界面
选择
Y
N
Y

图4-2  主要功能流程图 说明:首先在开始主程序后有一个过度界面,出现五秒钟后,自动跳转到登陆界面,输入密码和管理员姓名后登陆aList主界面,主界面上有各个功能模块,如:添加车辆信息、按姓名排列、按ID排列、按车牌号码排列、按姓名查询、按ID查询、按车牌查询等,用户可以根据需要选择相应的功能进行必要的操作。

在按姓名排列、按ID排列、按车牌号码排列、按姓名查询、按ID查询、按车牌查询界面上都有一个选择Command用来显示所存储的所有信息。同时也有删除和修改Command,用来随时修改和删除信息。

4.2.2  数据库的相关操作

表4.3  部分类和接口

类/接口说明
RecordStore类表示记录存储
RecordComparator接口用于比较记录存储中的两个记录是否匹配或它们的相对次序的接口
RecordEnumeration接口用于枚举记录存储中的记录,它是双向的
RecordFilter接口用于检查记录存储中的某个记录是否匹配
RecordListener接口用于监听记录存储中的记录的新增、删除、修改事件
记录存储的结构可以用图4-3来表示。在记录存储中的记录都有一个惟一的标识符recordID,这个标识符recordID可用于从记录存储中检索一个记录。加入记录存储中的第一个记录的recordID是1,第二个是2,下一个记录的recordID比上一个记录的recordID多1,采用的是一种单步增长的办法。当一个记录被删除时,对应的recordID不可被重用。如果新加入一个记录,新的记录的recordID将在原来的recordID基础上加1。但在实现上,两个相邻的记录并不一定具有连续的recordID,特别是当有记录被删除时。

recordID:1

recordID:5

 

recordID:3

 

recordID:9

 

……

       图4-3  记录存储的结构

4.3  主要类说明

4.3.1  Canvas画布

Canvas画布绘制游戏中各种图形或图像时,有许多函数可以用来处理图片绘制:

protect abstract void paint(Graphic g);

提供给Canvas类,绘制手机图像显示时运行该方法。但是这个方法不能直接将图像显示到手机上,需要配合其他方法才能将图像真正绘制到手机屏幕上。如:第一个setCurrent()函数运行时就会直接调用该方法来绘制屏幕:

public final void repaint ();

重画手机屏幕的指定范围。X、Y参数值为指定坐标点,而width、height为指定重画的宽度与长度:

public final void repaint (int x, int y, int width, int height) ;

用Graphics类绘制文本是基于锚点的。锚点(anchor point)的作用是放置文本的计算量最小。锚点是一个水平常量(LEFT、HCENTER、RIGHT)同一个垂直常量(TOP、BASELINE、BOTTOM)进行逻辑操作(逻辑或)得到的,默认的锚点是0,说明是使用文本区域的左上角来定位。

4.3.2  RecordStore的管理

当你查阅MIDP API文档的时候,你将略为惊讶的发现,RecordStore并不能通过new来打开或创建一个实例。事实上, RecordStore提供了一组静态方法openRecordStore()来取得实例。这里,你有三个选择:

openRecordStore (String recordStoreName, boolean createIfNecessary);

openRecordStore(String recordStoreName,boolean createIfNecessary,int authmode,boolean writable);

openRecordStore (String recordStoreName, String vendorName, String suiteName);

显然,最复杂(当然,也是最灵活的),是第二种开启方法。它的第一个参数是记录仓储的名称,第二个参数表明了当我们请求的仓储不存在时,是否新建一个Record Store;第三个参数表明了此仓储的读取权限,最后一个参数则决定了写入权限。

当你不在使用一个打开的RecordStore时,记得要关闭它以节约资源。这时,你就需要RecordStore的关闭方法closeRecordStore()。

在记录仓储关闭期间,加载在当前记录仓储上的所有监听器将被消除,记录仓储本身也不能再被调用或遍历,任何试图对RMS采取的操作都会抛出RecordStoreNotOpenException错误。

关闭方法是如此简单,以至于我们有可能忽略这样一个细节:记录仓储在调用closeRecordStore()不会立即被关闭,除非你确信你关闭方法的调用次数与开启方法openRecordStore()的调用次数一样多。也就是说,MIDlet套件需要在RMS的开启与关闭之间保持平衡。

当我们不再需要一个记录仓储的时候,我们就需要deleteRecordStore()来执行删除。一个MIDlet套件只能够删除它自己的记录仓储。在删除之前,我们需要确保当前的仓储是处于关闭状态,如果改仓储仍旧处于开启状态(被自身的MIDlet或者其他套件调用),那么删除记录将导致RecordStoreException异常抛出;如果要删除的仓储记录本身不存在,那么这将会引起RecordStoreNotFoundException异常抛出。

4.3.3  RecordStore的基本操作

a)增加记录

我们可以通过方法addRecord(byte data, int offset, int numBytes)添加byte数组类型的数据。在addRecord中,我们需要提供3个有效参数:byte数组,传入byte数组起始位置,传入数据的长度)。

当数据添加成功后,addRecord将返回记录ID号(RecordID),RecordID在一个RecordStore中中扮演着主键的角色,它由一个简单增长算法产生。例如第一条添加的记录ID是0,第二个是1,以此类推……

如果试图将数据添加到一个未经打开的记录仓储中,将产生RecordStoreNotOpenException异常;任何添加错误都将最终抛出异常RecordStoreException,所以,将它作为最后一个catch块将是一个很好的选择。

添加操作是一个阻塞操作,直到数据被持久的写到了存储器上,对addRecord方法的调用才会返回。同时这个操作也是个原子操作,这意味着多个线程中同时调用addRecord不会产生数据写丢失。但这并不保证读取和写入同时发生时能够读取的自动同步。复杂应用中对应的同步机制是必须的。

b)修改与删除记录

通过方法deleteRecord(int recordId),传入目标记录的ID以后,可以从记录仓储中删除记录。需要注意的是,正如前面提过的记录ID号是不能够被复用的。

如果试图从一个尚未开启的记录仓储中删除记录,将会抛出RecordStoreNotOpenException异常;如果传入的记录ID是无效的,将得到InvalidRecordIDException异常;而异常RecordStoreException则可以用来捕获一般性的仓储错误发生。

通过方法setRecord(int recordId, byte newData, int offset, int numBytes)可以修改一个指定ID的记录值。

修改记录的传入参数包括记录号,其余的与addRecord相同。当仓储没有打开或者传入ID无效时,你会得到与deleteRecord一致的抛出错误. 而异常RecordStoreException同样可以用来捕获一般性的仓储异常。

c)自定义数据类型与字节数组的转换技巧

我们在上面已经提到,针对RecordStore的操作只提供对针对byte数组的服务.而在日常处理中,大部分时候我们遇到的都将是非byte类型。当然,我们可以撰写一些工具方法来完成基本类型(int, char)与byte的相互转换,但我们又将如何解决另一种更常见的问题:自定义数据类型与byte的转换?在这里,向大家介绍一种已经被广泛采用的方法。

要将自定义数据与byte数组相互转换,需要ByteArrayOutputStream,DataOutputStream,ByteArrayInputStream,DataInputStream 4个类的协助,在MIDP的帮助API有对于他们的详细描述。

要写入数据首先要建立一个ByteArrayOutputStream的实例baos,然后将它作为参数传入DataOutputStream的构造函数来产生一个实例dos。dos由一组方便的I/O方法writeXXX方便我们将不同的数据写入流。例如writeInt用于写入int型、writeChar用于写入字符型、writeUTF用于写入一个String等。更多请参考API手册。当写入操作完成后,可以利用baos的toByteArray方法的得到一个byte数组,这个数组含有我们刚刚写入的数据,将它传给addRecord就可以增加一条记录了。最后记住关闭打开的流。

要读入就要利用剩余的两个类ByteArrayInputStream、DataInputStream。首先利用getRecord(int)得到刚刚写入的byte数组。利用得到的byte数组构造一个ByteArrayInputStream的实例bais,然后用DataInputStream包装它,得到一个实例dis。DataInputStream有一组的方便的I/O方法用于读入DataOutputStream对应方法写入的数据。应该注意的是读入顺序和写入顺序应保持一至。同样的不再使用流时,应关闭流以节约资源。

4.3.4  RecordStore的进阶操作

记录仓储类似于一个简单的数据库,不仅仅体现在最基本添加删除操作上,RecordStore同样为开发者提供一定程度的进阶功能,这主要体现在4个接口的使用:RecordComparator,RecordEnumeration,RecordFilter与RecordListener。

a)RecordEnumeration遍历接口

当我们需要走访一个记录仓储中所有记录时,通常的想法是使用一个for循环,利用RecordID来实现遍历。但是,很遗憾,在RMS中,这不是一个好方法。首先,当我们往往无从了解之前存入数据的RecordID;另外,也是最重要的一点,即便RecordID还存在,记录本身也可能已经被删除了,即我们不能保证RecordID对应记录的有效性。

这样的话,我们就需要一些更为有效的方法来走访记录仓储。MIDP规范中提供了一种安全,可靠的走访方式——RecordEnumeration接口。

RecordEnumeration内部没有存放任何记录仓储数据的副本,因此在使用RecordEnumeration读取数据的时候,实际上仍旧是抓取RecordStore之中的数据。RecordEnumeration如同是一个可用RecordID的集合,它甚至可以按我们指定的方式排列记录。

通过对RecordStore实例对象调用enumerateRecords方法来取得一个RecordEnumeration的实例。

在enumerateRecords方法中我们可以传入3个参数:filter,comparator与keepUpdated。当传入的filter不为空时,它将用于决定记录仓储中的哪些记录将被使用;当comparator不为空时,RecordStore将按照我们指定的排列顺序返回。第三个参数决定了当遍历器建立起来以后,是否对记录仓储新的改变做出回应。如果传入true,那么将有一个RecordListener被加入到RecordStore中,使得记录仓储的内容与RecordEnumeration随时保持同步。如果传入false,则可以使得当前遍历更有效率,但所取得的RecordID集合仅仅是调用此方法这个时刻的RecordStore快照。此后对RecordStore所有更改都不会反应在这个集合上。

b)RecordFilter 过滤接口

过滤接口是用来过滤不满足条件的记录的。使用RecordFilter接口必须实现match(byte candidate)方法,当传入byte数据符合筛选条件时,返回true。

c)RecordComparator比较接口

比较器定义了一个比较接口,用于比较两条记录是否匹配,或者符合一定的逻辑关系。使用比较器必须实现方法compare(byte rec1, byte rec2),当rec1在次序上领先于rec2时,返回RecordComparator.PRECEDES;反之则返回RecordComparator.FOLLOWS;如果两个传入参数相等,RecordComparator将返回RecordComparator.EQUIVALENT。

如同过滤器一样,我们设计一个静态类——WordComparator,用以实现RecordComparator接口。

d)RecordListener监听器接口

RecordListener是用于接受监听记录仓储中记录添加,更改或删除记录等事件的接口。它是作用在RecordStore上的。利用RecordStore的addRecordListener方法来注册一个监听器。使用监听器必须实现3个方法:recordAdded,recordChanged与recordDeleted,他们都需要传入两个参数:记录仓储名称recordStroe与记录号recordId。

recordAdded:当一条新的记录被添加到仓储空间的时候,该方法被触发。

recordChanged:当一条记录被修改时使用。

recordDeleted:当一条记录从记录仓储中删除时调用。

需要注意的是,RecordListener是在对记录仓储的操作动作完成以后被调用的!特别在recordDeleted方法中,由于传入的记录已经删除,所在如果再使用getRecord()试图取得刚刚被删除记录的话,将会抛出InvalidRecordIDException异常。

 






Directory
1 INTRODUCTION 1
1.1 J2ME development of a
1.2 J2ME development of the feasibility of a
2 mobile database market for two
2.1 Market Research 2
2.2 The market value of the expression 3 in the J2ME
3 Mobile Database Design 3
3.1 interface connection 3
3.2 The technical aspects of functional 5
4 mobile database concrete realization of 7
4.1 interfaces 7
4.2 Major Features 9
4.3 The main class note 10
Part 5 of the final results show 14
5.1 interface, part of the show 15
Demo 5.2 functional part 16
6 Project Test 17
6.1 Test Item 17
6.2 Test Content 17
6.3 Test Results 19
7 design process, problems and solutions 19
7.1 CANVAS, 19
7.2 in the record store 20
Conclusion 21
Thanks 22
References 23
What is a mobile database it? Simply put, the data is not only stored on a server or PC, they can also be stored in memory and processing power constrained mobile devices. Those installed on the mobile device, used to manage and operate the data system is the so-called mobile database. In many cases, need to store some data on mobile devices. In the mobile database, not yet born, all of the data is stored in the file, when larger than the data, the data retrieval, delete and other operations efficiency is very low. Many companies are now taking into account the diversity of mobile devices, the widespread use of XML to store data, while XML is a sort of platform-independent documentation standards, but because the current handling capacity constraints of mobile devices, so parsing an XML file that contains more data , its performance overhead is unable to meet the actual demand. The reason can be called a database, mobile database, mobile database refers to the amount of data that can be included to achieve a considerable degree of scale, rather than a small amount of data (tens or hundreds of records) can be compared.
Key words mobile databases, mobile devices, storage, size of
 
Graduation Project Manual (Thesis) foreign Abstract Title The Design of Mobile Database - The Design of Data Memory Abstract
What is a Mobile Database? Generally specking, the data is really not that memory displacement upper, also being able to store in memory and process a function to be limited in server or PC machine equipment is upper pure. These are assembled on moving equipment, the system being used to manage and handle a data is a so-called mobile data base. Need to store up a few data on moving equipment under many condition. All data all are deposition in the document before the displacement data base does not come into being, think that carrying out the efficiency handling such as search that, deleting on the data is very low when the data amount is comparatively big. Many companies thinks to the diversity moving equipment now, is put into use commonly coming to preserve a data XML , the treatment ability moving equipment because of present although XML is the document standard that one kind and platform are unconcerned with, restricts, whose function expense is to have no way to satisfy actual need''s when therefore analytical one contains more data XML document. But a mobile data base being able to be called a data base, the data amount containing being point to displacement that the data base is not bad can reach the scale being commensurate to degree, not a few data (several tens or several hundreds take notes) can be parallel but.
Keywords Mobile Database, Move equipment, Memory, Scale
  
4.2 Major Features

4.2.1 Functional Overview

N
Start
Administrator Login
Password is correct?
Baocuo
Function Interface
Various functional
Cancel / Return?
On the layer interface
Choose
Y
N
Y

Figure 4-2 shows flow chart of the main functions: First, at the beginning of the main program interface after an over, there five seconds, automatically jump to the login interface, enter the password and the administrator login aList after his name the main interface, the main interface, there are the various functional modules, such as: add the vehicle information, arranged by name, by ID order, arranged by license plate number, query by name, by ID check, according to license plate check, the user can select the appropriate functions necessary to operate .


In the Sort by name, by ID order, arranged by license plate number, query by name, by ID check, according to license plate query interface Command has a choice to display all the information stored. Also have to delete and modify Command, is used to modify, and delete information at any time.

4.2.2 Database-related operations

Table 4.3 Some classes and interfaces

Class / interface description
RecordStore class represents the record store
RecordComparator interface used to compare records stored in the two records match or their relative order of the interface
RecordEnumeration interface to enumerate the records in the record store, it is a two-way
RecordFilter interface used to check a record store records match
RecordListener interface for monitoring records in the record store to add, delete, modify the event

Record storage structure can be expressed in Figure 4-3. Records in the record store has a unique identifier recordID, this identifier recordID from the record store can be used to retrieve a record. Add record store the first record of recordID is 1, the second is 2, the next record recordID a record of the previous recordID more than 1, used is a single-step growth approach. When a record is deleted, the corresponding recordID not be reused. If you add a new record, new record of recordID will be on the basis of the original recordID plus one. However, the realization, the two adjacent track record is not necessarily continuous recordID, especially when there are records are deleted.

recordID: 1
 
recordID: 5


 
recordID: 3


 
recordID: 9


 

 
       
Figure 4-3 record storage structure

4.3 Main Class Description

4.3.1 Canvas canvas

Canvas canvas rendering the game a variety of graphics or images, there are many functions can be used to handle image rendering:

protect abstract void paint (Graphic g);

Provided to the Canvas class, draw the image display when the phone is running the method. However, this method does not directly image display on mobile phones and in line with other methods in order to really draw the image to the phone screen. Such as: the first one setCurrent () function, the runtime will call this method directly to draw the screen:

public final void repaint ();

Redraw the specified range of mobile phone screens. X, Y coordinates of the points for the specified parameter value, while the width, height re-painting for the specified width and length:

public final void repaint (int x, int y, int width, int height);

Draw the text with the Graphics class is based on the anchor. Anchor (anchor point) is the role of the calculation of the amount of text placed on the minimum. Anchor is a level constant (LEFT, HCENTER, RIGHT) with a vertical constants (TOP, BASELINE, BOTTOM) logical operations (logical or) received, the default anchor point is 0, indicating the use of text in the upper left corner of the region to location .

4.3.2 RecordStore Management

When you access MIDP API documentation, you will be somewhat surprised to discover, RecordStore and can not to open or create a new instance. In fact, RecordStore provides a set of static methods openRecordStore () to get an instance. Here, you have three choices:

openRecordStore (String recordStoreName, boolean createIfNecessary);


openRecordStore (String recordStoreName, boolean createIfNecessary, int authmode, boolean writable);


openRecordStore (String recordStoreName, String vendorName, String suiteName);


Clearly, the most complex (of course, is also the most flexible), is the second open method. Its first parameter is the name of the record storage, the second argument shows that when we ask the storage does not exist, does it create a new Record Store; third parameter indicates read permission to this warehouse, the last parameter determines the a write access.

When you are not using an open RecordStore, remember to close it to conserve resources. At this time, you will need to RecordStore closure method closeRecordStore ().

In the records storage and the closure period, loaded warehouse in the current record of all listeners will be eliminated, records storage itself can no longer be called or traversal, any attempt to take action on the RMS error will be thrown RecordStoreNotOpenException.

Close method is so simple, so that we may overlook such a detail: Record Storage calling closeRecordStore () will not immediately be closed, unless you are sure you close the method calls the number and open the way openRecordStore () call as many times. In other words, MIDlet suites need to RMS between the opening and closing balance.

When we no longer need a record of storage time, we need to deleteRecordStore () to perform the deletion. A MIDlet suite can only delete the record of its own warehouse. In the deletion, we need to ensure that the current warehouse is in a closed state, if the change is still in the warehouse to open state (by itself or other MIDlet suite is called), then delete the records will result in an exception thrown RecordStoreException; if you want to delete the storage record itself does not exist, then this will cause RecordStoreNotFoundException exception thrown.

4.3.3 RecordStore the basic operation of

a) increase the record

We can approach addRecord (byte data, int offset, int numBytes) Add a byte array type of data. The addRecord, we need to provide three effective parameters: byte array, the incoming byte array of the starting position, the incoming data length).

When the data to add successful, addRecord will return records ID numbers (RecordID), RecordID in a RecordStore play a primary key in the role, which consists of a simple growth algorithm generates. For example, the first to add a record ID is 0, the second one, and so on

If you try to add data to a record without the open storage, you will generate RecordStoreNotOpenException anomaly; any added errors will eventually throw an exception RecordStoreException, therefore, be it as the last catch block would be a good choice.

Add operation is a blocking operation, until the data is written to the persistent memory on the right addRecord method call will return. At the same time this operation is also atomic operation, which means that multiple threads simultaneously calling addRecord not have to write the data is lost. But this does not guarantee simultaneous read and write when you can read the automatic synchronization. Complex applications in the corresponding synchronization mechanism is necessary.

b) modify and delete records

Through the method deleteRecord (int recordId), after the incoming target record ID, you can delete records from the record storage. Note that, as mentioned earlier the record ID numbers can not be re-used.

If you try to record from a warehouse not open to delete records, an exception will be thrown RecordStoreNotOpenException; if the incoming record ID is invalid, an exception will be InvalidRecordIDException; while abnormal RecordStoreException can be used to capture the general storage error occurred.

Through the method setRecord (int recordId, byte newData, int offset, int numBytes) can modify the value of a specified record ID.

Modify the recorded incoming parameters include the record number, and the rest the same as with addRecord. When the warehouse is not open, or pass ID is invalid, you will get the same throw with deleteRecord errors. The exception RecordStoreException can also be used to capture general warehousing exception.

c) Self-defined data types and byte array conversion technique

We have already mentioned above, for the operation of RecordStore only right for the byte array of services. But in the daily processing, most of the time we encountered would be a non-byte type. Of course, we can write a number of ways to complete the basic types of tools (int, char) and the byte mutual conversion, but how will we solve another, more common problems: Self-defined data types and byte conversion? Here has been to introduce a widely used method.

To customize the data and convert between byte array needs to ByteArrayOutputStream, DataOutputStream, ByteArrayInputStream, DataInputStream 4 classes with the assistance, in the MIDP the help of API has a detailed description for them.

To write the data to create a ByteArrayOutputStream first instance of baos, and then it passed as a parameter DataOutputStream constructor to generate an instance of dos. dos by a group of convenient I / O method writeXXX convenience we will write different data streams. For example, writeInt for writing int type, writeChar used to write character, writeUTF used to write a String and so on. For more please refer to API manual. When the write operation is complete, can take advantage of baos of toByteArray method to get a byte array, the array contains the data we have just written, it would be passed to addRecord will be raised by a record. Finally remember the closure of the open stream.

Necessary to read into the use of the remaining two classes ByteArrayInputStream, DataInputStream. The first to use getRecord (int) to be just a byte array to write. Get byte array using a ByteArrayInputStream constructed instance of bais, and then use DataInputStream packaging it, and get an instance of dis. DataInputStream have a group of convenient I / O method is used to read the corresponding method of DataOutputStream to write data. It should be noted that the reading order and the order should be kept one to write. The same stream is no longer used, they should close the stream in order to conserve resources.

4.3.4 RecordStore Advanced Operation

Records storage is similar to a simple database, not only reflected in the most basic to add delete operation, RecordStore the same for the developer to provide a degree of advanced functionality, which is mainly reflected in the use of four interfaces: RecordComparator, RecordEnumeration, RecordFilter and RecordListener .

a) RecordEnumeration traversal interface

When we need to visit a record of all the records storage, usually the idea is to use a for loop, using RecordID to achieve traverse. However, it is regrettable that, in the RMS, this is not a good idea. First of all, when we are unable to understand the data before the stored RecordID; In addition, the most important point, even if there RecordID recording itself may have been deleted, RecordID that we can not guarantee the validity of the corresponding record.

In this case, we need some more effective ways to visit the records storage. MIDP specification provides a safe and reliable way to visit - RecordEnumeration interface.

RecordEnumeration does not store any records of internal storage and a copy of the data, so the use of RecordEnumeration read data when, in fact is still crawling RecordStore among data. RecordEnumeration as if it were a collection of available RecordID, it can even be arranged according to our records of the specified manner.

An instance of an object by RecordStore call enumerateRecords method to obtain a RecordEnumeration example.

The enumerateRecords method, we can pass three parameters: filter, comparator and keepUpdated. When the incoming filter is not empty, it will be used to determine which records in the records storage will be used; when the comparator is not empty, RecordStore will be specified in the order in accordance with our return. The third parameter determines when the walker set up after the record whether the storage to respond to new changes. If you pass true, then there will be a RecordListener been added to the RecordStore, making the content of records storage to keep pace with the RecordEnumeration at any time. If you pass false, you can make the current traversal more efficient, but the RecordID obtained a collection of this method is only called a snapshot of this moment RecordStore. After all the changes to the RecordStore will not be reflected in the sets.

b) RecordFilter filter interface

Filter interface is used to filter the records do not meet the conditions. RecordFilter interface must be implemented using the match (byte candidate) methods, when the incoming byte of data that match the filter conditions, return true.

c) RecordComparator Comparison of interface

Comparator defines a relatively interface, used to compare two records match, or meet certain logic. Using the comparator must implement the method compare (byte rec1, byte rec2), when the rec1 in the order when leading at the rec2 return RecordComparator.PRECEDES; the contrary is returned RecordComparator.FOLLOWS; if the two incoming arguments are equal, RecordComparator will return RecordComparator.EQUIVALENT.

As filters, we design a static class - WordComparator, used to achieve RecordComparator interface.

d) RecordListener listener interface

RecordListener is used to accept record storage and monitoring records to add, change, or delete records events such as the interface. It is the role of the RecordStore on. The use of RecordStore of addRecordListener method to register a listener. Using the listener must implement three methods: recordAdded, recordChanged with recordDeleted, they need to pass two parameters: the name of recordStroe record storage and record number recordId.

recordAdded: When a new record is added to the storage space of time, the method is triggered.

recordChanged: When a record is modified to use.

recordDeleted: When a record removed from the record when you call the warehouse.

Note that, RecordListener storage of records in the action after the completion of the operation was called! Particularly in the recordDeleted method, due to the incoming record has been deleted, the host if the re-use getRecord () attempts to obtain records has just been removed, it will throw an exception InvalidRecordIDException.

设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师