Search in sources :

Example 11 with ClassDaoException

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

the class ClassDaoImpl method getScheduleById.

@Override
public Schedule getScheduleById(long classId, long id) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Schedule schedule = null;
        if (_class == null)
            throw new ClassDaoException("Class with id : " + classId + " does not exist");
        for (Schedule s : _class.getScheduleList()) {
            if (s.getId() == id)
                schedule = s;
        }
        if (schedule == null)
            throw new ClassDaoException("Class's schedule with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return schedule;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 12 with ClassDaoException

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

the class ClassDaoImpl method getClassListBySubjectId.

@Override
public List<Class> getClassListBySubjectId(long subjectId) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Class> classList = new ArrayList<>();
        Query query = session.createQuery("from Class as c join c.subject as su where su.id = :subjectId");
        query.setParameter("subjectId", subjectId);
        for (Object classObject : query.list()) classList.add((Class) ((Object[]) classObject)[0]);
        session.getTransaction().commit();
        session.close();
        return classList;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) ArrayList(java.util.ArrayList) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 13 with ClassDaoException

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

the class ClassDaoImpl method getScheduleList.

@Override
public Set<Schedule> getScheduleList(long classId) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        if (_class == null)
            throw new ClassDaoException("Class with id : " + classId + " does not exist");
        Set<Schedule> scheduleSet = _class.getScheduleList();
        session.getTransaction().commit();
        session.close();
        return scheduleSet;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 14 with ClassDaoException

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

the class ClassDaoImpl method getClassListByTeacherId.

@Override
public List<Class> getClassListByTeacherId(long teacherId) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Class> classList = new ArrayList<>();
        Query query = session.createQuery("from Class as c join c.teacher as t where t.id = :teacherId");
        query.setParameter("teacherId", teacherId);
        for (Object classObject : query.list()) classList.add((Class) ((Object[]) classObject)[0]);
        session.getTransaction().commit();
        session.close();
        return classList;
    } catch (ClassDaoException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) ArrayList(java.util.ArrayList) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Example 15 with ClassDaoException

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

the class ClassDaoImpl method addScheduleById.

@Override
public Schedule addScheduleById(long classId, long id) throws ClassException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Schedule schedule = scheduleDao.getScheduleById(id);
        String hql = "from Class as c join c.subject as su join c.scheduleList as sc where sc.id = :scheduleId";
        Query query = session.createQuery("from Class as c join c.scheduleList as sc where sc.id = :scheduleId");
        query.setParameter("scheduleId", id);
        if (_class == null)
            throw new ClassDaoException("Class with id : " + classId + " does not exist");
        if (query.list().size() > 0)
            throw new ClassDaoException("Schedule with id : " + id + " already exist in a class");
        for (Schedule s : _class.getScheduleList()) {
            if (s.getId() == id)
                throw new ClassDaoException("Class's schedule with id : " + id + " already exist");
        }
        _class.getScheduleList().add(schedule);
        session.getTransaction().commit();
        session.close();
        return schedule;
    } catch (ClassDaoException | ScheduleException e) {
        session.close();
        throw new ClassException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Class(com.remswork.project.alice.model.Class) Session(org.hibernate.Session)

Aggregations

ClassDaoException (com.remswork.project.alice.dao.exception.ClassDaoException)19 Session (org.hibernate.Session)17 Class (com.remswork.project.alice.model.Class)15 Query (org.hibernate.Query)8 ArrayList (java.util.ArrayList)4 ClassException (com.remswork.project.alice.exception.ClassException)2 Schedule (com.remswork.project.alice.model.Schedule)2 Message (com.remswork.project.alice.model.support.Message)2 ScheduleException (com.remswork.project.alice.exception.ScheduleException)1 Student (com.remswork.project.alice.model.Student)1 ClassScheduleListResourceLinks (com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks)1 ClassStudentListResourceLinks (com.remswork.project.alice.resource.links.ClassStudentListResourceLinks)1 HashSet (java.util.HashSet)1