Java Reference
In-Depth Information
and its line items from the PersistenceManagerFactory -level cache when the
application navigates to them.
5.4.3
Using a query cache
The PersistenceManagerFactory -level cache optimizes the loading of individ-
ual objects but, by default, queries still go to the database. To improve query per-
formance, some JDO implementations also provide a query cache that caches the
results of a query and avoids the need to execute a SQL SELECT statement. The
query cache is used in conjunction with the PersistenceManagerFactory -level
cache. It caches the ID s of the objects returned by the query, which are then used
to find the objects in the PersistenceManagerFactory -level cache. A query is
dropped from the cache when an instance of a class that is accessed by the query
is modified.
Overview of the query cache
The details of the query cache depend on the JDO implementation. For example,
the Kodo JDO query cache is enabled by default if the data cache is enabled but can
be disabled by setting the kodo.QueryCache PersistenceManagerFactory prop-
erty to false . If the query cache is enabled, it can be turned off for a Persistence-
Manager by calling KodoPersistenceManager.setQueryCacheEnabled(false)
and turned off for a query by calling KodoQuery.setQueryCacheEnabled-
(false) . You also need to remember that the query cache is ignored in some sit-
uations. For example, the query cache is not used during pessimistic transactions
(see chapter 12 for a description of pessimistic transactions) because Kodo JDO
must go to the database to lock the rows.
Using the query cache for the Place Order use case
For the Place Order use case, the queries that could be cached are those executed
by RestaurantRepository.isRestaurantAvailable() and findAvailable-
Restaurants() . However, there are potentially many combinations of values for
each query's parameters - zipCode , and deliveryTime —so it is unclear whether
caching them would be advantageous. We would have to analyze the running
application to determine whether there is any benefit.
5.5 Summary
JDO 2.0 is a standard ORM framework that is comparable in power to Hibernate. It
provides mostly transparent persistence for POJO s, and a typical domain model can
 
 
 
 
 
 
 
Search WWH ::




Custom Search