Search in sources :

Example 91 with GradingFactorDaoException

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

the class ProjectDaoImpl method getProjectResultById.

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

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

the class ProjectDaoImpl method deleteProjectResultByProjectAndStudentId.

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

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

the class ProjectDaoImpl method getProjectById.

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

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

the class AttendanceDaoImpl method getAttendanceListByClassId.

@Override
public List<Attendance> getAttendanceListByClassId(long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Attendance> attendanceList = new ArrayList<>();
        Query query = session.createQuery("from Attendance where _class.id = :classId");
        query.setParameter("classId", classId);
        for (Object objAttendance : query.list()) attendanceList.add((Attendance) objAttendance);
        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 95 with GradingFactorDaoException

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

the class AttendanceDaoImpl method getAttendanceById.

@Override
public Attendance getAttendanceById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Attendance attendance = session.get(Attendance.class, id);
        if (attendance == null)
            throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
        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) 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