-
1. Re: EntityQuery and Facetted Browsing
andygibson.contact.andygibson.net Oct 20, 2008 5:10 PM (in response to sushi6677)If the entity query has all the results, it doesn't need the dynamic kind of pagination. You could simply use the rich faces data scroller since you have all the results.
Alternatively, you can use some other method to get the list of documents by year which will do so in a more optimized manner. This way you don't have to fetch all the results back to count them by year.
Cheers,
Andy
-
2. Re: EntityQuery and Facetted Browsing
sushi6677 Oct 21, 2008 12:09 PM (in response to sushi6677)Hi,
first thanks for your reply...
I will try your solution with the datascroller.But during coding on I developed the following method inside my DocumentList bean derived from EntityQuery<Document>.
@Factory("yearFacete") public List<Year> initYearFacete() { List<Document> documents = super.getResultList(); List<Year> years = new ArrayList<Year>(); for(Document doc : documents) { Year year = new Year(); year.setName(String.valueOf(doc.getYear())); if(years.contains(year)) { int index = years.indexOf(year); int value = years.get(index).getOcc(); value++; year.setOcc(value); years.set(index, year); } else { year.setOcc(1); years.add(year); } } return years; }
Here I call the super.getResultList() method and watched the log. It seams that seam just made one query to the database.
So my question is: When does seam decide if it has to make a query or not? I meandue to the logic
there should be two same queries:
1) for getting the resultList for the JSF page
2) for getting the resultList inside the yearFacete factory method...Bests,
Sushi -
3. Re: EntityQuery and Facetted Browsing
andygibson.contact.andygibson.net Oct 21, 2008 6:56 PM (in response to sushi6677)Hey Sascha,
Yes, that is correct. The resultList is only loaded on demand and remembered. If you look at at the iniResultList method that is called by getResultList :
private void initResultList() { if (resultList==null) { javax.persistence.Query query = createQuery(); resultList = query==null ? null : query.getResultList(); } }
In other words, once you get the results, the entity query remembers them for the lifespan of the bean (or until you call refresh which essentially sets results list = null)
Cheers,
Andy