use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ExamDaoImpl method getExamList.
@Override
public List<Exam> getExamList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Exam> examList = new ArrayList<>();
Query query = session.createQuery("from Exam");
for (Object objExam : query.list()) examList.add((Exam) objExam);
session.getTransaction().commit();
session.close();
return examList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ExamDaoImpl method addExamResult.
@Override
public ExamResult addExamResult(int score, long examId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Exam exam = session.get(Exam.class, examId);
Student student = session.get(Student.class, studentId);
ExamResult result = new ExamResult();
String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("examId", examId);
query.setParameter("studentId", studentId);
if (exam == null)
throw new GradingFactorDaoException("Exam's exam with id : " + examId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
if (examId < 1)
throw new GradingFactorDaoException("Query param : examId is required");
if (studentId < 1)
throw new GradingFactorDaoException("Query param : studentId is required");
if (score < 0 && score > exam.getItemTotal())
throw new GradingFactorDaoException("ExamResult's score is invalid");
if (query.list().size() > 0)
throw new GradingFactorDaoException("ExamResult's student with id : " + studentId + " already exist");
result.setScore(score);
result.setExam(exam);
result.setStudent(student);
session.persist(result);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ExamDaoImpl method getExamListByClassId.
@Override
public List<Exam> getExamListByClassId(long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Exam> examList = new ArrayList<>();
String hql = "from Exam where _class.id = :classId and term.id = :termId";
Query query = session.createQuery(hql);
query.setParameter("classId", classId);
query.setParameter("termId", termId);
for (Object objExam : query.list()) examList.add((Exam) objExam);
session.getTransaction().commit();
session.close();
return examList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ExamDaoImpl method getExamResultByExamAndStudentId.
@Override
public ExamResult getExamResultByExamAndStudentId(long examId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Exam exam = session.get(Exam.class, examId);
Student student = session.get(Student.class, studentId);
String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("examId", examId);
query.setParameter("studentId", studentId);
if (exam == null)
throw new GradingFactorDaoException("Exam with id : " + examId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No ExamResult found. Try use query param " + "(ex. studentId=[id])");
ExamResult result = (ExamResult) query.list().get(0);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ProjectDaoImpl method getProjectListByStudentId.
@Override
public List<Project> getProjectListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
List<Project> projectList = new ArrayList<>();
String hql = "from ProjectResult as R join R.project where R.student.id = :studentId";
if (student == null)
throw new GradingFactorDaoException("Project's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object object : query.list()) projectList.add((Project) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return projectList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations