use of com.remswork.project.alice.dao.exception.GradingFactorDaoException 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.dao.exception.GradingFactorDaoException 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.dao.exception.GradingFactorDaoException 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.dao.exception.GradingFactorDaoException 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());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class RecitationDaoImpl method getRecitationResultById.
@Override
public RecitationResult getRecitationResultById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
RecitationResult result = session.get(RecitationResult.class, id);
if (result == null)
throw new GradingFactorDaoException("RecitationResult with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations