计算机专业论文译文spring框架内容摘要:

approach, before deciding to take the effort and risk of building a similar infrastructure inhouse. Much of the O/R mapping support, no matter what technology you39。 re using may be used in a library style, as everything is designed as a set of reusable JavaBeans. Usage inside an ApplicationContext does provide additional benefits in terms of ease of configuration and deployment。 as such, most examples in this section show configuration inside an ApplicationContext. Some of the the benefits of using Spring to create your O/R mapping DAOs include: Ease of testing. Spring39。 s inversion of control approach makes it easy to swap the implementations and config locations of Hibernate SessionFactory instances, JDBC DataSources, transaction managers, and mapper object implementations (if needed). This makes it much easier to isolate and test each piece of persistencerelated code in isolation. Common data access can wrap exceptions from you O/R mapping tool of choice, converting them from proprietary (potentially checked) exceptions to a mon runtime DataAccessException hierarchy. This allows you to handle most persistence exceptions, which are nonrecoverable, only in the appropriate layers, without annoying boilerplate catches/throws, and exception declarations. You can still trap and handle exceptions anywhere you need to. Remember that JDBC exceptions (inc luding DB specific dialects) are also converted to the same hierarchy, meaning that you can perform some operations with JDBC within a consistent programming model. General resource management. Spring application contexts can handle the location and configuration of Hibernate SessionFactory instances, JDBC DataSources, iBATIS SQL Maps configuration objects, and other related resources. This makes these values easy to manage and change. Spring offers efficient, easy and safe handling of persistence resources. For example: Related code using Hibernate generally needs to use the same Hibernate Session for efficiency and proper transaction handling. Spring makes it easy to transparently create and bind a Session to the current thread, either by using an explicit 39。 template39。 wrapper class at the Java code level or by exposing a current Session through the Hibernate SessionFactory (for DAOs based on plain Hibernate3 API). Thus Spring solves many of the issues that repeatedly arise from typical Hibernate usage, for any transaction environment (local or JTA). Integrated transaction management. Spring allows you to wrap your O/R mapping code with either a declarative, AOP style method interceptor, or an explicit 39。 template39。 wrapper class at the Java code level. In either case, transaction semantics are handled for you, and proper transaction handling (rollback, etc) in case of exceptions is taken care of. As discussed below, you also get the benefit of being able to use and swap various transaction managers, without your Hibernate/JDO related code being affected: for example, between local transactions and JTA, with the same full services (such as declarative transactions) available in both scenarios. As an additional benefit, JDBCrelated code can fully integrate transactionally with the code you use to do O/R mapping. This is useful for data access that39。 s not suitable for O/R mapping, such as batch processing or streaming of BLOBs, which still needs to share mon transactions with O/R mapping operations. To avoid vendor lockin, and allow mixandmatch implementation strategies. While Hibernate is powerful, flexible, open source and free, it still uses a proprietary API. Furthermore one could argue that iBATIS is a bit lightweight, although it39。 s excellent for use in application that don39。 t require plex O/R mapping strategies. Given the choice, it39。 s usually desirable to implement major application functionality using standard or abstracted APIs, in case you need to switch to another implementation for reasons of functionality, performance, or any other concerns. For example, Spring39。 s abstraction of Hibernate transactions and exceptions, along with its IoC approach which allows you to easily swap in mapper/DAO objects implementing data access functionality, makes it easy to isolate all Hibernatespecific code in one area of your application, without sacrificing any of the power of Hibernate. Higher level service code dealing with the DAOs has no need to know anything about their implementation. This approach has the additional benefit of making it easy to intentionally implement data access with a mixandmatch approach (. some data access performed using Hibernate, and some using JDBC, others using iBATIS) in a nonintrusive fashion, potentially providing great benefits in terms of continuing to use legacy code or leveraging the strength of each technology. The Spring transaction abstraction Spring provides a consistent abstraction for transaction management. This abstraction is one of the most important of Spring39。 s abstractions, and delivers the following benefits: Provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, iBATIS。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。