Getting the results from a Finder method a chunk at a time

Discussions

EJB design: Getting the results from a Finder method a chunk at a time

  1. For example, a client initiates a find operation and views results 1-20. Then, some time later, sends a request for results 21-40.

    Should the matching primary keys be cached? How? And who should do the caching and calculation of the sublist--a stateful session bean, or the client?

    In our case, the "client" happens to be a servlet, so we could do the caching there.

    These are just a few questions to get the conversation started.

    Thanks,
    Kevin
  2. There are a variety of ways you could handle this. Some options are:

    1) Don't cache the PK's.
       In this scenario, you supply limiting criteria to your ejbFinder methods, thus your finders will only return one subset at a time. This is the least resource intensive and the simplest to implement.

    2) Rely on app.server caching.
       Here your finder returns the entire collection of entity beans to your business method, which only uses the subset it needs. If you have a decent app. server, all those entity beans should be cached implicitly and the next time your business method requests the collection, the entity bean instances will come out of memory.

    3) Implement your own caching routines
       You give an example of caching in the servlet tier. This will probably be difficult, as you will have to implement a central cache and worry about threading issues, etc. Plus it may be wasteful to cache so much data, what if the client doesn't want to see results "21-40"?

       On TheServerSide.com we are using option 1. An example of it in action is clicking "News Archive" on the front page, which shows results "15-30" of articles in the news forum. Doing this is simpler, and can also take advantage of app. server caching, just like option (2).

    take care,

    Floyd Marinescu

  3. Floyd,

    Could you please elaborate on how you're doing it here (Option 1). You mentioned clicking on NewsArchives. How does it work?

    A common problem-
    User needs to be shown data matching the string when he enters something in a search field and clicks enter.
    Now let's say I have a table field which I search for this value (I suppose this is the way most searches work , or is it differently).
    Now a finder method is called which searches for this and finds a big list, in excess of a page.
    How do I proceed?
    Please note:
    I don't know in advance how many matches I might find. Hence I cannot use any kind of numbering as a condition in my finder.

    The Option 2 you mentioned may need some mechanism to mechanism to find which set of data needs to be retrieved next (say 10th to 20th OR 20th to 30th). How do you suggest this should be done? Stateful beans?

    Thanks in advance
    cherote
  4. Hi Floyd,

      Can you please eloberate the method you are using. I guess this results in errorenous results.

      Assume there are 10 news messages first time 20 are displayed. Before user clicks on next assume 2 news are added. If you want to display next 20 how would you prevent 2 of the previously displayed results being appearing from screen?

    Regards,
    Mettu
  5. As you have mentioed in point 1,

    If we have to get the required no of records everytime then
    we should be fetching the data more number of times,ie hitting the database more number of times,which would reduce the performance,So should we compromise on the performance issue, and select the easy way of implementing it(as option one) or should we implement it so that the user will be given a set of records to be viewed,at a time and get good performance.
  6. As you have mentioed in point 1,

    If we have to get the required no of records everytime then
    we should be fetching the data more number of times,ie hitting the database more number of times,which would reduce the performance,So should we compromise on the performance issue, and select the easy way of implementing it(as option one) or should we implement it so that the user will be given a set of records to be viewed,at a time and get good performance.

    Thanks & Regards,
    Rimond