List of usage examples for org.hibernate Session clear
void clear();
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Recurso[] getNearest(double x, double y, Integer num, Usuario u) { List<Recurso> res = new LinkedList<Recurso>(); Session currentSession = getSession(); currentSession.clear(); Coordinate coordinate = new Coordinate(x, y); Point p = (new GeometryFactory()).createPoint(coordinate); p.setSRID(LogicConstants.SRID);/*from w w w. j a v a2 s . c o m*/ try { final DistanceOrder order = DistanceOrder.des("historico1_.geom", p); // final Criteria criteria = currentSession.createCriteria( // Recurso.class).setResultTransformer( // Criteria.DISTINCT_ROOT_ENTITY).createAlias("historicoGps", // "historico").createCriteria("flotas").createCriteria( // "roles").createCriteria("usuarios").add( // Restrictions.eq("id", u.getId())).addOrder(order) // .setMaxResults(num); Query criteria = currentSession.createSQLQuery("select this_.* from recursos this_ " + "inner join flotas flota2_ on this_.flota_x_flota=flota2_.x_flota " + "inner join ROLES_X_FLOTAS roles15_ on flota2_.x_flota=roles15_.X_FLOTA " + "inner join roles rol3_ on roles15_.X_ROL=rol3_.x_rol " + "inner join usuarios usuario4_ on rol3_.x_rol=usuario4_.fk_roles " + "inner join historico_gps historico1_ on this_.fk_historico_gps=historico1_.x_historico " + ((u != null && u.getId() != null) ? "where usuario4_.x_usuarios=:ID " + " and historico1_.marca_temporal > :TIMEOUT " : "") + "order by " + order.toString()).addEntity(Recurso.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setMaxResults(num); if (u != null && u.getId() != null) { criteria = criteria.setLong("ID", u.getId()); } Calendar timeout = Calendar.getInstance(); timeout.add(Calendar.MINUTE, -LogicConstants.getInt("AVL_TIMEOUT", 30)); criteria.setTimestamp("TIMEOUT", timeout.getTime()); log.debug(criteria); res = criteria.list(); for (Recurso uniqueResult : res) { if (uniqueResult != null) { if (uniqueResult.getPatrullas() != null) { uniqueResult.getPatrullas().getId(); } if (uniqueResult.getFlotas() != null) { uniqueResult.getFlotas().getId(); } } } } catch (Throwable e) { log.error("Error al calcular los ms cercanos", e); } log.info("Encontrados " + res.size() + " recursos"); return res.toArray(new Recurso[0]); }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Recurso getByNombre(String nombre) { try {/*from w w w . ja v a 2s.c o m*/ Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class).add(Restrictions.eq("nombre", nombre)); return (Recurso) criteria.uniqueResult(); } catch (Throwable t) { log.error(t, t); return null; } }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED) public Recurso getbyDispositivo(Integer disp) { Recurso uniqueResult = null;/*from w w w .j a v a2s . co m*/ try { Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class) .add(Restrictions.eq("dispositivo", disp)); uniqueResult = (Recurso) criteria.uniqueResult(); if (uniqueResult != null) { if (uniqueResult.getPatrullas() != null) { uniqueResult.getPatrullas().getId(); } if (uniqueResult.getFlotas() != null) { uniqueResult.getFlotas().getId(); } } } catch (Throwable t) { log.error(t, t); } return uniqueResult; }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public List<Recurso> getAll(Usuario u) { List<Recurso> res = new ArrayList<Recurso>(); try {/*w ww . j ava 2 s. co m*/ Session currentSession = getSession(); currentSession.clear(); final Calendar calenar = Calendar.getInstance(); calenar.add(Calendar.MINUTE, -LogicConstants.getInt("AVL_TIMEOUT", 30)); Date fecha = calenar.getTime(); String sql = "select this_.* from recursos this_ " + "inner join flotas flota2_ on this_.flota_x_flota=flota2_.x_flota " + "inner join ROLES_X_FLOTAS roles15_ on flota2_.x_flota=roles15_.X_FLOTA " + "inner join roles rol3_ on roles15_.X_ROL=rol3_.x_rol " + "inner join usuarios usuario4_ on rol3_.x_rol=usuario4_.fk_roles " + "inner join historico_gps historico1_ on this_.fk_historico_gps=historico1_.x_historico " + "where this_.habilitado=true " + "and historico1_.marca_temporal>=:DATE "; if (u != null && u.getId() != null) { sql += "and usuario4_.x_usuarios=:ID"; } Query criteria = currentSession.createSQLQuery(sql).addEntity(Recurso.class).setTimestamp("DATE", fecha) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (u != null && u.getId() != null) { criteria = criteria.setLong("ID", u.getId()); } log.trace("Cogemos los recursos visibles: " + criteria.toString() + " " + fecha); res = criteria.list(); if (log.isTraceEnabled()) { log.trace("Recursos que mostramos finalmente:"); for (Recurso s : res) { log.trace(s); } } for (Recurso uniqueResult : res) { if (uniqueResult != null) { if (uniqueResult.getEstadoEurocop() != null) { uniqueResult.getEstadoEurocop().getId(); } if (uniqueResult.getFlotas() != null) { uniqueResult.setFlotas( (Flota) currentSession.get(Flota.class, uniqueResult.getFlotas().getId())); currentSession.refresh(uniqueResult.getFlotas()); } if (uniqueResult.getPatrullas() != null) { uniqueResult.setPatrullas( (Patrulla) currentSession.get(Patrulla.class, uniqueResult.getPatrullas().getId())); uniqueResult.getPatrullas().getId(); } } } } catch (Throwable t) { log.error("Mostrando los recursos visibles", t); } return res; }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
/** * Devuelve todos los recursos que tienen posiciones en HistoricoGPS ms * antiguas que lmite./*from ww w . j av a 2s .c om*/ * * @param limite * @return */ @SuppressWarnings("unchecked") @Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public List<Recurso> getTodas(Calendar limite) { List<Recurso> res = new ArrayList<Recurso>(); try { Session currentSession = getSession(); currentSession.clear(); DetachedCriteria dc = DetachedCriteria.forClass(HistoricoGPS.class) .setProjection(Projections.property("recurso")) .add(Restrictions.le("marcaTemporal", limite.getTime())) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); final Criteria query = currentSession.createCriteria(Recurso.class) .add(Subqueries.propertyIn("identificador", dc)).addOrder(Order.asc("identificador")); if (log.isDebugEnabled()) log.debug(query); res = query.list(); // Para evitar LazyInicializationException accedemos a // todas las flotas de los recursos devueltos ya que en // los lugares en los que se usa esta funcin es necerasio // tambin la flota. for (Recurso uniqueResult : res) { if (uniqueResult != null) { if (uniqueResult.getFlotas() != null) { uniqueResult.getFlotas().getId(); } } } } catch (Throwable t) { log.error("Sacando los recursos para generar los gpx", t); } return res; }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED) public Recurso[] getAsigned(Incidencia i) { Recurso[] res = new Recurso[0]; if (i == null || i.getId() == null) { return res; }/*from ww w .ja v a2 s.c o m*/ log.debug("getAsigned(" + i + ")"); Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class).createCriteria("incidencias") .add(Restrictions.eq("id", i.getId())); criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]); return res; }
From source file:es.emergya.bbdd.dao.RolHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public Integer getTotal() { Integer res = new Integer(-1); Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Rol.class).setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); res = count.intValue();/*from w w w . j av a2 s . c om*/ return res; }
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<String> getAllString() { Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Rol.class) .setProjection(Projections.distinct(Projections.property("nombre"))).addOrder(Order.asc("nombre")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }
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> getAll() { Session currentSession = getSession(); currentSession.clear(); return currentSession.createCriteria(Rol.class).addOrder(Order.asc("nombre")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); }
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> getAll(String order, boolean asc) { List<Rol> res = new ArrayList<Rol>(0); Session currentSession = getSession(); currentSession.clear(); if (asc)//from www . ja va 2 s. com res = currentSession.createCriteria(Rol.class).addOrder(Order.asc(order)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); else res = currentSession.createCriteria(Rol.class).addOrder(Order.desc(order)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); return res; }