List of usage examples for org.hibernate Session clear
void clear();
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public Rol find(String nombreRol) { Session currentSession = getSession(); currentSession.clear(); return (Rol) currentSession.createCriteria(Rol.class).add(Restrictions.ilike("nombre", nombreRol)) .uniqueResult();/*from w w w .j a v a 2s . c o m*/ }
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Rol> findByName(String nombreRol) { Session currentSession = getSession(); currentSession.clear(); return (List<Rol>) currentSession.createCriteria(Rol.class).add(Restrictions.ilike("nombre", nombreRol)) .addOrder(Order.asc("nombre")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); }
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public boolean delete(Rol rol) { if (rol == null || rol.getId() == null) return true; Session currentSession = getSession(); currentSession.clear(); try {/*from ww w . j a v a 2 s . co m*/ rol = this.get(rol.getId()); } catch (Throwable t) { log.error("Tiene toda la pinta de que estamos borrando un objeto ya borrado", t); } if (rol != null && (rol.getUsuarios() == null || rol.getUsuarios().size() == 0)) { if (rol.getFlotas() != null) { for (Flota f : rol.getFlotas()) { f.getRoles().remove(rol); currentSession.saveOrUpdate(f); } } this.remove(rol.getId()); return true; } return false; }
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public boolean saveOrUpdate(final Rol rol) { Session currentSession = getSession(); currentSession.clear(); Rol entity = null;/*from w ww. j a va 2 s .co m*/ final Set<Flota> flotas = rol.getFlotas(); if (rol.getId() != null && this.get(rol.getId()) != null) entity = this.get(rol.getId()); if (entity == null) entity = rol; if (entity == null) return false; entity.setInfoAdicional(rol.getInfoAdicional()); currentSession.saveOrUpdate(entity); if (entity != null && flotas != null) { for (Flota f : flotas) { try { Flota flota = (Flota) currentSession.get(Flota.class, f.getId()); flota.getRoles().add(entity); entity.getFlotas().add(flota); currentSession.saveOrUpdate(flota); } catch (Throwable t) { log.error(t); } } } return true; }
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public void removeFlotas(Rol rol) { if (rol == null || rol.getId() == null) return;//from ww w .j a v a 2 s .c o m Session currentSession = getSession(); currentSession.clear(); Rol entity = this.get(rol.getId()); if (entity == null) return; if (entity.getFlotas() != null) for (Flota f : entity.getFlotas()) { if (!rol.getFlotas().contains(f)) { log.debug("Borrando la flota " + f + " del rol " + entity); f.getRoles().remove(entity); currentSession.saveOrUpdate(f); } else log.debug("La flota " + f + " permanece en el rol " + entity); } entity.setFlotas(new HashSet<Flota>()); currentSession.saveOrUpdate(entity); }
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Flota> getAsigned(Rol r) { if (r == null || r.getId() == null) return new ArrayList<Flota>(0); log.debug("getAsigned(" + r.getId() + ")"); Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Flota.class).add(Restrictions.eq("habilitada", true)) .createCriteria("roles").add(Restrictions.in("id", new Long[] { r.getId() })); return (List<Flota>) criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list(); }
From source file:es.emergya.bbdd.dao.RolHome.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 . j a va2 s . co m Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Rol.class) .setProjection(Projections.max("updatedAt")); res.setTime((Date) criteria.uniqueResult()); } catch (Throwable t) { log.error(t, t); return null; } return res; }
From source file:es.emergya.bbdd.dao.StreetHome.java
License:Open Source License
@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public boolean saveOrUpdate(Street s) { boolean res = true; if (s == null || s.getId() == null) { return res; }/*from w ww.j ava 2 s . c o m*/ Session currentSession = getSession(); currentSession.clear(); Street entity = get(s.getId()); if (entity != null) { entity.setCentroid(s.getCentroid()); currentSession.saveOrUpdate(entity); } return res; }
From source file:es.emergya.bbdd.dao.UsuarioHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Integer getTotal() { Integer res = new Integer(-1); org.hibernate.Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Usuario.class).setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); res = count.intValue();// www. jav a 2s . c o m return res; }
From source file:es.emergya.bbdd.dao.UsuarioHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Boolean isLastAdmin(String nombre) { org.hibernate.Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Usuario.class).setProjection(Projections.rowCount()) .add(Restrictions.eq("administrador", true)).add(Restrictions.eq("habilitado", true)) .add(Restrictions.ne("nombreUsuario", nombre)).setCacheable(false); Integer count = (Integer) criteria.uniqueResult(); return (count.intValue() == 0); }