Search in sources :

Example 51 with GradingFactorDaoException

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

the class ActivityDaoImpl method getActivityResultById.

@Override
public ActivityResult getActivityResultById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        ActivityResult result = session.get(ActivityResult.class, id);
        if (result == null)
            throw new GradingFactorDaoException("ActivityResult 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)

Example 52 with GradingFactorDaoException

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

the class ActivityDaoImpl method getActivityById.

@Override
public Activity getActivityById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Activity activity = session.get(Activity.class, id);
        if (activity == null)
            throw new GradingFactorDaoException("Activity with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return activity;
    } 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 53 with GradingFactorDaoException

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

the class AttendanceDaoImpl method addAttendance.

@Override
public Attendance addAttendance(Attendance attendance, long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Term term = session.get(Term.class, termId);
        if (attendance == null)
            throw new GradingFactorDaoException("You tried to add class with a null value");
        if (termId < 1)
            throw new GradingFactorDaoException("Query param : termId has an invalid input");
        if (_class == null)
            throw new GradingFactorDaoException("Attendance's class with id : " + classId + " does not exist");
        if (term == null)
            throw new GradingFactorDaoException("Attendance's term with id : " + termId + " does not exist");
        if (attendance.getTitle() == null)
            throw new GradingFactorDaoException("Attendance's title is required");
        if (attendance.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Attendance can't have an empty title");
        if (attendance.getDate() == null)
            throw new GradingFactorDaoException("Attendance's date is required");
        if (attendance.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Attendance can't have an empty date");
        attendance.set_class(_class);
        attendance.setTerm(term);
        session.persist(attendance);
        session.getTransaction().commit();
        session.close();
        return attendance;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 54 with GradingFactorDaoException

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

the class ExamDaoImpl method addExam.

@Override
public Exam addExam(Exam exam, long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        if (exam == null)
            throw new GradingFactorDaoException("You tried to add class with a null value");
        if (classId == 0)
            throw new GradingFactorDaoException("Query param : classId is required");
        if (_class == null)
            throw new GradingFactorDaoException("Exam's class with id : " + classId + " does not exist");
        if (exam.getTitle() == null)
            throw new GradingFactorDaoException("Exam's title is required");
        if (exam.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Exam can't have an empty title");
        if (exam.getDate() == null)
            throw new GradingFactorDaoException("Exam's date is required");
        if (exam.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Exam can't have an empty date");
        if (exam.getItemTotal() < 0)
            throw new GradingFactorDaoException("Exam's itemTotal is invalid");
        exam.set_class(_class);
        session.persist(exam);
        session.getTransaction().commit();
        session.close();
        return exam;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 55 with GradingFactorDaoException

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

the class ExamDaoImpl method deleteExamById.

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