my system framework is based on ejb.The EJB find method would return the list of EJB instances satisfying the search criteria.but how to display them? I have to cut them into several pages,and provide NEXT,PREVIOUS button.
Now I can not find effectic strategy.
firstly,every page has to be return quickly,so I can not search the database in every page
secondly,beacause of the limits of system framework,I can not turn to JDBC directly?
the problem is common in the web-based EJB framework,can u help me?
The problem you describe is very common. In my solution I am not using EJB, just regular domain objects. I have a class that I call SearchResults. It accepts a collection of objects and allows the user to page through his results without hitting the database again. I store the SearchResults in the session and it keeps track of what page the user is on. Plus I am able to offer the users the ability to sort the results by clicking on column headers (again, without another database hit) This framework is completely configurable (number of records per page, record limit, number of page numbers to display, etc) and easily extendable for any type of java object.
thx for your comments.
your solution is really configurable. and now I am try to
use a javabean to keep beans' primaryID(putting bean in the javabean will cost too much).that means I will keep all Id in a javabean,and set the scope of javabean as session
.when user enter NEXT page, I can get the collection of Ids will be shown on current page,then call findByPrimaryKey(id) to get the entity bean.
so I have go through all records TWO times.
can ejb-QL provide any help?
furthermore , I want to sure whether the following ql can do correctly:
select object(o) from XX as o where o.X MEMBER OF col_c
// in which col_c is a collection
I can't help you with the ejb-ql. I know nothing about it.
We essentially had the exact same setup as your SearchResults objects but we didn't want to store the result set in the user's session to ensure the data was never stale. We were also concerned about the overhead of the replicating that amount of data across multiple nodes in our network. Over the past couple months we switched our implementation to use Tangosol's cache product which still remains just as extendable. We can query across a cluster of caches for the dataset we need, while maintain a local copy in the vm where that client resides. With their latest release, paging support is included making the most complex queries scream while data integrity is maintained.