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());
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations