use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectDaoImpl method getSubjectList.
@Override
public List<Subject> getSubjectList() throws SubjectException {
List<Subject> subjectList = new ArrayList<>();
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Query query = session.createQuery("from Subject");
for (Object subjectObj : query.list()) subjectList.add((Subject) subjectObj);
session.getTransaction().commit();
session.close();
return subjectList;
} catch (SubjectDaoException e) {
session.close();
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectDaoImpl method addSubject.
@Override
public Subject addSubject(Subject subject) throws SubjectException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
if (subject == null)
throw new SubjectDaoException("You tried to add subject with a null value");
if (subject.getName() == null)
throw new SubjectDaoException("SubjectDto's name is required");
if (subject.getName().trim().equals(""))
throw new SubjectDaoException("SubjectDto can't have an empty name");
if (subject.getDescription() == null)
throw new SubjectDaoException("SubjectDto's description is required");
if (subject.getDescription().trim().equals(""))
throw new SubjectDaoException("SubjectDto can't have an empty description");
if (subject.getCode() == null)
throw new SubjectDaoException("SubjectDto's code is required");
if (subject.getCode().trim().equals(""))
throw new SubjectDaoException("SubjectDto can't have an empty code");
if (subject.getUnit() == 0)
throw new SubjectDaoException("SubjectDto's unit is required");
if (subject.getUnit() < 0)
throw new SubjectDaoException("SubjectDto's unit is invalid");
session.persist(subject);
session.getTransaction().commit();
session.close();
return subject;
} catch (SubjectDaoException e) {
session.close();
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectDaoImpl method getSubjectListByTeacherIdUnique.
public List<Subject> getSubjectListByTeacherIdUnique(long teacherId) throws SubjectException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Subject> subjectList = new ArrayList<>();
String hql = "from Class as c join c.subject as s join c.teacher as t where t.id = :teacherId group by s.id";
Query query = session.createQuery(hql);
query.setParameter("teacherId", teacherId);
for (Object list : query.list()) {
Object[] row = (Object[]) list;
subjectList.add((Subject) row[1]);
}
session.getTransaction().commit();
session.close();
return subjectList;
} catch (SubjectDaoException e) {
session.close();
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectDaoImpl method getSubjectListByStudentId.
@Override
public List<Subject> getSubjectListByStudentId(long studentId) throws SubjectException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Subject> subjectList = new ArrayList<>();
String hql = "from Class as c join c.subject as su join c.studentList as st where st.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object list : query.list()) {
Object[] row = (Object[]) list;
subjectList.add((Subject) row[1]);
}
session.getTransaction().commit();
session.close();
return subjectList;
} catch (SubjectDaoException e) {
session.close();
throw new SubjectException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectDaoImpl method getSubjectListByTeacherId.
@Override
public List<Subject> getSubjectListByTeacherId(long teacherId) throws SubjectException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Subject> subjectList = new ArrayList<>();
String hql = "from Class as c join c.subject as s join c.teacher as t where t.id = :teacherId";
Query query = session.createQuery(hql);
query.setParameter("teacherId", teacherId);
for (Object list : query.list()) {
Object[] row = (Object[]) list;
subjectList.add((Subject) row[1]);
}
session.getTransaction().commit();
session.close();
return subjectList;
} catch (SubjectDaoException e) {
session.close();
throw new SubjectException(e.getMessage());
}
}
Aggregations