View Javadoc
1   package ejava.examples.webtier.bl;
2   
3   import java.util.List;
4   
5   import java.util.Map;
6   
7   import org.slf4j.Logger;
8   import org.slf4j.LoggerFactory;
9   
10  import ejava.examples.webtier.bo.Grade;
11  import ejava.examples.webtier.bo.Student;
12  import ejava.examples.webtier.dao.StudentDAO;
13  
14  public class RegistrarImpl implements Registrar {
15      Logger logger = LoggerFactory.getLogger(RegistrarImpl.class);
16      private static final String NEW_STUDENT_QUERY = "getNewStudents";
17      private static final String GRAD_QUERY = "getGraduatingStudents";
18      
19      private StudentDAO dao;
20      
21      public void setStudentDAO(StudentDAO dao) {
22          this.dao = dao;
23      }
24  
25      public Student addStudent(Student student) throws RegistrarException {
26          try {
27              return dao.create(student);
28          }
29          catch (Throwable th) {
30              throw new RegistrarException(th);
31          }
32      }
33  
34      public Student completeCourse(Student student, Grade grade)
35              throws RegistrarException {
36          try {
37              student.getGrades().add(grade);            
38              return dao.update(student);
39          }
40          catch (Throwable th) {
41              throw new RegistrarException(th);
42          }
43      }
44  
45      public Student dropStudent(Student student) throws RegistrarException {
46          try {
47              //do some checking around.....
48              //if okay
49              return dao.remove(student);
50          }
51          catch (Throwable th) {
52              throw new RegistrarException(th);
53          }
54      }
55  
56      public List<Student> getStudents(int index, int count)
57          throws RegistrarException {
58          try {
59              return dao.find(index, count);
60          }
61          catch (Throwable th) {
62              throw new RegistrarException(th);
63          }
64      }
65      
66      public List<Student> getGraduatingStudents(int index, int count)
67              throws RegistrarException {
68          try {
69              return dao.find(GRAD_QUERY, null, index, count);
70          }
71          catch (Throwable th) {
72              throw new RegistrarException(th);
73          }
74      }
75  
76      public List<Student> getNewStudents(int index, int count)
77              throws RegistrarException {
78          try {
79              return dao.find(NEW_STUDENT_QUERY, null, index, count);
80          }
81          catch (Throwable th) {
82              throw new RegistrarException(th);
83          }
84      }
85  
86      public Student getStudent(long id) throws RegistrarException {
87          try {
88              return dao.get(id); 
89          }
90          catch (Throwable th) {
91              throw new RegistrarException(th);
92          }
93      }
94  
95      public List<Student> getStudents(
96              String queryName, Map<String, Object> params, int index, int count) 
97              throws RegistrarException {
98          try {
99              return dao.find(queryName, params, index, count);
100         }
101         catch (Throwable th) {
102             throw new RegistrarException(th);
103         }
104     }
105 }