I have classes in my program like
class QueryUtil1{
getByID(int id){
//open connection
//create query
// map to dataset and return
}
}
class QueryUtil2{
getByID(int id){
//open connection
//create query
// map to dataset and return
}
}
so these methods calls from multiple classes creates multiple round trips to database like hundreds in some cases what I am trying to do is merge all those queries and return it in single dataset bu method chaining like
QueryUtil utill = new QueryUtil()l
Dataset ds = utill
._queryUtil1.getByID(id)
._queryUtil2.getByID(id)
.execute();
whose implementation is
class QueryUtil {
StringBuilder query = new StringBuilder();
QueryUtil1 _queryUtil1 = new QueryUtil1();
QueryUtil2 _queryUtil2 = new QueryUtil2();
execute(){
string sql = query.ToString();
//execute command and return dataset
}
class QueryUtil1 : QueryUtil{
QueryUtil getByID(int id){
query.append("select * from table where id = " + id);
return this;
}
}
}
but the problem is it throws stackoverflowexeption because child class initiates parent class and parent class initiate child class and so on... I want to achieve chaining any idea how to?
Aucun commentaire:
Enregistrer un commentaire