I have a table named week with columns weekid, weeknumber and weekyear.
Given a starting week I want to get the next 9 weeks (for a total of 10) or the next weeks up to the current week.
I have this:
Week weekFirst = weekDao.getWeekByID(20);
Week weekLast = weekDao.getWeekByID(30);
List<Week> weekList= new ArrayList<Week>();
for(int i=weekFirst.getWeekid(); i<=weekLast.getWeekid();i++){
weekList.add(weekDao.getWeekByID(i));
if(weeksDAO.getWeekByID(i).getWeeknumber() == now.get(Calendar.WEEK_OF_YEAR)){
break;
}
But this won’t do cause it gets only the weekId instead of Week Itself(The Object)
I need to get the Object Week itself and put it in the list so it doesn’t add the Week by the next weekId but it adds according to the next Week Object.
Based on your last comment, you can add a method to your DAO:
Or if you really know the ids, you can add the DAO method:
Then your code above becomes:
Depending on how you use it, you could add a specialized DAO method to do the filtering in the query.