节点文献

基于HIBERNATE和AOP的三层架构缓存研究与实现

【作者】 杨鹍

【导师】 罗光春;

【作者基本信息】 电子科技大学 , 计算机应用, 2008, 硕士

【摘要】 随着信息技术的飞速发展,企业信息化建设逐渐被社会各界所关注,并开始在企业的管理运作中发挥着越来越重要的作用。在企业级开发领域中,使用基于J2EE的三层架构将是绝大多数厂商和企业的选择。近年来,在企业级应用开发环境中,面向对象的开发方式己成为主流,而关系数据库是目前使用最广泛的数据库,因此,在开发过程中通常会采用面向对象技术和关系数据库相结合的方式。由于面向对象技术和关系数据理论基于不同的理论基础,使得二者在协同工作时出现不匹配。造成三层架构的可维护性和可移植性比较差。另外一方面,三层架构中的持久层的性能问题也受到越来越多的关注。现有的一些系统在并发访问的规模扩大时,系统的响应时间会陡然增加,不能满足客户的需求,甚至拒绝服务。传统的提高持久层性能的办法不但浪费了大量的人力、物力和财力,而且对企业的创新也是一种束缚。基于上述原因,本文主要对三层架构中的持久层进行了研究。首先,分析了现有持久层对数据库操作的不足,相对于传统的使用JDBC直接写SQL语言,在持久层采用了基于O/R Mapping的Hibernate框架,Hibernate提供轻量级持久框架,提供了对象和数据库模型的一一对应的映射关系,同时还提供了面向对象的查询语言和恢复机制,大大减少操作数据库的工作量,同时还可以使程序员能够随心所欲的使用面向对象编程思想来操作数据库。其次,针对持久层的性能问题,本文对Hibernate的缓存机制做了细致的阐述,Hibernate的缓存介于Hibernate应用和数据库之间,主要用于减少直接访问数据库的频率,从而提高应用的性能。对于经常查询而又不经常改变的表,采用Ehcache在内存和硬盘里面做数据库的缓存,使得数据库的资源得到了增强,数据库不再成为三层架构的瓶颈。最后,针对Hibernate缓存生成的方式,本文提出应该把缓存的生成从持久层中独立出来,由此引入了面向方面编程AOP。本文结合了当前最为流行的J2EE轻量级框架Spring,利用Spring的强项AOP技术,对缓存的生成方式进行了改进,从而改变了缓存在三层架构中的位置。从而进一步的提高的三层架构的性能。

【Abstract】 As the information technology develops quickly, the information construction of enterprise draws more and more attention, and it becomes more and more important in the management of enterprise. 3-tired-architecture is very popular among enterprises, and it is based on J2EE. In recent years, oop pattern became the main stream of enterprise development, at the same time, relation database is being used mostly, so, it is very often to develop both with oop and relation dababase. But as the two technologies are based on different theory, there would be conflicts when they cooperate with each other, which would make the 3-tired-architecture hard to maintain and transfer. On the other hand, the performance of 3-tired-architecture became more and more important. Some present 3-tired-architecture would get much longer reponse delay, can not satisfy request of clients and even deny service when they get many concurrent requests. The traditional method of improving the performance of 3-tired-architecture would waste a lot of human, material and financial resources and also prevent the creation of enterprise.Due to the causes above, researched 3-tired-architecture especially the persistence layer is researched in this paper. First, fault of present persistence layer when it operates the database were analyzed. Then hibernate framework based on O/R mapping is introduced, which would present oop mechanism when we deal with relation database and reduce work greatly.Second, as for the performance of persistence layer, the cache mechanism of hibernate was expouded. Hibernate cache lies between application and database, which is often used to reduce the frequency of accessing database, and thus to improve performance. Ehcache was chosen to store data from database in memory and disk, which would reinforce the database resources and make database the bottleneck of 3 tiered layer no longer.Finally, as for the generation pattern of hibernate cache, it would better to put the cache out of persistence layer. Thus the AOP(aspect oriented programming) technology was introduced. With the most popular J2EE light weight framework Spring, AOP improved the generation pattern of hibernate cache, and changed the position of cache in 3 tiered layer , finally improved the performance of 3 tiered layer.

【关键词】 三层架构持久层HibernateAOP
【Key words】 3-tired-architectureHibernateEhcacheAOP
节点文献中: 

本文链接的文献网络图示:

本文的引文网络