You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by sridhar reddy <sr...@yahoo.com> on 2010/12/25 17:34:15 UTC
BeanListHandler is a raw type. References to generic type BeanListHandler should be parameterized
Hi,
I am trying to write a java class that will execute any sql select/update/delete
statement and return the result set object transforming to list of type <T>
objects.
But i am geting a waring at statement "h = new
BeanListHandler(type.newInstance().getClass()); that
BeanListHandler is a raw type. References to generic type BeanListHandler<T>
should be parameterized
public class StatementHandler<T>{
protected static DataSource ds = null;
protected final Class<T> type;
static{
try {
ds = (DataSource) new
InitialContext().lookup(ApplicationProperties.getInstance().getProperty("DATA_SOURCE"));
} catch (NamingException e) {
logger.error("Data source lookup failed" , e);
}
}
public StatementHandler(Class<T> type){
this.type = type;
}
public List<T> execute(String query, Object... args) {
List<T> list = null;
QueryRunner run = new QueryRunner(ds);
ResultSetHandler<List<T>> h=null;
try {
h = new
BeanListHandler(type.newInstance().getClass());
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
try {
list= run.query(query, h);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
Please some one help me on how to solve this and get rid of warning.
If my design in not correct, then also please suggest me for improvement.
Thanks,
Sridhar