List of usage examples for org.hibernate Session delete
void delete(Object object);
From source file:ca.usask.gmcte.currimap.action.OrganizationManager.java
License:Open Source License
public boolean removeLinkProgramOutcomeOrganizationOutcome(int id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w w w . j a v a 2s . c o m*/ try { LinkProgramOutcomeOrganizationOutcome l = (LinkProgramOutcomeOrganizationOutcome) session .get(LinkProgramOutcomeOrganizationOutcome.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.OrganizationManager.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 ava 2s . c om try { @SuppressWarnings("unchecked") List<LinkOrganizationCharacteristicType> existing = (List<LinkOrganizationCharacteristicType>) session .createQuery( "select l from LinkOrganizationCharacteristicType l where l.organization.id = :orgId order by l.displayIndex") .setParameter("orgId", 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(); } catch (Exception e) { HibernateUtil.logException(logger, e); try { session.getTransaction().rollback(); } catch (Exception e2) { logger.error("Unable to roll back!", e2); } return false; } return done; }
From source file:ca.usask.gmcte.currimap.action.OrganizationManager.java
License:Open Source License
public boolean removeCourseFromOrganization(String subject, String courseNumber, int organizationId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//ww w .j a v a2s . c om try { Course course = CourseManager.instance().getCourseBySubjectAndNumber(subject, courseNumber, session); LinkCourseOrganization toDelete = (LinkCourseOrganization) session .createQuery("FROM LinkCourseOrganization WHERE organization.id=:orgId and course.id=:courseId") .setParameter("orgId", organizationId).setParameter("courseId", course.getId()).uniqueResult(); 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.OutcomeManager.java
License:Open Source License
public boolean deleteOutcomeObject(String object, int id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w . j a va 2 s. co m try { if (object.equals("ProgramOutcome")) { ProgramOutcome o = (ProgramOutcome) session.get(ProgramOutcome.class, id); session.delete(o); } else if (object.equals("ProgramOutcomeGroup")) { ProgramOutcomeGroup o = (ProgramOutcomeGroup) session.get(ProgramOutcomeGroup.class, id); session.delete(o); } else if (object.equals("OrganizationOutcome")) { OrganizationOutcome o = (OrganizationOutcome) session.get(OrganizationOutcome.class, id); session.delete(o); } else if (object.equals("OrganizationOutcomeGroup")) { OrganizationOutcomeGroup o = (OrganizationOutcomeGroup) session.get(OrganizationOutcomeGroup.class, id); session.delete(o); } 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.OutcomeManager.java
License:Open Source License
public boolean deleteCourseOfferingOutcome(int outcomeId, int courseOfferingId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w w w .ja v a 2 s.co m*/ try { @SuppressWarnings("unchecked") List<LinkCourseOfferingOutcome> existing = (List<LinkCourseOfferingOutcome>) session.createQuery( "select l from LinkCourseOfferingOutcome l where l.courseOffering.id = :offeringId order by l.displayIndex") .setParameter("offeringId", courseOfferingId).list(); LinkCourseOfferingOutcome toDelete = null; for (LinkCourseOfferingOutcome link : existing) { if (toDelete != null) { link.setDisplayIndex(link.getDisplayIndex() - 1); session.merge(link); } if (link.getCourseOutcome().getId() == outcomeId) { toDelete = link; } } if (toDelete != null) { Set<LinkCourseOfferingOutcomeCharacteristic> existingCharacteristics = toDelete .getLinkCourseOfferingOutcomeCharacteristics(); for (LinkCourseOfferingOutcomeCharacteristic linkToDelete : existingCharacteristics) { session.delete(linkToDelete); } List<LinkCourseOutcomeProgramOutcome> existingLinks = ProgramManager.instance() .getProgramOutcomeLinksForCourseOutcome(courseOfferingId, outcomeId, session); for (LinkCourseOutcomeProgramOutcome programLinktoDelete : existingLinks) { session.delete(programLinktoDelete); } @SuppressWarnings("unchecked") List<LinkAssessmentCourseOutcome> existingAssessmentLinks = (List<LinkAssessmentCourseOutcome>) session .createQuery( "from LinkAssessmentCourseOutcome l where l.courseOffering.id=:courseOfferingId AND l.outcome.id=:outcomeId") .setParameter("courseOfferingId", courseOfferingId).setParameter("outcomeId", outcomeId) .list(); for (LinkAssessmentCourseOutcome assessmentLinktoDelete : existingAssessmentLinks) { session.delete(assessmentLinktoDelete); } session.refresh(toDelete); session.delete(toDelete); } // CourseOutcome toDelete = (CourseOutcome)session.get(CourseOutcome.class, outcomeId); // 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.OutcomeManager.java
License:Open Source License
public boolean deleteOutcomeAssessmentLink(int linkToDelete) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w w w .j a v a2 s . c o m*/ try { LinkAssessmentCourseOutcome link = (LinkAssessmentCourseOutcome) session .get(LinkAssessmentCourseOutcome.class, linkToDelete); session.delete(link); 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.PermissionsManager.java
License:Open Source License
public boolean removeSystemPermission(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* ww w . ja va 2s . co m*/ try { SystemAdmin p = (SystemAdmin) session.get(SystemAdmin.class, Integer.parseInt(id)); 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.PermissionsManager.java
License:Open Source License
public boolean removeOrganizationPermission(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w. j a v a 2s . c o m try { OrganizationAdmin p = (OrganizationAdmin) session.get(OrganizationAdmin.class, Integer.parseInt(id)); 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
public boolean saveCourseOutcomeProgramOutcome(int outcomeId, int programOutcomeId, int courseOfferingId, int existingLinkId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w .j av a2 s . c om try { ProgramOutcome pOutcome = (ProgramOutcome) session.get(ProgramOutcome.class, programOutcomeId); CourseOffering courseOffering = (CourseOffering) session.get(CourseOffering.class, courseOfferingId); CourseOutcome outcome = (CourseOutcome) session.get(CourseOutcome.class, outcomeId); logger.debug(outcomeId + " " + (outcome == null)); LinkCourseOutcomeProgramOutcome o = null; if (existingLinkId > -1) // need to update or delete { o = (LinkCourseOutcomeProgramOutcome) session.get(LinkCourseOutcomeProgramOutcome.class, existingLinkId); if (outcomeId > -1) { o.setCourseOutcome(outcome); session.merge(o); } else session.delete(o); // contribution is invalid (or 0) Delete it } else { //need to create a new one o = new LinkCourseOutcomeProgramOutcome(); o.setCourseOffering(courseOffering); o.setCourseOutcome(outcome); o.setProgramOutcome(pOutcome); session.save(o); } session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); logger.error("Oops " + outcomeId + " " + programOutcomeId + " " + courseOfferingId, 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 removeProgramCourse(int courseLinkId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w . j a v a 2s . c om try { LinkCourseProgram l = (LinkCourseProgram) session.get(LinkCourseProgram.class, courseLinkId); Program p = l.getProgram(); Course c = l.getCourse(); //any program contributions in the system linked to the course offering and program outcomes need to be deleted as well. @SuppressWarnings("unchecked") List<LinkCourseOfferingContributionProgramOutcome> offeringContributions = (List<LinkCourseOfferingContributionProgramOutcome>) session .createQuery("FROM LinkCourseOfferingContributionProgramOutcome lcoc " + "WHERE linkProgramOutcome IN (SELECT l FROM LinkProgramProgramOutcome l WHERE l.program.id=:programId) " + " AND lcoc.courseOffering.course.id = :courseId") .setParameter("programId", p.getId()).setParameter("courseId", c.getId()).list(); for (LinkCourseOfferingContributionProgramOutcome contr : offeringContributions) { session.delete(contr); } //any program contributions in the system linked to the course and program outcomes need to be deleted as well. @SuppressWarnings("unchecked") List<LinkCourseContributionProgramOutcome> courseContributions = (List<LinkCourseContributionProgramOutcome>) session .createQuery("FROM LinkCourseContributionProgramOutcome lcoc " + "WHERE linkProgramOutcome IN (SELECT l FROM LinkProgramProgramOutcome l WHERE l.program.id=:programId) " + " AND lcoc.course.id = :courseId") .setParameter("programId", p.getId()).setParameter("courseId", c.getId()).list(); for (LinkCourseContributionProgramOutcome contr : courseContributions) { session.delete(contr); } @SuppressWarnings("unchecked") List<LinkCourseOutcomeProgramOutcome> courseOutcomeLinks = (List<LinkCourseOutcomeProgramOutcome>) session .createQuery("FROM LinkCourseOutcomeProgramOutcome " + " WHERE courseOffering.course.id=:courseId " + " AND programOutcome IN (SELECT l.programOutcome FROM LinkProgramProgramOutcome l WHERE l.program.id=:programId)") .setParameter("courseId", c.getId()).setParameter("programId", p.getId()).list(); for (LinkCourseOutcomeProgramOutcome link : courseOutcomeLinks) { session.delete(link); } 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; } }