Java Reference
In-Depth Information
Let's look at each of these options.
Retrieving all the data using a single query
A simple approach that works well for small amounts of data is to execute a single
query and store the entire result set as part of the session state either in the server
or the browser.
This approach has the following benefits:
It can be efficient because the application only executes a single database
query.
The application has a consistent view of the database because it executes a
single query.
The main drawback of this approach is that it is only practical when the result set
is small. Executing a query that returns a large result set would be too expensive.
It would be inefficient and impractical for the application to load a large result set
into the application server's memory or send it to the browser. The result set
would occupy too much memory and take too much time to transfer over the net-
work. As a result, this approach is rarely useful.
Retrieving the primary keys
A variation on the first approach is for the application to first execute a query that
retrieves the primary keys of the matching rows and store them as part of the ses-
sion state. The application would then use a separate query to retrieve each page
of data using the primary keys obtained by the first query.
This approach has a number of benefits:
The potentially expensive query that finds the matching rows is only exe-
cuted once.
It reduces the amount of data that needs to be stored as part of the session
state because primary keys are significantly smaller than the data.
It also has several drawbacks:
The database must find all of the matching rows even though the user
might only look at the first few.
If there are a large number of rows, the session state can be large even
though the application only stores the primary keys. The session state will
either require a lot of memory on the server or take a long time to transport
to the client.
Search WWH ::




Custom Search