Sometimes applications access data in a tabular fashion, such as when browsing a catalog or a list of names or when exporting data in batches for use elsewhere. This kind of data access is usually read-only. In such situations, using entity beans to represent persistent data incurs overhead and provides little benefit. Entity beans are best for coarse-grained access to individual business entities, and are not effective for read-only access to large quantities of tabular data.
The Fast Lane Reader design pattern provides a more efficient way to access tabular, read-only data. A fast lane reader component directly accesses persistent data using JDBCTM components, instead of using entity beans. The result is improved performance and less coding, because the component represents data in a form that is closer to how the data are used.
CatalogHelper
,
together with DAO class
CatalogDAO
. Figure 1 below shows
a structure diagram of
CatalogHelper acting as a
fast lane reader, along with associated classes.
|
| Figure 1. The CatalogHelper acting as fast lane reader |
CatalogHelper has a boolean property
useFastLane
that indicates whether or not to use the Fast Lane Reader pattern.
If
useFastLane is true, the
CatalogHelper
implements most of its methods to the
CatalogDAO of
the same name; if it is false,
CatalogHelper delegates
the call to the corresponding method of
CatalogEJB
. The code sample
below shows the
CatalogHelper calling the appropriate
method depending on whether
useFastLane is true.
public Page getCategories()
throws CatalogException {
return useFastLane
? getCategoriesFromDAO(start, count, locale)
: getCategoriesFromEJB(start, count, locale);
}
By using the Fast Lane Reader pattern,
CatalogHelper
can improve performance by avoiding using enterprise beans.
The sample application provides these two options primarily for illustration purposes. In an actual production application, the architecture would either use a fast lane pattern or it would not, instead of providing a runtime choice.