Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

References to generic type BeanListHandler<T> should be parameterized

826582Dec 25 2010 — edited Dec 26 2010
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.
For this i am using DBUtils from apache.

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;
}

@Override
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;
}

}


the constructor of BeanListHandler from DBUtils is

public BeanListHandler(Class<T> type) {
this(type, ArrayHandler.ROW_PROCESSOR);
}

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 23 2011
Added on Dec 25 2010
3 comments
3,767 views