List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:DataLayer.CtrlJoc2048DB.java
@Override public Joc2048 get() { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*ww w. ja va 2 s . c o m*/ List<Joc2048> l = session.createQuery("from Joc2048").list(); session.getTransaction().commit(); factory.close(); if (!l.isEmpty()) return l.get(0); else { Joc2048 j = Joc2048.joc2048(); return j; } }
From source file:DataLayer.CtrlJugadorDB.java
@Override public Jugador getU(String username) throws Exception { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();//from ww w . j a va 2 s. c om List<Jugador> l = session.createQuery("from Jugador where username = :usr").setParameter("usr", username) .list(); session.getTransaction().commit(); factory.close(); if (!l.isEmpty()) return l.get(0); throw new Exception("jugadorNoExisteix"); }
From source file:DataLayer.CtrlJugadorDB.java
@Override public Jugador getE(String email) throws Exception { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w w w. ja v a 2 s. c om*/ List<Jugador> l = session.createQuery("from Jugador where email = :em").setParameter("em", email).list(); session.getTransaction().commit(); factory.close(); if (!l.isEmpty()) return l.get(0); throw new Exception("jugadorNoExisteix"); }
From source file:DataLayer.CtrlJugadorDB.java
@Override public Boolean existsU(String username) { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*from ww w .j a va 2 s .c o m*/ List<Jugador> l = session.createQuery("from Jugador where username = :usr").setParameter("usr", username) .list(); session.getTransaction().commit(); factory.close(); return !l.isEmpty(); }
From source file:DataLayer.CtrlJugadorDB.java
@Override public Boolean existsE(String email) { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();//from w w w .j av a2 s . c o m List<Jugador> l = session.createQuery("from Jugador where email = :em").setParameter("em", email).list(); session.getTransaction().commit(); factory.close(); return !l.isEmpty(); }
From source file:DataLayer.CtrlJugadorDB.java
@Override public Set<Jugador> all() { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w ww . ja v a 2s .c om*/ List<Jugador> l = session.createQuery("from Jugador").list(); session.getTransaction().commit(); factory.close(); Set<Jugador> r = new HashSet(); for (Jugador j : l) { r.add(j); } return r; }
From source file:DataLayer.CtrlPartidaDB.java
@Override public Partida get(Integer idPartida) throws Exception { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*from www . j av a2s . c o m*/ List<Partida> l = session.createQuery("from Partida where idPartida = :idP").setParameter("idP", idPartida) .list(); session.getTransaction().commit(); factory.close(); if (!l.isEmpty()) { return l.get(0); } throw new Exception("partidaNoExisteix"); }
From source file:DataLayer.CtrlPartidaDB.java
@Override public boolean exists(Integer idPartida) { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*from ww w .j a v a 2 s . com*/ List<Partida> l = session.createQuery("from Partida where idPartida = :idP").setParameter("idP", idPartida) .list(); session.getTransaction().commit(); factory.close(); return !l.isEmpty(); }
From source file:DataLayer.CtrlPartidaDB.java
@Override public Set<Partida> all() { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();// w w w. java 2 s.c om List<Partida> l = session.createQuery("from Partida").list(); session.getTransaction().commit(); factory.close(); Set<Partida> r = new HashSet(); for (Partida p : l) { r.add(p); } return r; }
From source file:DataLayer.CtrlUsuariRegistratDB.java
@Override public UsuariRegistrat get(String username) throws Exception { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Partida.class); config.addAnnotatedClass(Casella.class); config.addAnnotatedClass(Jugador.class); config.addAnnotatedClass(UsuariRegistrat.class); config.addAnnotatedClass(Joc2048.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w w w . j a va 2 s . c om*/ List<UsuariRegistrat> l = session.createQuery("from UsuariRegistrat where username = :usr") .setParameter("usr", username).list(); session.getTransaction().commit(); factory.close(); if (!l.isEmpty()) { return l.get(0); } throw new Exception("usernameNoExisteix"); //To change body of generated methods, choose Tools | Templates. }