Search in sources :

Example 81 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class QuizDaoImpl method addQuizResult.

@Override
public QuizResult addQuizResult(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);
        QuizResult result = new QuizResult();
        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 (score < 0 && score > quiz.getItemTotal())
            throw new GradingFactorDaoException("QuizResult's score is invalid");
        if (query.list().size() > 0)
            throw new GradingFactorDaoException("QuizResult's  student with id : " + studentId + " already exist");
        result.setScore(score);
        result.setQuiz(quiz);
        result.setStudent(student);
        session.persist(result);
        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 82 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class QuizDaoImpl method deleteQuizResultByQuizAndStudentId.

@Override
public QuizResult deleteQuizResultByQuizAndStudentId(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);
        session.delete(result);
        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 83 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class RecitationDaoImpl method updateRecitationResultByRecitationAndStudentId.

@Override
public RecitationResult updateRecitationResultByRecitationAndStudentId(int score, long recitationId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Recitation recitation = session.get(Recitation.class, recitationId);
        Student student = session.get(Student.class, studentId);
        String hql = "from RecitationResult as R where R.recitation.id = :recitationId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("recitationId", recitationId);
        query.setParameter("studentId", studentId);
        if (recitation == null)
            throw new GradingFactorDaoException("Recitation's recitation with id : " + recitationId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
        if (recitationId < 1)
            throw new GradingFactorDaoException("Query param : recitationId 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");
        RecitationResult result = (RecitationResult) 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 84 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class RecitationDaoImpl method deleteRecitationById.

@Override
public Recitation deleteRecitationById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        String[] table = new String[1];
        table[0] = RecitationResult.class.getSimpleName();
        Recitation recitation = session.get(Recitation.class, id);
        if (recitation == null)
            throw new GradingFactorDaoException("Recitation with id : " + id + " does not exist");
        for (String cell : table) {
            String hql = "delete from ".concat(cell).concat(" where recitation.id = :recitationId");
            Query query = session.createQuery(hql);
            query.setParameter("recitationId", id);
            query.executeUpdate();
        }
        session.delete(recitation);
        session.getTransaction().commit();
        session.close();
        return recitation;
    } 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 85 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.

the class RecitationDaoImpl method deleteRecitationResultByRecitationAndStudentId.

@Override
public RecitationResult deleteRecitationResultByRecitationAndStudentId(long recitationId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Recitation recitation = session.get(Recitation.class, recitationId);
        Student student = session.get(Student.class, studentId);
        String hql = "from RecitationResult as R where R.recitation.id = :recitationId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("recitationId", recitationId);
        query.setParameter("studentId", studentId);
        if (recitation == null)
            throw new GradingFactorDaoException("Recitation's recitation with id : " + recitationId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
        if (recitationId < 1)
            throw new GradingFactorDaoException("Query param : recitationId 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");
        RecitationResult result = (RecitationResult) query.list().get(0);
        session.delete(result);
        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)

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