当前在系统设计开发过程中,面向对象设计开发方式和关系型数据库被普遍的采用。这种在面向对象的设计开发过程中使用关系型数据库的方式,造成了所谓的“阻抗不匹配”。“阻抗不匹配”的产生原因是在面向对象的设计和开发过程中,在程序里面以硬编码SQL的方式来操作数据库,造成了对象数据和关系数据之间的数据结构以及操作方式的不一致。解决“阻抗不匹配”是对象/关系映射模型产生的原因。现存的对象/关系映射模型在对象查询检索过程中会导致大量消耗系统内存,这种缺陷产生的原因是由于从数据库中检索到的对象的所有属性并不完全被系统所使用,尤其是在大量对象从数据库中检索出来的时候。本文提出了一种面向对象的方式来解决这种缺陷,这种解决方式改造了当前的对象/关系映射框架的检索方法参数,通过使用新的参数代替老的参数,可以携带更多的信息,从而实现对象属性的传递,最终控制对象/关系映射框架提交到数据库的查询语句中的SELECT字段数量,从而解决了这种缺陷。本改进方式采用反射的机制来对传递的参数进行处理,通过反射机制,映射框架内部可以得到对象属性的元数据信息,通过这些属性的元数据信息,就可以构造SELECT语句中的检索字段。本改进方案具有一些优点:采用纯面向对象方式改进、对映射框架改动不大但是效果明显、可以用于改进任何的映射框架。现存的基于对象/关系映射模型的框架系统有Hibernate、JDO、EJB ENTITY BEAN等系统。Hibernate和JDO属于比较成熟的映射框架,EJB 3.0中的ENTITY BEAN框架是一种全新的对象/关系映射解决方案,它采用了诸如:注释、依赖注入、POJO、改进的查询语言EJB-QL等新技术,它代表了今后对象/关系映射模型的发展趋势,本文研究了它的这些新特性,并分析了它对其他框架的优势。本文用对象/关系映射模型实现了一个电子商务系统的数据层,并给出了具体的实现方法和核心代码。通过使用映射模型,代码量减少了1/3,提高了开发效率,并且由于开发人员不必在面向对象思维与面向关系思维中切换,大大降低了出错的机率。
The Object-Oriented Design Development (OOD) and Relational Database Management System (RDBMS) are widely used in system design and development nowadays. Using RDBMS in OOD can result in the so-called impedance not matching. The reason for it is that the software codes manipulate the database using the traditional hard coding method in OOD process. The Object/Relation Mapping framework can resolve this problem. There is a weakness in O/R MAPPING framework. The weakness can increase memory consumption in the objects queries process. The reason for this weakness is that not all of the properties of an object are used, and many of the properties are useless in some functions. The weakness will be serious when the number of objects which take part in a query process is large. In this paper, an object-oriented method is brought out to resolve the problem.The method replaces the parameter of the query function with new one which uses Ojbect type instead of Class type.The Object type can take more information such as Class type and property data. In order to get the properties data, the method adopts Reflection. When the properties data are acquired, the framework can use them to build SELECT SQL languages to query the databases.The advantage of this method: object-oriented, little change in the framework, can be used in any framework.There are some frameworks based on Object/Relation Mapping, Hibernate, JDO and EJB ENTITY BEAN etc. ENTITY BEAN 3 is a newer framework, it uses many new technologies: annotation, dependency injection, POJO and new EJB-QL, and it will be a leader framework in the future.In this paper, a B2C system using O/R MAPPING is shown in some core codes. After using O/R MAPPING, lines of the code decreases 1/3, development efficiency is higher, and the risk of mistake is decreased.