use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AssignmentDaoImpl method deleteAssignmentById.
@Override
public Assignment deleteAssignmentById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
String[] table = new String[1];
table[0] = AssignmentResult.class.getSimpleName();
Assignment assignment = session.get(Assignment.class, id);
if (assignment == null)
throw new GradingFactorDaoException("Assignment with id : " + id + " does not exist");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where assignment.id = :assignmentId");
Query query = session.createQuery(hql);
query.setParameter("assignmentId", id);
query.executeUpdate();
}
session.delete(assignment);
session.getTransaction().commit();
session.close();
return assignment;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AssignmentDaoImpl method getAssignmentList.
@Override
public List<Assignment> getAssignmentList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Assignment> assignmentList = new ArrayList<>();
Query query = session.createQuery("from Assignment");
for (Object objAssignment : query.list()) assignmentList.add((Assignment) objAssignment);
session.getTransaction().commit();
session.close();
return assignmentList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method getAttendanceListByStudentId.
@Override
public List<Attendance> getAttendanceListByStudentId(long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Student student = session.get(Student.class, studentId);
List<Attendance> attendanceList = new ArrayList<>();
String hql = "from AttendanceResult as R join R.attendance where R.student.id = :studentId";
if (student == null)
throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
Query query = session.createQuery(hql);
query.setParameter("studentId", studentId);
for (Object object : query.list()) attendanceList.add((Attendance) ((Object[]) object)[1]);
session.getTransaction().commit();
session.close();
return attendanceList;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method updateAttendanceResultByAttendanceAndStudentId.
@Override
public AttendanceResult updateAttendanceResultByAttendanceAndStudentId(int status, long attendanceId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Attendance attendance = session.get(Attendance.class, attendanceId);
Student student = session.get(Student.class, studentId);
String hql = "from AttendanceResult as R where R.attendance.id = :attendanceId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("attendanceId", attendanceId);
query.setParameter("studentId", studentId);
if (attendance == null)
throw new GradingFactorDaoException("Attendance's attendance with id : " + attendanceId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
if (attendanceId < 1)
throw new GradingFactorDaoException("Query param : attendanceId is required");
if (studentId < 1)
throw new GradingFactorDaoException("Query param : studentId is required");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No result to delete");
AttendanceResult result = (AttendanceResult) query.list().get(0);
result.setStatus(status);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class AttendanceDaoImpl method deleteAttendanceById.
@Override
public Attendance deleteAttendanceById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
String[] table = new String[1];
table[0] = AttendanceResult.class.getSimpleName();
Attendance attendance = session.get(Attendance.class, id);
if (attendance == null)
throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where attendance.id = :attendanceId");
Query query = session.createQuery(hql);
query.setParameter("attendanceId", id);
query.executeUpdate();
}
session.delete(attendance);
session.getTransaction().commit();
session.close();
return attendance;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations