Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
excessive LazyQuery.size() calls in Table with LazyQueryContainer?
Hi,
I've implemented a Table with LazyQueryContainer that get data from a service.
I've added a counter to register how many times LazyQueryContainer.containsId() and consequently LazyQuery.size() is being called.
I got surprised. For a collection of 15 objects, I got 18 calls on LazyQuery.size(). With that I got 18 calls to my service...
When I add the number of row it come impracticable... :(
It has something not right with this behavior. I just don't know yet if its problem on Vaadin's Table or it add on...
Anyone have seen this ?
regards,
Cristiano
Yes I have. In the JPA Criteria Query container, which wraps LZQ, I ended up caching the results of the size() method in order to avoid excessive queries. Table does appear to be the culprit.
Since implementing a service-based variant likely led you to get a fairly detailed understanding of LZQ, you can likely just borrow the relevant pieces of code from JPA Criteria Query Container (source is online)
Hi Jean,
Thanks for the tip...
I saw your add-on, very clever.
I've implemented the size cache too, but I had to create my own LazyQueryView because the private method below:
private void queryItem(final int index) {
final int batchSize = getBatchSize();
final int startIndex = index - index % batchSize;
final int count = Math.min(batchSize, [b]getQuery().size()[/b] - startIndex);
I think you have missed this piece too, because you are calling lazyQueryView.getItem in your BeanTupleQueryView:
public Item getItem(int index) {
init();
// standard behavior of getItem.
Item item = lazyQueryView.getItem(index);
return item;
}
thanks again and cheers,
Cristiano
I put up a patch with a pull request if anyone's interested. It was pretty simple and could have been done in extensions of the AbstractBeanQuery but could not due to a call inside the private method.