Newbie not able to use Lazy Query Container (sigh) need help

Hello all, I need your help to figure out how to use LQC.

I have a DAO to access objects stored in DB. I wrote the following to use LQC:


public class UserBeanQuery extends AbstractBeanQuery<User> 
{
	private DAO dao = DAOFactory.instance().createDAO();

	public UserBeanQuery(QueryDefinition definition,
			Map<String, Object> queryConfiguration, Object[] sortPropertyIds,
			boolean[] sortStates) 
	{
		super(definition, queryConfiguration, sortPropertyIds, sortStates);
	}
	
	protected User constructBean() 
	{ return new User(-1); }

	protected List<User> loadBeans(int startIndex, int count)
	{
		Set<User> result = dao.findAll(User.class, startIndex, count);
		return new ArrayList<User>(result);
	}

	@Override
	protected void saveBeans(List<User> addedTasks, List<User> modifiedTasks,
			List<User> removedTasks)
	{}

	@Override
	public int size() 
	{ return  (int)dao.count(User.class); }
}

And use it in the table:


public class UserTable extends Table
{
	public UserTable()
	{
		BeanQueryFactory<UserBeanQuery> factory = new BeanQueryFactory<UserBeanQuery>(UserBeanQuery.class);
		LazyQueryContainer container = new LazyQueryContainer(factory, false, 10);
		setContainerDataSource(container);
	}
}

In the log I can see that UserBeanQuery.size() method is called many times (once for each User entry).

Do you have any idea about this strange behaviour ?

Thanks in advance for your help
jona


Solved
adding LazyQueryDefinition:


public class UserTable extends Table
{
	private static final long serialVersionUID = -8877945668449793082L;
	private static final Object[] ORDER = { "userId", "name", "surname", "email", "street", "streetNumber", "city", "postalCode", "state", "country" };
	private static final String[] HEADERS = { "ID", "Surname", "First Name", "Email", "Street", "N", "City", "Code", "State", "Country" };

	public UserTable()
	{
		setSizeFull();

		BeanQueryFactory<UserBeanQuery> factory = new BeanQueryFactory<UserBeanQuery>(UserBeanQuery.class);
		LazyQueryDefinition definition = new LazyQueryDefinition(false, 30);
		
		definition.addProperty("userId", String.class, new Integer(-1), true, true);
		definition.addProperty("name", String.class, "", true, true);
		definition.addProperty("surname", String.class, "", true, true);
		definition.addProperty("email", String.class, "", true, true);
		definition.addProperty("street", String.class, "", true, true);
		definition.addProperty("streetNumber", String.class, "", true, true);
		definition.addProperty("city", String.class, "", true, true);
		definition.addProperty("postalCode", String.class, "", true, true);
		definition.addProperty("state", String.class, "", true, true);
		definition.addProperty("country", String.class, "", true, true);

		LazyQueryContainer container = new LazyQueryContainer(definition, factory);
		setContainerDataSource(container);
		
		setVisibleColumns(ORDER);
		setColumnHeaders(HEADERS);
	}
}

jona

this was very helpful. I was unable to figure it out myself until I saw your post.