Java Reference
In-Depth Information
consider improving the performance of the query that finds the available restau-
rants. One option is to use the query cache. Enabling caching for this query
might improve performance because
JDO
or Hibernate will then try to get the
results of the query from the query cache instead of executing a
SQL
statement.
However, because there are potentially many combinations of values for the
query's parameters—for example, ZIP code and delivery time—it is unclear
whether there would be any benefit. We would have to analyze the running appli-
cation to determine whether there is any benefit. The query cache can improve
performance of other queries significantly.
By using eager loading, process-level caching, and query caching, you can
often significantly improve the performance of your application. The details
depend on which persistence framework your application uses. You will learn
about those in the next two chapters, but before that we must look at the details of
the example schema.
4.7 The example schema
We have now had an overview of
ORM
and looked at how to write tests and opti-
mize the performance of a persistence layer. The next step is to learn how to per-
sist a domain model using Hibernate and
JDO
. Because I'm going to use the Food
to Go domain model as an example, it will be helpful to look at the database
schema that the application uses. The schema, which is shown in figure 4.5, is
quite similar to the domain model you saw in chapter 3.
It uses many of the ORM techniques you saw earlier in section 4.1. Each of the
main classes in the domain model—
PendingOrder
,
PendingOrderLineItem
,
Order
,
OrderLineItem
,
Coupon
,
Restaurant
, and
MenuItem
—has a corresponding table.
The
Restaurant
-
MenuItem
and
PendingOrder
-
PendingOrderLineItem
relationships,
which are one-to-many relationships, are represented by foreign keys in the
MENU_ITEM
and
PENDING_ORDER_LINE_ITEM
tables, respectively.
Similarly, the
PendingOrder
-
PendingOrderLineItem
, which is a many-to-one rela-
tionship, is represented by a foreign key in the
PENDING_ORDER_LINE_ITEM
table.
A restaurant's ZIP codes—which in Java is a collection of strings and corresponds
to a many-to-many relationship between restaurants and ZIP codes—is represented
by the join table
RESTAURANT_ZIP_CODE
, which has foreign keys to both the
RES-
TAURANT
and
ZIP_CODE
tables.
In the following chapters, this schema is used to illustrate some of the chal-
lenges you will face when trying to Hibernate or
JDO
to persist a domain model.
Search WWH ::
Custom Search