Search in sources :

Example 1 with GradingFactorDaoException

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

the class RecitationDaoImpl method getRecitationById.

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

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

the class RecitationDaoImpl method addRecitation.

@Override
public Recitation addRecitation(Recitation recitation, 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 (recitation == 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("Recitation's class with id : " + classId + " does not exist");
        if (term == null)
            throw new GradingFactorDaoException("Recitation's term with id : " + termId + " does not exist");
        if (recitation.getTitle() == null)
            throw new GradingFactorDaoException("Recitation's title is required");
        if (recitation.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Recitation can't have an empty title");
        if (recitation.getDate() == null)
            throw new GradingFactorDaoException("Recitation's date is required");
        if (recitation.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Recitation can't have an empty date");
        if (recitation.getItemTotal() < 0)
            throw new GradingFactorDaoException("Recitation's itemTotal is invalid");
        recitation.set_class(_class);
        recitation.setTerm(term);
        session.persist(recitation);
        session.getTransaction().commit();
        session.close();
        return recitation;
    } 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 3 with GradingFactorDaoException

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

the class RecitationDaoImpl method getRecitationList.

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

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

the class RecitationDaoImpl method getRecitationListByClassId.

@Override
public List<Recitation> getRecitationListByClassId(long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Recitation> recitationList = new ArrayList<>();
        String hql = "from Recitation where _class.id = :classId and term.id = :termId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", classId);
        query.setParameter("termId", termId);
        for (Object objRecitation : query.list()) recitationList.add((Recitation) objRecitation);
        session.getTransaction().commit();
        session.close();
        return recitationList;
    } 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 5 with GradingFactorDaoException

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

the class RecitationDaoImpl method getRecitationResultByRecitationAndStudentId.

@Override
public RecitationResult getRecitationResultByRecitationAndStudentId(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 with id : " + recitationId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No RecitationResult found. Try use query param " + "(ex. studentId=[id])");
        RecitationResult result = (RecitationResult) 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)

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