List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:business.ChampionDB.java
public static List<Champion> loadChampions(int aid) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;// w w w .j a v a2s .c o m List<Champion> champs = null; try { String qS = "FROM Champion c WHERE c.accountID = :aid"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("aid", aid); champs = q.list(); } catch (HibernateException e) { champs = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return champs; }
From source file:business.ChampionDB.java
public static boolean checkChampionName(String name) { boolean used = false; SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*w w w . j a v a2s . co m*/ Champion c; try { String qS = "FROM Champion c WHERE c.name = :name"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("name", name); c = (Champion) q.uniqueResult(); used = true; } catch (NoResultException e) { used = false; } finally { if (session != null && session.isOpen()) { session.close(); } } return used; }
From source file:business.ChampionDB.java
public static String addNewChampion(Champion c) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from www . j a v a2 s . co m*/ String msg = ""; try { session = sessionFactory.openSession(); session.beginTransaction(); session.persist(c); session.getTransaction().commit(); session.flush(); session.refresh(c); msg = "Champion Created!"; } catch (HibernateException e) { msg = "Error Creating Champion: " + e.getMessage(); if (session != null && session.isOpen()) { session.getTransaction().rollback(); } } finally { session.close(); } return msg; }
From source file:business.MoveDB.java
public static List<Move> loadMoves() { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//from w ww . j a va2s. c o m List<Move> moves = null; try { String qS = "FROM Move m"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); moves = q.list(); } catch (HibernateException e) { moves = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return moves; }
From source file:business.MoveDB.java
public static String addNewMove(Move m) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//from w ww .j a v a 2 s . c om String msg = ""; try { session = sessionFactory.openSession(); session.beginTransaction(); session.persist(m); session.getTransaction().commit(); session.flush(); session.refresh(m); msg = "Move Added!"; } catch (HibernateException e) { msg = "Error Creating Move: " + e.getMessage(); if (session != null && session.isOpen()) { session.getTransaction().rollback(); } } finally { if (session != null && session.isOpen()) { session.close(); } } return msg; }
From source file:business.OpponentDB.java
public static Opponent findOpponent(int oppID) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from w ww . j av a 2s . c om*/ Opponent opp = null; try { String qS = "FROM Opponent o WHERE o.id = :oppID"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("oppID", oppID); opp = (Opponent) q.uniqueResult(); } catch (NoResultException e) { return null; } finally { if (session != null && session.isOpen()) { session.close(); } } return opp; }
From source file:business.PostDB.java
public static List<Post> loadPosts(int aid) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from w w w . j a v a 2 s. c om*/ List<Post> posts = null; try { String qS = "FROM Post p WHERE p.accountID = :aid"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("aid", aid); posts = q.list(); } catch (HibernateException e) { posts = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return posts; }
From source file:business.PostDB.java
public static String addNewPost(Post p) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//from ww w . j av a 2s .co m String msg = ""; try { session = sessionFactory.openSession(); session.beginTransaction(); session.persist(p); session.getTransaction().commit(); session.flush(); session.refresh(p); msg = "Post Added!"; } catch (HibernateException e) { msg = "Error Creating Post: " + e.getMessage(); session.getTransaction().rollback(); } finally { session.close(); } return msg; }
From source file:business.XPChartDB.java
public static List<XPChart> loadXPChart() { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from w w w. ja v a 2s. com*/ List<XPChart> xpchart = null; try { String qS = "FROM XPChart x"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); xpchart = q.list(); } catch (HibernateException e) { xpchart = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return xpchart; }
From source file:by.bsuir.akkerman.mobile.server.dao.DaoUniversal.java
public boolean add(EntityHelper obj) { boolean isSuccessfully = false; SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction();// www . ja va2 s .c o m try { session.save(obj); if (obj.getParent() != null) { Set<EntityHelper> set = new HashSet(obj.getParent()); for (Iterator it = set.iterator(); it.hasNext();) { EntityHelper parent_obj = (EntityHelper) session.get(it.next().getClass(), ((EntityHelper) it.next()).getId()); parent_obj.getChild().add(obj); session.update(parent_obj); } } isSuccessfully = true; } catch (HibernateException ex) { System.out.println(ex.getMessage()); } finally { session.getTransaction().commit(); } return isSuccessfully; }