use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class QuizDaoImpl method deleteQuizById.
@Override
public Quiz deleteQuizById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
String[] table = new String[1];
table[0] = QuizResult.class.getSimpleName();
Quiz quiz = session.get(Quiz.class, id);
if (quiz == null)
throw new GradingFactorDaoException("Quiz with id : " + id + " does not exist");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where quiz.id = :quizId");
Query query = session.createQuery(hql);
query.setParameter("quizId", id);
query.executeUpdate();
}
session.delete(quiz);
session.getTransaction().commit();
session.close();
return quiz;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class ExamDaoImpl method getExamListByStudentId.
@Override
public List<Exam> getExamListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
List<Exam> examList = new ArrayList<>();
String hql = "from ExamResult as R join R.exam where R.student.id = :studentId";
if (student == null)
throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object object : query.list()) examList.add((Exam) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return examList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class ExamDaoImpl method deleteExamResultByExamAndStudentId.
@Override
public ExamResult deleteExamResultByExamAndStudentId(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'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 (query.list().size() < 1)
throw new GradingFactorDaoException("No result to delete");
ExamResult result = (ExamResult) query.list().get(0);
session.delete(result);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class ExamDaoImpl method updateExamResultByExamAndStudentId.
@Override
public ExamResult updateExamResultByExamAndStudentId(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);
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 (query.list().size() < 1)
throw new GradingFactorDaoException("No result to delete");
ExamResult result = (ExamResult) query.list().get(0);
result.setScore(score);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class ExamDaoImpl method getExamResultById.
@Override
public ExamResult getExamResultById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
ExamResult result = session.get(ExamResult.class, id);
if (result == null)
throw new GradingFactorDaoException("ExamResult with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations