I am developing a multi-level database-based web application - SQL relational database, Java for the middle level of service, web interface for the user interface. Language doesn't really matter.
An average service level performs the actual database query. The user interface simply asks for certain data and has no idea that it supports the database.
The question is, how to handle large data sets? The user interface requests data, but the results can be huge, perhaps too large to fit in memory. For example, a street sign application may have a service level:
StreetSign getStreetSign(int identifier) Collection<StreetSign> getStreetSigns(Street street) Collection<StreetSign> getStreetSigns(LatLonBox box)
The user interface layer requests that all street signs meet certain criteria. Depending on the criteria, the result set can be huge. The user interface layer can split the results into separate pages (for the browser) or simply present them all (serving up to Goolge Earth). A potentially huge set of results can be a performance and resource (memory) issue.
One solution is to not return fully loaded objects (StreetSign objects). Rather, return some result set or iterator that lazily loads each individual object.
Another solution is to change the service API to return a subset of the requested data:
Collection<StreetSign> getStreetSigns(LatLonBox box, int pageNumber, int resultsPerPage)
Of course, the user interface can request a huge set of results:
getStreetSigns(box, 1, 1000000000)
I am curious what is the standard design pattern for this scenario?
java database web-applications lazy-loading resultset
Steve kuo
source share