use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.
the class QuizDaoImpl method getQuizListByStudentId.
@Override
public List<Quiz> getQuizListByStudentId(long studentId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
Term term = session.get(Term.class, termId);
List<Quiz> quizList = new ArrayList<>();
String hql = "from QuizResult as R join R.quiz as A where R.student.id = :studentId and " + "A.term.id = :termId";
if (term == null)
throw new GradingFactorDaoException("Quiz's term with id : " + termId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
query.setParameter("termId", termId);
for (Object object : query.list()) quizList.add((Quiz) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return quizList;
} 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 QuizDaoImpl method getQuizList.
@Override
public List<Quiz> getQuizList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Quiz> quizList = new ArrayList<>();
Query query = session.createQuery("from Quiz");
for (Object objQuiz : query.list()) quizList.add((Quiz) objQuiz);
session.getTransaction().commit();
session.close();
return quizList;
} 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 QuizDaoImpl method updateQuizResultByQuizAndStudentId.
@Override
public QuizResult updateQuizResultByQuizAndStudentId(int score, long quizId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Quiz quiz = session.get(Quiz.class, quizId);
Student student = session.get(Student.class, studentId);
String hql = "from QuizResult as R where R.quiz.id = :quizId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("quizId", quizId);
query.setParameter("studentId", studentId);
if (quiz == null)
throw new GradingFactorDaoException("Quiz's quiz with id : " + quizId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
if (quizId < 1)
throw new GradingFactorDaoException("Query param : quizId 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");
QuizResult result = (QuizResult) 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 QuizDaoImpl method getQuizById.
@Override
public Quiz getQuizById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Quiz quiz = session.get(Quiz.class, id);
if (quiz == null)
throw new GradingFactorDaoException("Quiz with id : " + id + " does not exist");
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 QuizDaoImpl method getQuizListByClassId.
@Override
public List<Quiz> getQuizListByClassId(long classId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Quiz> quizList = new ArrayList<>();
Query query = session.createQuery("from Quiz where _class.id = :classId");
query.setParameter("classId", classId);
for (Object objQuiz : query.list()) quizList.add((Quiz) objQuiz);
session.getTransaction().commit();
session.close();
return quizList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations