List of usage examples for org.hibernate Session delete
void delete(Object object);
From source file:ca.usask.gmcte.currimap.action.ProgramManager.java
License:Open Source License
public boolean removeLinkCourseOutcomeProgramOutcome(int id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w w w .j a va 2 s . c o m*/ try { LinkCourseOutcomeProgramOutcome l = (LinkCourseOutcomeProgramOutcome) session .get(LinkCourseOutcomeProgramOutcome.class, id); session.delete(l); session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.ProgramManager.java
License:Open Source License
public boolean removeProgram(int programId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w w w . j ava 2s .co m*/ try { Program p = (Program) session.get(Program.class, programId); List<LinkProgramProgramOutcome> outcomeLinks = p.getLinkProgramOutcomes(); for (LinkProgramProgramOutcome link : outcomeLinks) { session.delete(link); } List<QuestionResponse> questionResponses = QuestionManager.instance() .getAllQuestionResponsesForProgram(p, session); for (QuestionResponse link : questionResponses) { session.delete(link); } List<LinkProgramQuestion> programQuestions = p.getLinkProgramQuestions(); for (LinkProgramQuestion link : programQuestions) { session.delete(link); } List<LinkCourseProgram> courseLinks = p.getLinkCoursePrograms(); for (LinkCourseProgram link : courseLinks) { session.delete(link); } @SuppressWarnings("unchecked") List<ProgramAdmin> adminLinks = session.createQuery("FROM ProgramAdmin WHERE program.id = :programId") .setParameter("programId", p.getId()).list(); for (ProgramAdmin link : adminLinks) { session.delete(link); } session.delete(p); session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.ProgramManager.java
License:Open Source License
@SuppressWarnings("unchecked") public boolean removeProgramOutcome(int outcomeLinkId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*w ww. j av a 2 s .c o m*/ try { LinkProgramProgramOutcome l = (LinkProgramProgramOutcome) session.get(LinkProgramProgramOutcome.class, outcomeLinkId); //delete associated characteristics List<LinkProgramProgramOutcomeCharacteristic> chars = session.createQuery( "FROM LinkProgramProgramOutcomeCharacteristic WHERE linkProgramProgramOutcome.id=:linkId") .setParameter("linkId", outcomeLinkId).list(); for (LinkProgramProgramOutcomeCharacteristic linkedChar : chars) { session.delete(linkedChar); } List<LinkCourseOfferingContributionProgramOutcome> offeringLinks = (List<LinkCourseOfferingContributionProgramOutcome>) session .createQuery( "FROM LinkCourseOfferingContributionProgramOutcome l where l.linkProgramOutcome.id=:linkId") .setParameter("linkId", outcomeLinkId).list(); if (offeringLinks != null) { for (LinkCourseOfferingContributionProgramOutcome li : offeringLinks) { session.delete(li); } } session.delete(l); session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.ProgramManager.java
License:Open Source License
public boolean moveCharacteristicType(int id, int charTypeId, String direction) { //when moving up, find the one to be moved (while keeping track of the previous one) and swap display_index values //when moving down, find the one to be moved, swap displayIndex values of it and the next one //when deleting, reduce all links following one to be deleted by 1 boolean done = false; Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w .j a va 2 s.c o m try { @SuppressWarnings("unchecked") List<LinkOrganizationCharacteristicType> existing = (List<LinkOrganizationCharacteristicType>) session .createQuery( "select l from LinkProgramCharacteristicType l where l.program.id = :programId order by l.displayIndex") .setParameter("programId", id).list(); if (direction.equals("up")) { LinkOrganizationCharacteristicType prev = null; for (LinkOrganizationCharacteristicType link : existing) { if (link.getCharacteristicType().getId() == charTypeId && prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(link.getDisplayIndex()); link.setDisplayIndex(swap); session.merge(prev); session.merge(prev); done = true; break; } prev = link; } } else if (direction.equals("down")) { LinkOrganizationCharacteristicType prev = null; for (LinkOrganizationCharacteristicType link : existing) { if (prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(link.getDisplayIndex()); link.setDisplayIndex(swap); session.merge(prev); session.merge(link); done = true; break; } if (link.getCharacteristicType().getId() == charTypeId) { prev = link; } } } else if (direction.equals("delete")) { LinkOrganizationCharacteristicType toDelete = null; for (LinkOrganizationCharacteristicType link : existing) { if (toDelete != null) { link.setDisplayIndex(link.getDisplayIndex() - 1); session.merge(link); } if (link.getCharacteristicType().getId() == charTypeId) { toDelete = link; } } if (toDelete != null) { session.delete(toDelete); done = true; } } session.getTransaction().commit(); return done; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.QuestionManager.java
License:Open Source License
@SuppressWarnings("unchecked") public boolean moveAnswerOption(int toMoveId, String direction) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w . j ava 2 s.co m try { AnswerOption toMove = (AnswerOption) session.get(AnswerOption.class, toMoveId); List<AnswerOption> existing = (List<AnswerOption>) session .createQuery("FROM AnswerOption WHERE answerSet.id=:answerSetId order by displayIndex") .setParameter("answerSetId", toMove.getAnswerSet().getId()).list(); if (direction.equals("up")) { AnswerOption prev = null; for (AnswerOption link : existing) { if (link.getId() == toMoveId && prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(link.getDisplayIndex()); link.setDisplayIndex(swap); session.merge(prev); session.merge(prev); break; } prev = link; } } else if (direction.equals("down")) { AnswerOption prev = null; for (AnswerOption link : existing) { if (prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(link.getDisplayIndex()); link.setDisplayIndex(swap); session.merge(prev); session.merge(link); break; } if (link.getId() == toMoveId) { prev = link; } } } else if (direction.equals("delete")) { AnswerOption toDelete = null; for (AnswerOption link : existing) { if (toDelete != null) { link.setDisplayIndex(link.getDisplayIndex() - 1); List<QuestionResponse> responsesUsingAnswer = (List<QuestionResponse>) session.createQuery( "FROM QuestionResponse WHERE question in (FROM Question WHERE answerSet.id=:answerSetId) AND response=:responseValue") .setParameter("answerSetId", toMove.getAnswerSet().getId()) .setParameter("responseValue", toMove.getValue()).list(); for (QuestionResponse resp : responsesUsingAnswer) { session.delete(resp); } session.merge(link); } if (link.getId() == toMoveId) { toDelete = link; } } if (toDelete != null) { session.delete(toDelete); } } session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.QuestionManager.java
License:Open Source License
@SuppressWarnings("unchecked") public boolean moveQuestion(int programId, int questionId, String direction) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w ww. ja v a 2s . c o m try { LinkProgramQuestion toMove = (LinkProgramQuestion) session .createQuery("FROM LinkProgramQuestion WHERE program.id=:programId AND question.id=:questionId") .setParameter("programId", programId).setParameter("questionId", questionId).uniqueResult(); int toMoveId = toMove.getId(); List<LinkProgramQuestion> existing = (List<LinkProgramQuestion>) session .createQuery("FROM LinkProgramQuestion WHERE program.id=:programId ORDER BY displayIndex") .setParameter("programId", toMove.getProgram().getId()).list(); if (direction.equals("up")) { LinkProgramQuestion prev = null; for (LinkProgramQuestion link : existing) { if (link.getId() == toMoveId && prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(link.getDisplayIndex()); link.setDisplayIndex(swap); session.merge(prev); session.merge(prev); break; } prev = link; } } else if (direction.equals("down")) { LinkProgramQuestion prev = null; for (LinkProgramQuestion link : existing) { if (prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(link.getDisplayIndex()); link.setDisplayIndex(swap); session.merge(prev); session.merge(link); break; } if (link.getId() == toMoveId) { prev = link; } } } else if (direction.equals("delete")) { LinkProgramQuestion toDelete = null; for (LinkProgramQuestion link : existing) { if (toDelete != null) { link.setDisplayIndex(link.getDisplayIndex() - 1); session.merge(link); } if (link.getId() == toMoveId) { toDelete = link; } } if (toDelete != null) { List<QuestionResponse> responsesToQuestion = (List<QuestionResponse>) session .createQuery("FROM QuestionResponse WHERE question.id=:questionId") .setParameter("questionId", questionId).list(); for (QuestionResponse resp : responsesToQuestion) session.delete(resp); session.delete(toDelete); } } session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.QuestionManager.java
License:Open Source License
public boolean deleteQuestion(int questionId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w w w .j a v a 2 s.co m*/ try { Question q = (Question) session.get(Question.class, questionId); @SuppressWarnings("unchecked") List<QuestionResponse> responsesToQuestion = (List<QuestionResponse>) session .createQuery("FROM QuestionResponse WHERE question.id=:questionId") .setParameter("questionId", q.getId()).list(); for (QuestionResponse resp : responsesToQuestion) session.delete(resp); @SuppressWarnings("unchecked") List<LinkProgramQuestion> questionLinks = (List<LinkProgramQuestion>) session .createQuery("FROM LinkProgramQuestion WHERE question.id=:questionId") .setParameter("questionId", q.getId()).list(); for (LinkProgramQuestion qLink : questionLinks) session.delete(qLink); session.delete(q); session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } }
From source file:ca.usask.gmcte.currimap.action.QuestionManager.java
License:Open Source License
public boolean clearResponsesForOfferingInProgram(Program p, int courseOfferingId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w ww . j a v a2 s .c o m*/ try { @SuppressWarnings("unchecked") List<QuestionResponse> questionResponses = (List<QuestionResponse>) session.createQuery( "FROM QuestionResponse WHERE program.id=:programId AND courseOffering.id=:courseOfferingId") .setParameter("programId", p.getId()).setParameter("courseOfferingId", courseOfferingId).list(); for (QuestionResponse responseToDelete : questionResponses) { session.delete(responseToDelete); } session.getTransaction().commit(); return true; } catch (Exception e) { try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } HibernateUtil.logException(logger, e); return false; } }
From source file:caipsfa.app.modelo.GestionDiagnostico.java
public boolean deleteDiagnostic(int id) { boolean estado = false; try {/*from w ww .j av a 2 s . com*/ SessionFactory sesFact = HibernateUtil.getSessionFactory(); Session ses = sesFact.openSession(); Transaction trans = ses.beginTransaction(); Diagnostico diagnostic = (Diagnostico) ses.get(Diagnostico.class, id); ses.delete(diagnostic); trans.commit(); ses.close(); estado = true; return estado; } catch (Exception e) { System.out.println(e); return estado; } }
From source file:caipsfa.app.modelo.GestionDoctores.java
public boolean deleteDoctor(int id) { boolean estado = false; try {/*from w w w .jav a 2 s . co m*/ SessionFactory sesFact = HibernateUtil.getSessionFactory(); Session ses = sesFact.openSession(); Transaction trans = ses.beginTransaction(); Doctores doctors = (Doctores) ses.get(Doctores.class, id); ses.delete(doctors); trans.commit(); ses.close(); estado = true; return estado; } catch (Exception e) { System.out.println(e); return estado; } }