Example usage for org.hibernate Session flush

List of usage examples for org.hibernate Session flush

Introduction

In this page you can find the example usage for org.hibernate Session flush.

Prototype

void flush() throws HibernateException;

Source Link

Document

Force this session to flush.

Usage

From source file:com.asociate.dao.AmistadDAO.java

/**
 *
 * @param idAmigo/*from  w  w  w.j  a  v a  2s  .c om*/
 * @param idOrigen
 * @param estado
 */
public void actualizarAmistad(Long idAmigo, Long idOrigen, String estado) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    try {
        Query qu = sesion.createQuery(
                "Update Amistad A set A.bloqueado=:est  where ((A.idAmigo:idA and A.idOrigen=:idO)or(A.idOrigen:idA1 and A.idAmigo=:idO1))");
        qu.setParameter("idO", idOrigen).setParameter("idA", idAmigo).setParameter("idA1", idOrigen)
                .setParameter("idO1", idAmigo).setParameter("est", estado);
        qu.executeUpdate();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @param regAsoc//w ww .j  av a  2s .c om
 * @return
 */
public boolean registrar(Asociacion regAsoc) {
    Boolean error = false;
    Transaction transaccion = null;
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    try {
        transaccion = sesion.beginTransaction();
        sesion.save(regAsoc);
        transaccion.commit();
    } catch (JDBCException c) {
        c.printStackTrace();
        error = true;
        if (transaccion != null) {
            transaccion.rollback();
        }

    } catch (Exception e) {
        e.printStackTrace();
        error = true;
        if (transaccion != null) {
            transaccion.rollback();
        }
    } finally {
        sesion.flush();
        sesion.close();

    }
    return error;
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @param id/*from w  w  w  .j  a  va  2 s . com*/
 * @return
 */
public Asociacion getAsociacionById(Long id) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    Asociacion salida = null;
    try {

        salida = (Asociacion) sesion.get(Asociacion.class, id);

    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }

    return salida;
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @return/*  w w w. ja v  a 2  s  .  com*/
 */
public List<Asociacion> getListaAsociaciones() {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Asociacion> salida = null;
    try {

        salida = sesion.createQuery("Select A from Asociacion A where A.completa = 'S'").list();

    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }

    return salida;
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @return/*from  w  ww. j a  v a2  s  . co m*/
 */
public List<Asociacion> getListaAsocPendiente() {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Asociacion> salida = null;
    try {

        salida = sesion.createQuery("Select A from Asociacion A where A.completa = 'N'").list();

    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }

    return salida;
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @param cif//from  w w  w  .  j a  va 2 s. c o m
 * @param estado
 */
public void actualizarAsociacion(String cif, String estado) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {

        sesion.createQuery("Update Asociacion A set A.completa=:es where A.cif=:cif").setParameter("es", estado)
                .setParameter("cif", cif).executeUpdate();
        sesion.createQuery(
                "Update Usuario U set U.bloqueado='S' where U.idUsuario =(Select A.idUsuario.idUsuario from Asociacion A where A.cif=:cif)")
                .setParameter("cif", cif).executeUpdate();

    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @param value/*from w  w  w.  jav  a  2  s .  c o m*/
 * @return
 */
public boolean comprobarCIF(String value) {
    boolean existe = false;
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    Query qu = sesion.createQuery("Select A.cif from Asociacion A where A.cif=:cif").setString("cif", value);
    Object salida = qu.uniqueResult();

    if (salida != null) {
        existe = true;
    }
    sesion.flush();
    sesion.close();

    return existe;
}

From source file:com.asociate.dao.ComentarioDAO.java

/**
 *
 * @param idUsuario//w w  w  .j  a va2 s . c  o m
 * @return
 */
public List<Comentario> getListaComentarioesPorId(Long idUsuario) {
    List<Comentario> salida = new ArrayList();
    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {
        salida = sesion.createQuery("Select C from Comentario C where C.idAutor.idUsuario=:id")
                .setParameter("id", idUsuario).list();

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return salida;

}

From source file:com.asociate.dao.ComentarioDAO.java

/**
 *
 * @param comentario/*from  ww w .  j a va 2 s  .c om*/
 */
public void guardar(Comentario comentario) {

    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {
        sesion.save(comentario);

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }

}

From source file:com.asociate.dao.DirectorioDAO.java

/**
 *
 * @param idAsociacion//from  w w  w  .  j ava2  s  .  c o m
 * @return
 */
public boolean hasDirectorioAsociacion(Long idAsociacion) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    Directorio dir = null;
    try {
        Query qu = sesion.createQuery(
                "Select D from Directorio D where D.idDirectorio = (Select A.idDirectorio from Asociacion A where A.idAsociacion=:idAsoc)");
        qu.setParameter("idAsoc", idAsociacion);
        qu.setMaxResults(1).getFirstResult();

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return dir != null;

}