List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:manejadorDB.controlador.UsuarioControlador.java
@Override public Usuario cambioContrasenha(Usuario user) { SessionFactory factory = Sesion.init(); if (user != null) { try {//from ww w .j a v a 2 s . c o m Session session = factory.getCurrentSession(); session.beginTransaction(); session.update(user); session.getTransaction().commit(); } catch (Exception e) { user = null; e.printStackTrace(); } finally { Sesion.close(); } return user; } else { return null; } }
From source file:manejadorDB.controlador.UsuarioControlador.java
@Override public void eliminar(Usuario usuario) { SessionFactory factory = Sesion.init(); if (factory != null) { try {/*from w w w. j a va 2s . c o m*/ //crear sesion Session session = factory.getCurrentSession(); //transaccion session.beginTransaction(); //eliminar session.delete(usuario); //commitear transaccion session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { Sesion.close(); } } }
From source file:manejadorDB.controlador.VueloControlador.java
@Override public void crear(Vuelo vuelo) { SessionFactory factory = Sesion.init(); if (factory != null) { try {/*from w w w . j a v a 2s . com*/ //crear sesion Session session = factory.getCurrentSession(); //transaccion session.beginTransaction(); //guardar aeropuerto session.save(vuelo); //commitear transaccion session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { Sesion.close(); } } }
From source file:manejadorDB.controlador.VueloControlador.java
@Override public List<Vuelo> todos() { List<Vuelo> vuelos = null; SessionFactory factory = Sesion.init(); if (factory != null) { try {/*from w w w .j a v a2 s . com*/ //crear sesion Session session = factory.getCurrentSession(); //transaccion session.beginTransaction(); //obtener lista vuelos = session.createNamedQuery("Vuelo.findAll").list(); //commitear transaccion session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { Sesion.close(); } } return vuelos; }
From source file:manejadorDB.controlador.VueloControlador.java
@Override public int cantidad() { List<Vuelo> vuelos = null; SessionFactory factory = Sesion.init(); if (factory != null) { try {// w w w . j a v a2s .c o m //crear sesion Session session = factory.getCurrentSession(); //transaccion session.beginTransaction(); //obtener lista vuelos = session.createNamedQuery("Vuelo.findAll").list(); //commitear transaccion session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { Sesion.close(); } } if (vuelos == null) return 0; else return vuelos.size(); }
From source file:model.ThuaDatControl.java
public List<tblThuaDat> getAllLands() { List<tblThuaDat> lst = new ArrayList<>(); SessionFactory factory = HibernateUltils2.getSessionFactory(); Session session = factory.getCurrentSession(); try {/* w ww. j a va 2 s .co m*/ //tat ca cac lenh hanh dong voi db thong qua hibernate //deu phai nam trong 1 giao dich //bat dau giao dich session.getTransaction().begin(); //tao mot cau lenh HQL query object String sql = "select e from " + tblThuaDat.class.getName() + "" + "order by e.SHBANDO"; //tao query den csdl Query query = session.createQuery(sql); //thuc hien truy van lst = query.list(); //commit du lieu session.getTransaction().commit(); } catch (Exception ex) { ex.printStackTrace(); //rollback trong truong hop co loi session.getTransaction().rollback(); } return lst; }
From source file:models.AdminModel.java
public static List<Admin> getAllAdmin() { //sf=H.getSessionFactory(); SessionFactory sf = H.getSessionFactory(); List<Admin> res = null; try {/*from ww w . ja v a2 s . c o m*/ sf.getCurrentSession().beginTransaction(); res = sf.getCurrentSession().createCriteria(Admin.class).list(); sf.getCurrentSession().close(); //sf.close(); } catch (Exception e) { sf.getCurrentSession().close(); } return res; }
From source file:models.AdminModel.java
public static Admin getAdminById(String Id) { Admin res = null;// w w w . jav a 2 s. co m SessionFactory sf = H.getSessionFactory(); try { sf.getCurrentSession().beginTransaction(); res = (Admin) sf.getCurrentSession().get(Admin.class, Id); sf.getCurrentSession().close(); } catch (Exception e) { // TODO: handle exception sf.getCurrentSession().close(); } return res; }
From source file:models.AdminModel.java
public static void SaveOrUpdateAdm(Admin a) { SessionFactory sf = H.getSessionFactory(); try {// ww w . j a va 2 s . c om sf.getCurrentSession().beginTransaction(); sf.getCurrentSession().saveOrUpdate(a); sf.getCurrentSession().getTransaction().commit(); sf.getCurrentSession().close(); } catch (Exception e) { sf.getCurrentSession().close(); } }
From source file:models.AdminModel.java
public static void DeteleAdmin(Admin admin) { SessionFactory sf = H.getSessionFactory(); try {/*from w w w.j a va 2s .co m*/ sf.getCurrentSession().beginTransaction(); sf.getCurrentSession().delete(admin); sf.getCurrentSession().getTransaction().commit(); sf.getCurrentSession().close(); } catch (Exception e) { sf.getCurrentSession().close(); } }