Search in sources :

Example 36 with GradingFactorDaoException

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

the class AssignmentDaoImpl method deleteAssignmentById.

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

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

the class AssignmentDaoImpl method getAssignmentList.

@Override
public List<Assignment> getAssignmentList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Assignment> assignmentList = new ArrayList<>();
        Query query = session.createQuery("from Assignment");
        for (Object objAssignment : query.list()) assignmentList.add((Assignment) objAssignment);
        session.getTransaction().commit();
        session.close();
        return assignmentList;
    } 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 38 with GradingFactorDaoException

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

the class AttendanceDaoImpl method getAttendanceListByStudentId.

@Override
public List<Attendance> getAttendanceListByStudentId(long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Student student = session.get(Student.class, studentId);
        List<Attendance> attendanceList = new ArrayList<>();
        String hql = "from AttendanceResult as R join R.attendance where R.student.id = :studentId";
        if (student == null)
            throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        for (Object object : query.list()) attendanceList.add((Attendance) ((Object[]) object)[1]);
        session.getTransaction().commit();
        session.close();
        return attendanceList;
    } 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 39 with GradingFactorDaoException

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

the class AttendanceDaoImpl method updateAttendanceResultByAttendanceAndStudentId.

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

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

the class AttendanceDaoImpl method deleteAttendanceById.

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