use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionDaoImpl method getSectionById.
@Override
public Section getSectionById(long id) throws SectionException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Section section = session.get(Section.class, id);
if (section == null)
throw new SectionDaoException("Section with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return section;
} catch (SectionDaoException e) {
session.close();
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionDaoImpl method updateSectionById.
@Override
public Section updateSectionById(long id, Section newSection, long departmentId) throws SectionException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Section section = session.get(Section.class, id);
if (section == null)
throw new SectionDaoException("Section with id : " + id + " does not exist");
if (newSection == null)
newSection = new Section();
if (!(newSection.getName() != null ? newSection.getName() : "").trim().isEmpty())
section.setName(newSection.getName().trim());
if (departmentId > 0) {
Department department = departmentDao.getDepartmentById(departmentId);
if (department.getId() == (section.getDepartment() != null ? section.getDepartment().getId() : 0))
throw new SectionDaoException("Can't update section's department with same department");
section.setDepartment(department);
}
session.getTransaction().commit();
session.close();
return section;
} catch (SectionDaoException | DepartmentException e) {
session.close();
throw new SectionException(e.getMessage());
}
}
Aggregations