LazyQueryContainer

Hi Tommi,

I have a few questions:

  1. how do I change the page size after creating the lazyquerycontainer? no way to get queryview or other classes to change this.

  2. How does lazy query container determine how much data to pre-fetch? it seems like it has something to do with the size of the table row. The smaller the row the more data it seems to download. The larger the row the less data it prefetches.

  3. When I have a table that shows some images via Embedded, due to the prefetching of images that are not visibile into the browser I often run into performance/usability issues.
    Example. If my table contains 200 rows, my browser view is only large enough to show 10 rows, and I am on the 50th row, with page size 10, lazyquerycontainer decides to fetch records, from 25-75, though my view only shows 10 rows, it fetches 50 and tries to load all the images via Embedded into the browser creating a very sluggish experience. The scrollbar often flickers, and ui blocks, when lazyquerycontainer decides to fetch the next batch.

Thanks.

Any input? Thanks.

I am not the author, but had to read the source code for LazyQueryContainer to build an add-on on top of it.

Short answer is that the container does pretty much what it is told; therefore you probably want to look at Table to see the various parameters that control fetching/pre-fetching.

With respect to getting access to the view, a workaround is to create the lazy container with a view (there is a constructor for that), and keep a handle to the view you created.

Not sure about LQC caches but note that the Table component also has a client-side cache of rows to facilitate smoother scrolling. See Table.setCacheRate() for adjusting this.

Hi Guys,

I have implemented Query and QueryFactory Interface to implement Lazy Query Container in my project. After running the project the Query.size() function is getting called but the loaditems() is not getting called for retrieving the Recordset from Database. Please let me know if any code has to implemented to invoke loaditems().

Any Dependency for invoking loaditems() functions?

Any comments?

Hi Tommi,

Is there any reason that LazyQueryContainer be a final class? I need to unit testing vaadin components, and if LazyQueryContainer is final i can’t mock it (at least with plain mockito).

Regards,
NahuelE

I have problem to set container property readonly. I connect container to vaadin table with DefaultFieldFactory.


container.addContainerProperty("id", Long.class, 0L, true, true);
        container.addContainerProperty("code", String.class, "", false, true);
        container.addContainerProperty("name", String.class, "", false, true);
        container.addContainerProperty("createdAt", Date.class, null, true, true);
        container.addContainerProperty("createdBy", String.class, "", true, true);
        container.addContainerProperty("version", Long.class, 1L, true, true);

id is primary key and version is the Hibernate @version (optimistic lock) property.

These two properties are
always readonly
.
Other properties are
always read-write
.

Setting readonly state at addContainer property doesn’t have an effect.

How do I do it right?

Hi Praveen,

I just started using LazyQueryContainer some days ago and I ran into the same problem as you.

Solution: you have to call LQC#addContainerProperty() at least once to trigger the loadItems(). My guess is, that LQC thinks it doesn’t need to load items because there are no columns to display.

Regards

Andreas

Hi,

I implemented org.vaadin.addons.lazyquerycontainer.Query and org.vaadin.addons.lazyquerycontainer.QueryFactory and use them for a LQC. While playing around with the LQC component, I saw that there are numerous calls to Query.size() that are imho unnecessary. Here is a code sample:

Initialisation of Table

...
addComponent(table);
update("", -1);
table.setColumnAlignment(visCols[1]
, Table.ALIGN_CENTER);
table.setColumnAlignment(visCols[2]
, Table.ALIGN_RIGHT);
table.setColumnAlignment(visCols[4]
, Table.ALIGN_RIGHT);
table.setColumnAlignment(visCols[7]
, Table.ALIGN_RIGHT);
table.setColumnAlignment(visCols[9]
, Table.ALIGN_RIGHT);
table.setColumnAlignment(visCols[10]
, Table.ALIGN_RIGHT);
...

Update of LQC

public final void update(String string, Integer integer)
{
  lqc = new LazyQueryContainer(new TestQueryFactory(string, integer), false, 50);
  query.setColumns(lqc);
  table.setContainerDataSource(lqc);
  table.setVisibleColumns(visCols);
}

I get
4
calls to Query.size() for each invocation of my update() routine and I get
6
calls to Query.size() for the initialisation (1 for calling table.setVisibleColumns() and 1 for each call to table.setColumnAlignment()).

I tried several variations of the code but none of them reduced the calls to Query.size().

Is there anything I can do to reduce these calls?

Any help is much appreciated

Andreas

Hi

Query size should be immutable so you can store the value to field after first invocation and read it from there in the subsequent size invocations.

-Tommi

Hi Tommy,

are you sure about the
should be immutable
? I’m asking, because there are still calls to size() right before a new Query object is created. And since the amount of queried rows can vary every second, I don’t know if this could have any side effects.

Thanks

Andreas

Hi Tommi,

i also do not agree that the size is immutable. Think of a table that increases (import running) while you ar looking at it. I think while a view to the search result is rendered no total call should be made after the initial one. Maybe a method

public SearchResult searchAndTotal(int startIndex, int count)

would help. What do you think?

Thanks

Jan

i am getting the following error when trying to start the sample application. googling i found it has something todo with the jpa2 specification. as i am however relatively new to jpa i do not understand how to fix that.

SCHWERWIEGEND: Servlet.service() for servlet [Lazyapp Application]
 in context with path 
[/LazyApp] threw exception [java.lang.NoSuchMethodError: javax.persistence.EntityManager.detach(Ljava/lang/Object;)V]
 with root cause
java.lang.NoSuchMethodError: javax.persistence.EntityManager.detach(Ljava/lang/Object;)V
	at org.vaadin.addons.lazyquerycontainer.EntityQuery.loadItems(EntityQuery.java:134)
	at org.vaadin.addons.lazyquerycontainer.LazyQueryView.queryItem(LazyQueryView.java:246)
	at org.vaadin.addons.lazyquerycontainer.LazyQueryView.getItem(LazyQueryView.java:224)
	at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.getItem(LazyQueryContainer.java:176)
	at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.getContainerProperty(LazyQueryContainer.java:186)
	at com.vaadin.ui.AbstractSelect.getContainerProperty(AbstractSelect.java:745)
	at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1550)
	at com.vaadin.ui.Table.enableContentRefreshing(Table.java:2313)
	at com.vaadin.ui.Table.setContainerDataSource(Table.java:1901)
	at com.example.lazyapp.LazyappApplication.init(LazyappApplication.java:188)

with use of eclipselink my persistence.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="vaadin-lazyquerycontainer-example" transaction-type="RESOURCE_LOCAL">
		<provider>
                        org.eclipse.persistence.jpa.PersistenceProvider
                </provider>
		<class>com.example.lazyapp.Task</class>
				
		<exclude-unlisted-classes>false</exclude-unlisted-classes>
		<properties>
			<property name="eclipselink.logging.level" value="OFF" />
			<property name="eclipselink.jdbc.driver" value="org.hsqldb.jdbcDriver" />
			<property name="eclipselink.jdbc.url" value="jdbc:hsqldb:nasaaal" />
			<property name="eclipselink.jdbc.user" value="sa" />
			<property name="eclipselink.jdbc.password" value="" />
			<property name="eclipselink.target-database"
				value="org.eclipse.persistence.platform.database.HSQLPlatform" />
			<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
			<property name="eclipselink.ddl-generation.output-mode"
				value="database" />
			<property name="eclipselink.orm.throw.exceptions" value="true" />
		</properties>
	</persistence-unit>
</persistence>

any tips would be great.

SOLVED:
i had two jpa persistence jars in my build path. deleted the jpa 1 jar. now everything works.

I have the same problem, I have added container properties and still my custom query class loadItems() is never called.

This is what I am trying to achieve: I have a Table, to be populated by a search result. The search (in a Solr index) can be repeated with new parameters, so the Table can be reloaded with new data.

When the page is first rendered, there is no search result, so the Table is empty. When a search is started, I set the search criteria in my QueryFactory implementation and call LazyQueryContainer.refresh(). Query.size() is called (I have checked that I return a correct size), but that is all that happens.

Where should I start digging?

Answering myself here… Problem solved as soon as I realized I had to trigger the load of the first batch when there is a new search. That was easy enough:

getQueryView().getItem(0);

I have encountered a problem using LazyQueryContainer as data container for a ComboBox. I need to set the selected item of the ComboBox, but cannot use


MyClass itemToSelect;
...
comboBox.select(itemToSelect)

since
LazyQueryContainer.containsId(Object itemId)
expects
itemId
to be an Integer.

Filtering works fine though. Is there an easy way to programmatically set the filter?

Replying to myself again (this is becoming a habit…), I think I have found a/the Vaadinic way of doing this.

Problem:

  • I want to use a LazyQueryContainer as data container for a ComboBox with filtering
  • The basic filtering of the ComboBox is too slow with 10000 items in the container

Solution:

  • LazySearchContainer is a subclass of LazyQueryContainer which loads items from a Solr index
  • LazySearchContainer implements Filterable, when
    addContainerFilter()
    adds a
    SimpleStringFilter
    (keys pressed in ComboBox) I change the search parameters and re-query the Solr index, in removeAllContainerFilters() i reset the query to “*”

Voilà, an index-backed autocomplete, exactly what I wanted in the first place. Thanks Tommi, LazyQueryContainer made my day!

Hi everyone,
Thanks tommi for this geat addon -_-
I’ll be using the LazyQueryContainer for to load data from a remote service so i don’t have access neither for the queries nor the entityManager.i need the lazyQueryContainer to notifiy the remote service to load the next batch of data.do you have any suggestions for how should i proceed with this problem.
PS:the entityContainer needs the entityManager and a query to interact with database which i don’t have.
thank you in advance.

What’s the maven dependency code for LQC? The one on download page does not work.

org.vaadin.addons.lazyquerycontainer vaadin-lazyquerycontainer 1.2.11

What’s the correct one?