Search in sources :

Example 66 with GradingFactorDaoException

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

the class ProjectDaoImpl method deleteProjectById.

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

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

the class ProjectDaoImpl method getProjectList.

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

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

the class AssignmentDaoImpl method getAssignmentListByClassId.

@Override
public List<Assignment> getAssignmentListByClassId(long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Assignment> assignmentList = new ArrayList<>();
        String hql = "from Assignment where _class.id = :classId and term.id = :termId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", classId);
        query.setParameter("termId", termId);
        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 69 with GradingFactorDaoException

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

the class AssignmentDaoImpl method getAssignmentResultByAssignmentAndStudentId.

@Override
public AssignmentResult getAssignmentResultByAssignmentAndStudentId(long assignmentId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Assignment assignment = session.get(Assignment.class, assignmentId);
        Student student = session.get(Student.class, studentId);
        String hql = "from AssignmentResult as R where R.assignment.id = :assignmentId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("assignmentId", assignmentId);
        query.setParameter("studentId", studentId);
        if (assignment == null)
            throw new GradingFactorDaoException("Assignment with id : " + assignmentId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Assignment's student with id : " + studentId + " does not exist");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No AssignmentResult found. Try use query param " + "(ex. studentId=[id])");
        AssignmentResult result = (AssignmentResult) query.list().get(0);
        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 70 with GradingFactorDaoException

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

the class AssignmentDaoImpl method updateAssignmentResultByAssignmentAndStudentId.

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

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