I'm looking for a little direction on the most appropriate way to access a database from the flow layer.
My application requires read-only access to the database only so an O/R type approach would probably be

What I would like to do in the flow layer is something like the following psuedo code. Do a select query
against the database using a java component.  Test the returned collection to see if it contains any
elements and use that test to determine whether redisplay the current page or to break out of the
recursive loop.

Any suggestions?

function searchCategories(locType, class1, class2) {
    var categories = Search.searchCategories(locType, class1, class2);
    if(categories != null) {
       // if search returned categories, search again on expanded categories
       cocoon.sendPageAndWait("page/showCategories.xml", {"categories" : categories} );
       // when user request arrives
       class1 = cocoon.request.getParameter("class1");
       class2 = cocoon.request.getParameter("class2");
       // recursively calls itself with
       searchCategories(locType, class1, class2);