List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:ca.myewb.frame.servlet.WrapperServlet.java
License:Open Source License
public static UserModel getUser(final String defaultPath, Logger log, Session hibernateSession, HttpSession httpSession) throws HibernateException, RedirectionException { UserModel user;/* w w w . ja v a 2 s.c o m*/ Integer userid = (Integer) httpSession.getAttribute("userid"); // New session: retrieve guest user from database if (httpSession.isNew() || (userid == null)) { httpSession.setMaxInactiveInterval(60 * 60); //increase session length to 1 hour userid = new Integer(1); log.debug("No userid found, forcing default user: guest..."); } user = (UserModel) hibernateSession.get(UserModel.class, userid); if (user == null) { log.warn("invalid userid in session! userid=" + userid); throw new RedirectionException(defaultPath); } log.debug("User identified: " + user.getUsername()); return user; }
From source file:ca.usask.gmcte.currimap.action.CharacteristicManager.java
License:Open Source License
public boolean updateCharacteristicType(String id, String name, String questionDisplay, String valueType) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//w ww.ja va2 s . c o m try { CharacteristicType c = (CharacteristicType) session.get(CharacteristicType.class, Integer.parseInt(id)); c.setName(name); c.setQuestionDisplay(questionDisplay); c.setValueType(valueType); session.merge(c); 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.CharacteristicManager.java
License:Open Source License
public boolean deleteCharacteristicsType(String toDelete) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();// ww w . ja va 2 s .c o m try { CharacteristicType ct = (CharacteristicType) session.get(CharacteristicType.class, Integer.parseInt(toDelete)); List<Characteristic> existing = this.getCharacteristicsForType(ct, session); for (Characteristic ch : existing) { deleteCharacteristic(ch, session); } @SuppressWarnings("unchecked") List<LinkOrganizationCharacteristicType> programLinks = session .createQuery( "FROM LinkOrganizationCharacteristicType WHERE characteristicType.id = :charTypeId") .setParameter("charTypeId", ct.getId()).list(); for (LinkOrganizationCharacteristicType pLink : programLinks) { session.delete(pLink); } session.delete(ct); 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.CharacteristicManager.java
License:Open Source License
public boolean moveCharacteristic(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 w w w.ja va 2s. c o m try { CharacteristicType ct = (CharacteristicType) session.get(CharacteristicType.class, charTypeId); List<Characteristic> existing = this.getCharacteristicsForType(ct, session); if (direction.equals("up")) { Characteristic prev = null; for (Characteristic ch : existing) { if (ch.getId() == id && prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(ch.getDisplayIndex()); ch.setDisplayIndex(swap); session.merge(prev); session.merge(ch); done = true; break; } prev = ch; } } else if (direction.equals("down")) { Characteristic prev = null; for (Characteristic ch : existing) { if (prev != null) { int swap = prev.getDisplayIndex(); prev.setDisplayIndex(ch.getDisplayIndex()); ch.setDisplayIndex(swap); session.merge(prev); session.merge(ch); done = true; break; } if (ch.getId() == id) { prev = ch; } } } else if (direction.equals("delete")) { Characteristic toDelete = null; for (Characteristic ch : existing) { if (toDelete != null) { ch.setDisplayIndex(ch.getDisplayIndex() - 1); session.merge(ch); } if (ch.getId() == id) { toDelete = ch; } } 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.CharacteristicManager.java
License:Open Source License
public Characteristic getCharacteristicById(int id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//w ww .j a v a2 s . c o m Characteristic c = null; try { c = (Characteristic) session.get(Characteristic.class, id); session.getTransaction().commit(); } catch (Exception e) { HibernateUtil.logException(logger, e); } return c; }
From source file:ca.usask.gmcte.currimap.action.CharacteristicManager.java
License:Open Source License
public Characteristic getCharacteristicById(int id, Session session) { Characteristic c = (Characteristic) session.get(Characteristic.class, id); return c;// w w w . j av a 2s.c o m }
From source file:ca.usask.gmcte.currimap.action.CharacteristicManager.java
License:Open Source License
public CharacteristicType getCharacteristicTypeById(int id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from ww w. j a v a2s . c om CharacteristicType c = null; try { c = (CharacteristicType) session.get(CharacteristicType.class, id); session.getTransaction().commit(); } catch (Exception e) { HibernateUtil.logException(logger, e); } return c; }
From source file:ca.usask.gmcte.currimap.action.CharacteristicManager.java
License:Open Source License
public CharacteristicType getCharacteristicTypeById(int id, Session session) { CharacteristicType c = (CharacteristicType) session.get(CharacteristicType.class, id); return c;//w w w. ja va 2 s.c o m }
From source file:ca.usask.gmcte.currimap.action.CourseManager.java
License:Open Source License
public boolean setCommentsForCourseOffering(int id, String comments, String type) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w ww.j a v a2 s .co m*/ try { CourseOffering c = (CourseOffering) session.get(CourseOffering.class, id); if (type.equals("teaching_comment")) c.setTeachingComment(comments); else if (type.equals("contribution_comment")) c.setContributionComment(comments); else if (type.equals("outcome_comment")) c.setOutcomeComment(comments); else c.setComments(comments); session.merge(c); 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.CourseManager.java
License:Open Source License
public boolean updateLinkCourseOfferingTeachingMethod(int id, int teachingMethod, int howLongId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w .j av a 2 s . co m try { LinkCourseOfferingTeachingMethod o = (LinkCourseOfferingTeachingMethod) session .get(LinkCourseOfferingTeachingMethod.class, id); TeachingMethod tm = (TeachingMethod) session.get(TeachingMethod.class, teachingMethod); TeachingMethodPortionOption howLong = (TeachingMethodPortionOption) session .get(TeachingMethodPortionOption.class, howLongId); o.setHowLong(howLong); o.setTeachingMethod(tm); 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; } }