use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method getStudentById.
@Override
public Student getStudentById(long classId, long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Student student = null;
if (_class == null)
throw new ClassDaoException("Class with id : " + classId + " does not exist");
for (Student s : _class.getStudentList()) {
if (s.getId() == id)
student = s;
}
if (student == null)
throw new ClassDaoException("Class's student with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return student;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method deleteClassById.
@Override
public Class deleteClassById(long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, id);
if (_class == null)
throw new ClassDaoException("Class with id : " + id + " does not exist");
_class.setTeacher(null);
_class.setSubject(null);
_class.setScheduleList(null);
_class.setSection(null);
_class.setStudentList(null);
for (Object object : session.createQuery("from Activity where _class.id = '" + id + "'").list()) {
Activity activity = (Activity) object;
String hql = "delete from ActivityResult where activity.id = :activityId";
Query query = session.createQuery(hql);
query.setParameter("activityId", activity.getId());
query.executeUpdate();
session.delete(activity);
}
for (Object object : session.createQuery("from Assignment where _class.id = '" + id + "'").list()) {
Assignment assignment = (Assignment) object;
String hql = "delete from AssignmentResult where assignment.id = :assignmentId";
Query query = session.createQuery(hql);
query.setParameter("assignmentId", assignment.getId());
query.executeUpdate();
session.delete(assignment);
}
for (Object object : session.createQuery("from Attendance where _class.id = '" + id + "'").list()) {
Attendance attendance = (Attendance) object;
String hql = "delete from AttendanceResult where attendance.id = :attendanceId";
Query query = session.createQuery(hql);
query.setParameter("attendanceId", attendance.getId());
query.executeUpdate();
session.delete(attendance);
}
for (Object object : session.createQuery("from Exam where _class.id = '" + id + "'").list()) {
Exam exam = (Exam) object;
String hql = "delete from ExamResult where exam.id = :examId";
Query query = session.createQuery(hql);
query.setParameter("examId", exam.getId());
query.executeUpdate();
session.delete(exam);
}
for (Object object : session.createQuery("from Project where _class.id = '" + id + "'").list()) {
Project project = (Project) object;
String hql = "delete from ProjectResult where project.id = :projectId";
Query query = session.createQuery(hql);
query.setParameter("projectId", project.getId());
query.executeUpdate();
session.delete(project);
}
for (Object object : session.createQuery("from Quiz where _class.id = '" + id + "'").list()) {
Quiz quiz = (Quiz) object;
String hql = "delete from QuizResult where quiz.id = :quizId";
Query query = session.createQuery(hql);
query.setParameter("quizId", quiz.getId());
query.executeUpdate();
session.delete(quiz);
}
for (Object object : session.createQuery("from Recitation where _class.id = '" + id + "'").list()) {
Recitation recitation = (Recitation) object;
String hql = "delete from RecitationResult where recitation.id = :recitationId";
Query query = session.createQuery(hql);
query.setParameter("recitationId", recitation.getId());
query.executeUpdate();
session.delete(recitation);
}
String hql = "delete from Grade as G where G._class.id = :classId";
Query query = session.createQuery(hql);
query.setParameter("classId", id);
query.executeUpdate();
session.delete(_class);
session.getTransaction().commit();
session.close();
return _class;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method addStudentById.
@Override
public Student addStudentById(long classId, long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
if (_class == null)
throw new ClassDaoException("Class with id : " + classId + " does not exist");
Student student = studentDao.getStudentById(id);
for (Student s : _class.getStudentList()) {
if (s.getId() == id)
throw new ClassDaoException("Class's student with id : " + id + " already exist");
}
_class.getStudentList().add(student);
session.merge(_class);
session.getTransaction().commit();
session.close();
return student;
} catch (ClassDaoException | StudentException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method getClassList.
@Override
public List<Class> getClassList() throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Class> classList = new ArrayList<>();
Query query = session.createQuery("from Class");
for (Object classObject : query.list()) classList.add((Class) classObject);
session.getTransaction().commit();
session.close();
return classList;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Class in project classify-system by anverliedoit.
the class ClassDaoImpl method getScheduleById.
@Override
public Schedule getScheduleById(long classId, long id) throws ClassException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Schedule schedule = null;
if (_class == null)
throw new ClassDaoException("Class with id : " + classId + " does not exist");
for (Schedule s : _class.getScheduleList()) {
if (s.getId() == id)
schedule = s;
}
if (schedule == null)
throw new ClassDaoException("Class's schedule with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return schedule;
} catch (ClassDaoException e) {
session.close();
throw new ClassException(e.getMessage());
}
}
Aggregations