List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:ca.usask.gmcte.currimap.action.PermissionsManager.java
License:Open Source License
public boolean saveInstructor(int id, String userid, String first, String last) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from www .java 2 s .c o m*/ try { boolean createNew = true; Instructor i = new Instructor(); if (id > -1) { i = (Instructor) session.get(Instructor.class, id); createNew = false; } else { i = (Instructor) session.createQuery("FROM Instructor where lower(userid) = :userid") .setParameter("userid", userid.toLowerCase()).uniqueResult(); if (i == null) i = new Instructor(); } i.setUserid(userid); i.setFirstName(first); i.setLastName(last); if (createNew) session.save(i); else session.merge(i); 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 Instructor getInstructorById(int id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w .j a v a 2s . c om Instructor toReturn = null; try { toReturn = (Instructor) session.get(Instructor.class, id); session.getTransaction().commit(); } catch (Exception e) { HibernateUtil.logException(logger, e); } return toReturn; }
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();//from w ww. j a v a2s .c o 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 ww w . j a v a 2 s . 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 save(String name, String description, String organizationId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w w w . ja v a 2 s . c o m*/ try { /** Creating Pojo */ Organization organization = (Organization) session.get(Organization.class, Integer.parseInt(organizationId)); Program o = new Program(); o.setOrganization(organization); o.setName(name); o.setDescription(description); session.save(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.ProgramManager.java
License:Open Source License
public boolean saveProgramOutcomeGroupNameById(String value, int programOutcomeGroupId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w ww .j av a 2 s . c o m try { ProgramOutcomeGroup o = (ProgramOutcomeGroup) session.get(ProgramOutcomeGroup.class, programOutcomeGroupId); 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.ProgramManager.java
License:Open Source License
public boolean saveProgramOutcomeNameById(String value, int programOutcomeId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from www .j a va 2 s . c o m*/ try { ProgramOutcome o = (ProgramOutcome) session.get(ProgramOutcome.class, programOutcomeId); 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.ProgramManager.java
License:Open Source License
public boolean saveNewProgramOutcomeNameAndGroup(String value, int programOutcomeGroupId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from www .j a v a 2s . com*/ try { ProgramOutcome o = new ProgramOutcome(); ProgramOutcomeGroup group = (ProgramOutcomeGroup) session.get(ProgramOutcomeGroup.class, programOutcomeGroupId); o.setGroup(group); o.setDescription(""); o.setName(value); session.save(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.ProgramManager.java
License:Open Source License
public boolean saveProgramOutcomeDescriptionById(String value, int programOutcomeId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from ww w . j ava 2s .co m*/ try { ProgramOutcome o = (ProgramOutcome) session.get(ProgramOutcome.class, programOutcomeId); 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.ProgramManager.java
License:Open Source License
public boolean saveCourseOutcomeProgramOutcome(int outcomeId, int programOutcomeId, int courseOfferingId, int existingLinkId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* w ww . j av a2 s. com*/ 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; } }