Example usage for org.hibernate SessionFactory getCurrentSession

List of usage examples for org.hibernate SessionFactory getCurrentSession

Introduction

In this page you can find the example usage for org.hibernate SessionFactory getCurrentSession.

Prototype

Session getCurrentSession() throws HibernateException;

Source Link

Document

Obtains the current session.

Usage

From source file:manejadorDB.controlador.PaqueteControlador.java

@Override
public List<Paquete> buscarPorFechasRegistro(Date fechaInicio, Date fechaFin) {
    List<Paquete> paquetes = null;
    SessionFactory factory = Sesion.init();
    if (factory != null) {
        try {/*from w ww .  j  a va  2  s  .c om*/
            //crear sesion
            Session session = factory.getCurrentSession();
            //transaccion
            session.beginTransaction();
            //obtener lista 
            paquetes = session.createNamedQuery("Paquete.findByfechas").setParameter("fechainicio", fechaInicio)
                    .setParameter("fechafin", fechaFin).list();
            //commitear transaccion
            session.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }
    return paquetes;
}

From source file:manejadorDB.controlador.PaqueteControlador.java

@Override
public Paquete obtener_paquete(int id) {
    Paquete paquete = null;/*from  w w w.  j  av a  2 s. c  om*/

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener paquete 
            paquete = session.get(Paquete.class, id);

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }

    }

    return paquete;
}

From source file:manejadorDB.controlador.PerfilControlador.java

@Override
public void crear(Perfil perfil) {

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {//from  w  w  w.  j ava2  s  .  com
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //guardar aeropuerto
            session.save(perfil);

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

}

From source file:manejadorDB.controlador.PerfilControlador.java

@Override
public List<Perfil> todos() {

    List<Perfil> perfiles = null;

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {/*  ww  w .j  a v a  2s . c  om*/
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener lista 
            perfiles = session.createNamedQuery("Perfil.findAll").list();

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

    return perfiles;
}

From source file:manejadorDB.controlador.PerfilControlador.java

@Override
public int cantidad() {
    List<Perfil> perfiles = null;

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {//ww w  .j  a v a2 s .  c  o  m
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener lista 
            perfiles = session.createNamedQuery("Perfil.findAll").list();

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

    if (perfiles == null)
        return 0;
    else
        return perfiles.size();
}

From source file:manejadorDB.controlador.PerfilControlador.java

@Override
public Perfil devolverPerfilPorID(Integer idPerfil) {
    List<Perfil> perfiles = null;

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {//  ww w .j a va  2  s. co  m
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener lista 
            perfiles = session.createNamedQuery("Perfil.findByIdperfil").setParameter("idperfil", idPerfil)
                    .list();

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

    if (perfiles != null && perfiles.size() > 0) {
        return perfiles.get(0);
    } else {
        return null;
    }

}

From source file:manejadorDB.controlador.PerfilControlador.java

@Override
public Perfil devolverPerfilPorNivelAcceso(Integer nivelAcceso) {
    List<Perfil> perfiles = null;

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {//ww  w  .j  ava2s  .  co  m
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener lista 
            perfiles = session.createNamedQuery("Perfil.findByNivelacceso")
                    .setParameter("nivelacceso", nivelAcceso).list();

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

    if (perfiles != null && perfiles.size() > 0) {
        return perfiles.get(0);
    } else {
        return null;
    }
}

From source file:manejadorDB.controlador.PersonaControlador.java

@Override
public Persona crear(Persona persona) {

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {//from   w  ww  . jav  a  2 s  .c o  m
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //guardar aeropuerto
            session.save(persona);

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }
    return persona;
}

From source file:manejadorDB.controlador.PersonaControlador.java

@Override
public List<Persona> todos() {

    List<Persona> personas = null;

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {/*from w w  w  . ja va2 s . co m*/
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener lista 
            personas = session.createNamedQuery("Persona.findAll").list();

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

    return personas;
}

From source file:manejadorDB.controlador.PersonaControlador.java

@Override
public int cantidad() {
    List<Persona> personas = null;

    SessionFactory factory = Sesion.init();
    if (factory != null) {

        try {/* w  ww  .  j ava 2  s. c o m*/
            //crear sesion
            Session session = factory.getCurrentSession();

            //transaccion
            session.beginTransaction();

            //obtener lista 
            personas = session.createNamedQuery("Persona.findAll").list();

            //commitear transaccion
            session.getTransaction().commit();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Sesion.close();
        }
    }

    if (personas == null)
        return 0;
    else
        return personas.size();
}