use of com.remswork.project.alice.dao.exception.GradingFactorDaoException in project classify-system by anverliedoit.
the class RecitationDaoImpl method getRecitationById.
@Override
public Recitation getRecitationById(long id) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Recitation recitation = session.get(Recitation.class, id);
if (recitation == null)
throw new GradingFactorDaoException("Recitation with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return recitation;
} 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 RecitationDaoImpl method addRecitation.
@Override
public Recitation addRecitation(Recitation recitation, long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Class _class = session.get(Class.class, classId);
Term term = session.get(Term.class, termId);
if (recitation == null)
throw new GradingFactorDaoException("You tried to add class with a null value");
if (termId < 1)
throw new GradingFactorDaoException("Query param : termId has an invalid input");
if (_class == null)
throw new GradingFactorDaoException("Recitation's class with id : " + classId + " does not exist");
if (term == null)
throw new GradingFactorDaoException("Recitation's term with id : " + termId + " does not exist");
if (recitation.getTitle() == null)
throw new GradingFactorDaoException("Recitation's title is required");
if (recitation.getTitle().trim().equals(""))
throw new GradingFactorDaoException("Recitation can't have an empty title");
if (recitation.getDate() == null)
throw new GradingFactorDaoException("Recitation's date is required");
if (recitation.getDate().trim().equals(""))
throw new GradingFactorDaoException("Recitation can't have an empty date");
if (recitation.getItemTotal() < 0)
throw new GradingFactorDaoException("Recitation's itemTotal is invalid");
recitation.set_class(_class);
recitation.setTerm(term);
session.persist(recitation);
session.getTransaction().commit();
session.close();
return recitation;
} 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 RecitationDaoImpl method getRecitationList.
@Override
public List<Recitation> getRecitationList() throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Recitation> recitationList = new ArrayList<>();
Query query = session.createQuery("from Recitation");
for (Object objRecitation : query.list()) recitationList.add((Recitation) objRecitation);
session.getTransaction().commit();
session.close();
return recitationList;
} 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 RecitationDaoImpl method getRecitationListByClassId.
@Override
public List<Recitation> getRecitationListByClassId(long classId, long termId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Recitation> recitationList = new ArrayList<>();
String hql = "from Recitation where _class.id = :classId and term.id = :termId";
Query query = session.createQuery(hql);
query.setParameter("classId", classId);
query.setParameter("termId", termId);
for (Object objRecitation : query.list()) recitationList.add((Recitation) objRecitation);
session.getTransaction().commit();
session.close();
return recitationList;
} 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 RecitationDaoImpl method getRecitationResultByRecitationAndStudentId.
@Override
public RecitationResult getRecitationResultByRecitationAndStudentId(long recitationId, long studentId) throws GradingFactorException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Recitation recitation = session.get(Recitation.class, recitationId);
Student student = session.get(Student.class, studentId);
String hql = "from RecitationResult as R where R.recitation.id = :recitationId and R.student.id = :studentId";
Query query = session.createQuery(hql);
query.setParameter("recitationId", recitationId);
query.setParameter("studentId", studentId);
if (recitation == null)
throw new GradingFactorDaoException("Recitation with id : " + recitationId + " does not exist");
if (student == null)
throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
if (query.list().size() < 1)
throw new GradingFactorDaoException("No RecitationResult found. Try use query param " + "(ex. studentId=[id])");
RecitationResult result = (RecitationResult) query.list().get(0);
session.getTransaction().commit();
session.close();
return result;
} catch (GradingFactorDaoException e) {
session.close();
throw new GradingFactorException(e.getMessage());
}
}
Aggregations