Example usage for org.hibernate Session clear

List of usage examples for org.hibernate Session clear

Introduction

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

Prototype

void clear();

Source Link

Document

Completely clear the session.

Usage

From source file:es.emergya.bbdd.dao.FlotaHome.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Calendar lastUpdated() {
    Calendar res = Calendar.getInstance();
    try {/*from  w w  w.  j a v a 2  s  .  c o m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Flota.class)
                .setProjection(Projections.max("updatedAt"));
        res.setTime((Date) criteria.uniqueResult());
    } catch (NullPointerException t) {
        log.error("No hay datos en la tabla.");
        return null;
    } catch (Throwable t) {
        log.error(t, t);
        return null;
    }
    return res;
}

From source file:es.emergya.bbdd.dao.HistoricoGPSHome.java

License:Open Source License

@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public HistoricoGPS saveOrUpdate(HistoricoGPS hgps) {

    Session currentSession = getSession();
    currentSession.clear();

    HistoricoGPS entity = null;//from  ww w. j  a v a 2 s  .  c  o  m

    if (hgps.getId() == null || (hgps.getId() != null && this.get(hgps.getId()) == null))
        entity = hgps;
    else
        entity = (HistoricoGPS) currentSession.merge(hgps);

    currentSession.saveOrUpdate(entity);
    return entity;
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = Throwable.class)
public Integer getTotal() {
    try {//  w  w w.ja va 2  s .co  m
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class)
                .setProjection(Projections.rowCount());
        return (Integer) criteria.uniqueResult();
    } catch (Throwable t) {
        log.error(t, t);
        return -1;
    }
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Calendar lastUpdated() {
    Calendar res = Calendar.getInstance();
    try {//  w w w  .ja  va 2  s  . c  o m
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class)
                .setProjection(Projections.max("updatedAt"));
        res.setTime((Date) criteria.uniqueResult());
    } catch (NullPointerException t) {
        log.error("No hay datos en la tabla.");
        return null;
    } catch (Throwable t) {
        log.error(t, t);
        return null;
    }
    return res;
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<Incidencia> getAll() {
    List<Incidencia> res = new LinkedList<Incidencia>();
    try {/*from w w  w .j  av  a2  s  . c  o m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        res = (List<Incidencia>) criteria.list();
        for (Incidencia i : res) {
            if (i.getCreador() != null)
                i.getCreador().getId();
            if (i.getEstado() != null)
                i.getEstado().getId();
            if (i.getCategoria() != null)
                i.getCategoria().getId();
        }
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<Incidencia> getOpened() {
    List<Incidencia> res = new LinkedList<Incidencia>();
    try {/*from   ww w.  j  a  va  2 s. co m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class).createCriteria("estado")
                .add(Restrictions.ne("id", 3l)).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        res = (List<Incidencia>) criteria.list();

        for (Incidencia i : res)
            if (i != null) {
                if (i.getCreador() != null)
                    i.getCreador().getId();
                if (i.getEstado() != null)
                    i.getEstado().getId();
                if (i.getCategoria() != null)
                    i.getCategoria().getId();
            }
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Incidencia find(String identificador) {
    try {/*from ww w  . j  a  va 2 s  .c  o m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class)
                .add(Restrictions.eq("referenciaHumana", identificador))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setMaxResults(1);
        final Incidencia uniqueResult = (Incidencia) criteria.uniqueResult();
        return uniqueResult;
    } catch (Throwable t) {
        log.error(t, t);
    }
    return null;
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<Incidencia> getByExample(Incidencia f) {
    try {/*www.  ja  va 2s.c om*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Incidencia.class).addOrder(Order.asc("titulo"));

        // titulo
        if (f.getTitulo() != null && f.getTitulo().trim().length() > 0) {
            criteria.add(Restrictions.ilike("titulo", LogicConstants.getGenericString(f.getTitulo())));
        }

        // prioridad
        if (f.getPrioridad() != null) {
            criteria.add(Restrictions.eq("prioridad", f.getPrioridad()));
        }

        // categoria
        if (f.getCategoria() != null) {
            criteria.createAlias("categoria", "cat")
                    .add(Restrictions.eq("cat.identificador", f.getCategoria().getIdentificador()));
        }

        // estado
        if (f.getEstado() != null) {
            criteria.createAlias("estado", "est")
                    .add(Restrictions.eq("est.identificador", f.getEstado().getIdentificador()));
        } else {
            criteria.createAlias("estado", "est").add(Restrictions.ne("est.id", 3l));
        }

        List<Incidencia> res = new LinkedList<Incidencia>();
        res = criteria.list();
        for (Incidencia i : res)
            if (i != null) {
                if (i.getCreador() != null)
                    i.getCreador().getId();
                if (i.getEstado() != null)
                    i.getEstado().getId();
                if (i.getCategoria() != null)
                    i.getCategoria().getId();
            }
        return res;
    } catch (Throwable t) {
        log.error("Error extrayendo las categorias de las incidencias", t);
    }
    return new LinkedList<Incidencia>();
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<Object> getCategorias() {
    try {//from   w  w  w .jav  a  2  s  .  com
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CategoriaIncidencia.class)
                .addOrder(Order.asc("identificador"));
        return criteria.list();
    } catch (Throwable t) {
        log.error("Error extrayendo las categorias de las incidencias", t);
    }
    return new LinkedList<Object>();
}

From source file:es.emergya.bbdd.dao.IncidenciaHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<Object> getStatuses() {
    try {/*from  w ww  .  j  a v  a  2s .  c  o  m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(EstadoIncidencia.class)
                .addOrder(Order.asc("identificador"));
        return criteria.list();
    } catch (Throwable t) {
        log.error("Error extrayendo los estados de las incidencias", t);
    }
    return new LinkedList<Object>();
}