List of usage examples for org.hibernate Session merge
Object merge(Object object);
From source file:ca.usask.gmcte.currimap.action.CourseManager.java
License:Open Source License
public boolean editInstructorAttributeValue(int id, String value) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();// w w w .ja v a 2s . c o m try { InstructorAttributeValue o = (InstructorAttributeValue) session.get(InstructorAttributeValue.class, id); o.setValue(value); session.merge(o); session.getTransaction().commit(); return true; } catch (Exception e) { HibernateUtil.logException(logger, e); return false; } }
From source file:ca.usask.gmcte.currimap.action.CourseManager.java
License:Open Source License
public boolean editCourseAttributeValue(int id, String value) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w .j av a2 s. c o m try { CourseAttributeValue o = (CourseAttributeValue) session.get(CourseAttributeValue.class, id); o.setValue(value); session.merge(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.OrganizationManager.java
License:Open Source License
public boolean update(String id, String name, String systemName, String active, int parentId, int oldParentId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w w w . j a va 2 s . c o m*/ try { Organization o = (Organization) session.get(Organization.class, Integer.parseInt(id)); if (oldParentId != parentId) { Organization parent = (Organization) session.get(Organization.class, parentId); o.setParentOrganization(parent); } o.setName(name); o.setActive(active); o.setSystemName(systemName); session.merge(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.OrganizationManager.java
License:Open Source License
public boolean saveOrganizationOutcomeGroupNameById(String value, int organizationOutcomeGroupId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from ww w .jav a2 s .c o m*/ try { OrganizationOutcomeGroup o = (OrganizationOutcomeGroup) session.get(OrganizationOutcomeGroup.class, organizationOutcomeGroupId); o.setName(value); session.merge(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.OrganizationManager.java
License:Open Source License
public boolean saveOrganizationOutcomeNameById(String value, int organizationOutcomeId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w w w . j av a2 s . c o m*/ try { OrganizationOutcome o = (OrganizationOutcome) session.get(OrganizationOutcome.class, organizationOutcomeId); o.setName(value); session.merge(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.OrganizationManager.java
License:Open Source License
public boolean saveOrganizationOutcomeDescriptionById(String value, int organizationOutcomeId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w ww. j av a 2s . c o m try { OrganizationOutcome o = (OrganizationOutcome) session.get(OrganizationOutcome.class, organizationOutcomeId); o.setDescription(value); session.merge(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.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 www .ja v a 2s . c o m 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 saveCourseOutcomeValue(CourseOutcome o, String name) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w .ja v a 2 s .c om try { o.setName(name); session.merge(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 updateCharacteristic(int courseOfferingId, int outcomeId, String characteristicValue, String characteristicType) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w. j a v a 2 s . co m try { CourseOutcome outcome = (CourseOutcome) session.get(CourseOutcome.class, outcomeId); CourseOffering courseOffering = (CourseOffering) session.get(CourseOffering.class, courseOfferingId); LinkCourseOfferingOutcome lco = getLinkCourseOfferingOutcome(courseOffering, outcome, session); CharacteristicType cType = getCharacteristicTypeById(Integer.parseInt(characteristicType), session); Characteristic characteristic = null; if (cType.getValueType().equals("String")) { characteristic = this.getCharacteristicById(Integer.parseInt(characteristicValue), session); } else if (cType.getValueType().equals("Boolean")) { characteristic = this.getCharacteristicByNameAndTypeId(characteristicValue, Integer.parseInt(characteristicType), session); } LinkCourseOfferingOutcomeCharacteristic characteristicLink = this.getCharacteristicLinkWithType(cType, lco, session); boolean createNew = false; if (characteristicLink == null) { characteristicLink = new LinkCourseOfferingOutcomeCharacteristic(); characteristicLink.setLinkCourseOfferingOutcome(lco); createNew = true; } characteristicLink.setCharacteristic(characteristic); characteristicLink.setCreatedByUserid("website"); characteristicLink.setCreatedOn(new Date(System.currentTimeMillis())); if (createNew) session.save(characteristicLink); else session.merge(characteristicLink); 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 updateProgramOutcomeCharacteristic(int linkId, String characteristicValue, String characteristicType, String creatorUserid) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w ww . j a v a 2s . com*/ try { LinkProgramProgramOutcome lpo = (LinkProgramProgramOutcome) session.get(LinkProgramProgramOutcome.class, linkId); CharacteristicType cType = getCharacteristicTypeById(Integer.parseInt(characteristicType), session); Characteristic characteristic = null; if (cType.getValueType().equals("String")) { characteristic = this.getCharacteristicById(Integer.parseInt(characteristicValue), session); } else if (cType.getValueType().equals("Boolean")) { characteristic = this.getCharacteristicByNameAndTypeId(characteristicValue, Integer.parseInt(characteristicType), session); } LinkProgramProgramOutcomeCharacteristic characteristicLink = this.getCharacteristicLinkWithType(cType, lpo, session); if (characteristicLink == null) { characteristicLink = new LinkProgramProgramOutcomeCharacteristic(); characteristicLink.setLinkProgramProgramOutcome(lpo); characteristicLink.setCharacteristic(characteristic); characteristicLink.setCreatedByUserid(creatorUserid); characteristicLink.setCreatedOn(new Date(System.currentTimeMillis())); session.save(characteristicLink); } else { characteristicLink.setCharacteristic(characteristic); characteristicLink.setCreatedByUserid(creatorUserid); characteristicLink.setCreatedOn(new Date(System.currentTimeMillis())); session.merge(characteristicLink); } 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; } }