public void setStudentCourses(Student student, List courseIds) {
// First remove current courses
List removes = student.getCourses();
for (int i = removes.size() - 1; i >= 0; i--) {
Course course = (Course) removes.get(i);
student.removeFromCourses(course);
}
if (courseIds == null || courseIds.isEmpty()) {
return;
}
// Next, set the new courses
SelectQuery query = new SelectQuery(Course.class);
query.setQualifier(ExpressionFactory.inDbExp("id", courseIds));
List courses = getDataContext().performQuery(query);
for (Iterator it = courses.iterator(); it.hasNext(); ) {
Course course = (Course) it.next() ;
student.addToCourses(course);
}
}