Hi,
This might be a stupid question possibly but I just don't feel like
investigating myself.
I have introduced a new simple helper class called BeanResult to simplify
queries for a list of POJO's a bit.
I looks roughly like this:
public class BeanResult<T extends Object> extends ArrayList<T>
{
private DBCommand cmd;
private Class<T> type;
public BeanResult(Class<T> type, DBCommand cmd)
{
this.type = type;
this.cmd = cmd;
}
public int fetch(Connection conn, int maxItems)
{
clear();
DBReader reader = new DBReader();
try {
// Open and Read
reader.open(cmd, conn);
reader.getBeanList(this, type, maxItems);
return size();
} finally {
reader.close();
}
}
}
In order to use it, I must write the following:
BeanResult<SampleBean> result = new BeanResult<SampleBean>(SampleBean.class,
cmd);
What I don't like is, that I have to pass the SampleBean.class in the
constructor.
I would rather just write:
BeanResult<SampleBean> result = new BeanResult<SampleBean>(cmd);
This is beause the getBeanList uses type.newInstance() to create new Instances
of the bean.
Does anyone know whether and how to determine the Class from T or another
option to get rid of this extra parameter.
I have checked the code in under the EMPIREDB-99 branch.
Regards
Rainer