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.CapaInformacionHome.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Integer getTotal() {
    try {//from   www  .  j ava2s . c om
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .setProjection(Projections.rowCount());
        return (Integer) criteria.uniqueResult();
    } catch (Throwable t) {
        log.error(t, t);
        return -1;
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<CapaInformacion> getByFilter(CapaInformacion capaInfo) {
    List<CapaInformacion> res = new ArrayList<CapaInformacion>(0);
    try {/* w w  w  . j av a  2 s .  c o m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class);

        if (capaInfo.getInfoAdicional() != null) {
            criteria = criteria.add(Restrictions.ilike("infoAdicional",
                    LogicConstants.getGenericString(capaInfo.getInfoAdicional())));
        }

        if (capaInfo.getNombre() != null) {
            criteria = criteria
                    .add(Restrictions.ilike("nombre", LogicConstants.getGenericString(capaInfo.getNombre())));
        }

        if (capaInfo.getUrl() != null && capaInfo.getUrl().length() > 0) {
            criteria = criteria
                    .add(Restrictions.ilike("url", LogicConstants.getGenericString(capaInfo.getUrl())));
        }

        if (capaInfo.getOrden() != null) {
            criteria = criteria.add(Restrictions.eq("orden", capaInfo.getOrden()));
        }

        if (capaInfo.getHabilitada() != null) {
            criteria = criteria.add(Restrictions.eq("habilitada", capaInfo.getHabilitada()));
        }

        if (capaInfo.getOpcional() != null) {
            criteria = criteria.add(Restrictions.eq("opcional", capaInfo.getOpcional()));
        }

        criteria = criteria.addOrder(Order.asc("orden")).setCacheable(false)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        res = criteria.list();

        for (CapaInformacion c : res) {
            if (c != null) {
                if (c.getCapas() != null) {
                    for (Capa cap : c.getCapas()) {
                        if (cap != null) {
                            cap.getId();
                        }
                    }
                }
            }
        }

        if (log.isTraceEnabled()) {
            log.info("Sacamos de la base de datos las siguientes capas:");
            for (CapaInformacion capa : res) {
                log.info(" " + capa.getOrden() + ".- " + capa.getNombre());
            }
        }
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

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

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class)
public void removeUsuarios(CapaInformacion ci) {
    try {/*  ww w.  j  av a2  s  .co  m*/
        final Session currentSession = getSession();
        currentSession.clear();
        CapaInformacion r = this.get(ci.getId());
        if (r != null && r.getCapasInformacion() != null) {
            for (CapaInformacionUsuario capaUsuario : r.getCapasInformacion()) {
                currentSession.delete(capaUsuario);
            }
        }
    } catch (Throwable t) {
        log.error(t, t);
    }

}

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

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public boolean alreadyExists(String nombre) {
    Integer res = new Integer(-1);
    try {/*from w ww . j a va 2 s  . c o m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .setProjection(Projections.rowCount()).add(Restrictions.ilike("nombre", nombre));
        Integer count = (Integer) criteria.uniqueResult();
        res = count.intValue();
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res != 0;
}

From source file:es.emergya.bbdd.dao.CapaInformacionHome.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  a2  s .  com*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .setProjection(Projections.max("updatedAt"));
        res.setTime((Date) criteria.uniqueResult());
    } catch (Throwable t) {
        log.error("Error al buscar la ultima actualizacion de capas" + t);
        return null;
    }
    return res;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<CapaInformacion> getAll(boolean base, Boolean historico) {
    List<CapaInformacion> res = new LinkedList<CapaInformacion>();
    try {/*from w w w .  ja  v  a2 s .  c o m*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class).addOrder(Order.desc("orden"))
                .add(Restrictions.eq("opcional", (!base))).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        if (!base) {
            if (historico != null) {
                criteria = criteria.createCriteria("capasInformacion");
                if (!historico) {
                    criteria.add(Restrictions.eq("visibleGPS", true));
                } else {
                    criteria.add(Restrictions.eq("visibleHistorico", true));
                }
                criteria = criteria.add(Restrictions
                        .sqlRestriction("{alias}.fk_usuarios = " + Authentication.getUsuario().getId()));
            }
        }

        res = (List<CapaInformacion>) criteria.list();
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
@Override/*from w w  w.  ja v  a2s.  co m*/
public List<CapaInformacion> getAll() {
    List<CapaInformacion> res = new LinkedList<CapaInformacion>();
    try {
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        res = (List<CapaInformacion>) criteria.list();
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

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

License:Open Source License

/**
 *
 * @return  devuelve todas las capas de informacin ordenadas por el campo orden
 * ascendentemente.//  w  ww. j a v a2s  . c o  m
 */
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public List<CapaInformacion> getAllOrderedByOrden() {
    List<CapaInformacion> res = new LinkedList<CapaInformacion>();
    try {
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.addOrder(Order.asc("orden"));
        res = (List<CapaInformacion>) criteria.list();
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

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

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public CapaInformacion getByNombre(String nombre) {
    CapaInformacion res = null;/* w  ww.  j  a  va 2 s. co  m*/
    try {
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(CapaInformacion.class)
                .add(Restrictions.ilike("nombre", nombre));
        res = (CapaInformacion) criteria.uniqueResult();
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

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

License:Open Source License

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class)
public Integer getTotal() {
    try {/*  www. jav a 2s .  c  om*/
        Session currentSession = getSession();
        currentSession.clear();
        Criteria criteria = currentSession.createCriteria(Flota.class).add(Restrictions.eq("habilitada", true))
                .setProjection(Projections.rowCount());
        Integer count = (Integer) criteria.uniqueResult();
        return count.intValue();
    } catch (Throwable t) {
        log.error(t, t);
        return -1;
    }
}