Search in sources :

Example 16 with GradingFactorDaoException

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());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 17 with GradingFactorDaoException

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());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 18 with GradingFactorDaoException

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());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 19 with GradingFactorDaoException

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());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 20 with GradingFactorDaoException

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());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Aggregations

GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)104 Session (org.hibernate.Session)104 Query (org.hibernate.Query)64 ArrayList (java.util.ArrayList)27 Class (com.remswork.project.alice.model.Class)16 Grade (com.remswork.project.alice.model.Grade)7 Formula (com.remswork.project.alice.model.Formula)6 Student (com.remswork.project.alice.model.Student)2 Subject (com.remswork.project.alice.model.Subject)2 Teacher (com.remswork.project.alice.model.Teacher)2 Term (com.remswork.project.alice.model.Term)2