资源说明:This project revolves around developing an optimization technique to improve the responsiveness of iBATIS cache by introducing the notion of a cache warming harness in iBATIS framework. iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java. It allows programmers to map the parameters and results between the class properties and the columns of a database table. It also provides support to load properties that represent composite objects. However, this results in the classic N+1 query problem. Though iBATIS provides a way to cache the mapped statement, the default iBATIS cache models are not sufficient to solve the N+1 problem as it caches data only on demand and each unique cache miss is costly. The problems of different cache strategies are initially studied and an enhanced cache design for iBATIS is proposed and implemented in this dissertation. The experimental results showed that the proposed cache design outperformed the default cache model of iBATIS framework in terms of responsiveness and solved the N+1 query problem by incurring that cost upfront at application load time.
See http://balak1986.github.com/prime-cache-support-in-ibatis2 for better look.
CHAPTER 1
Introduction
1.1 Overview
iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java. It allows programmers to map JavaBeans objects to PreparedStatement parameters and ResultSets. It uses XML descriptors to map JavaBeans to SQL statements. In iBATIS, Result Maps finish the job by mapping the result of a database query (a set of columns) to object properties. It is possible to load properties that represent composite objects by associating a result map property with a mapped statement that specifies how to load the appropriate data and class for complex property. The results from a query mapped statement can be cached by iBATIS cache model.
The problem with populating properties of fully-formed complex type is that whenever iBATIS load a complex type, two SQL statements are actually being run (one for composite object and one for its complex property). This problem seems trivial when loading a single composite object, but if we were to run a query that loaded N composite objects, a separate query would be run for each composite object to load its complex property. This results in N+ 1 query in total: one for the list of composite object and one for each composite object returned to load each related complex property.
The result set might have N objects, but there might only be M (where M
Cache model configuration
Figure 3: The static structure of the primed cache design
PrimeCachingStatement holds the reference to mapped statement that needs to be executed to load data for primed cache. When user set primedCache attribute to true, it is mandatory to set primedCacheQuery attribute of select element that want to take advantage of primed cache. The primedCacheQuery attribute specifies which query needs to be run to warm the cache.