use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class ProjectDaoImpl method deleteProjectById.
@Override
public Project deleteProjectById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
String[] table = new String[1];
table[0] = ProjectResult.class.getSimpleName();
Project project = session.get(Project.class, id);
if (project == null)
throw new GradingFactorDaoException("Project with id : " + id + " does not exist");
for (String cell : table) {
String hql = "delete from ".concat(cell).concat(" where project.id = :projectId");
Query query = session.createQuery(hql);
query.setParameter("projectId", id);
query.executeUpdate();
}
session.delete(project);
session.getTransaction().commit();
session.close();
return project;
} 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 ProjectDaoImpl method getProjectList.
@Override
public List<Project> getProjectList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Project> projectList = new ArrayList<>();
Query query = session.createQuery("from Project");
for (Object objProject : query.list()) projectList.add((Project) objProject);
session.getTransaction().commit();
session.close();
return projectList;
} 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 getAssignmentListByClassId.
@Override
public List<Assignment> getAssignmentListByClassId(long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Assignment> assignmentList = new ArrayList<>();
String hql = "from Assignment where _class.id = :classId and term.id = :termId";
Query query = session.createQuery(hql);
query.setParameter("classId", classId);
query.setParameter("termId", termId);
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 AssignmentDaoImpl method getAssignmentResultByAssignmentAndStudentId.
@Override
public AssignmentResult getAssignmentResultByAssignmentAndStudentId(long assignmentId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Assignment assignment = session.get(Assignment.class, assignmentId);
Student student = session.get(Student.class, studentId);
String hql = "from AssignmentResult as R where R.assignment.id = :assignmentId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("assignmentId", assignmentId);
query.setParameter("studentId", studentId);
if (assignment == null)
throw new GradingFactorDaoException("Assignment with id : " + assignmentId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Assignment's student with id : " + studentId + " does not exist");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No AssignmentResult found. Try use query param " + "(ex. studentId=[id])");
AssignmentResult result = (AssignmentResult) query.list().get(0);
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 AssignmentDaoImpl method updateAssignmentResultByAssignmentAndStudentId.
@Override
public AssignmentResult updateAssignmentResultByAssignmentAndStudentId(int score, long assignmentId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Assignment assignment = session.get(Assignment.class, assignmentId);
Student student = session.get(Student.class, studentId);
String hql = "from AssignmentResult as R where R.assignment.id = :assignmentId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("assignmentId", assignmentId);
query.setParameter("studentId", studentId);
if (assignment == null)
throw new GradingFactorDaoException("Assignment's assignment with id : " + assignmentId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Assignment's student with id : " + studentId + " does not exist");
if (assignmentId < 1)
throw new GradingFactorDaoException("Query param : assignmentId 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");
AssignmentResult result = (AssignmentResult) query.list().get(0);
result.setScore(score);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations