List of usage examples for org.hibernate Session clear
void clear();
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Integer getTotal() { try {//from w w w . java 2 s . c om Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class).setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); return count.intValue(); } catch (Throwable t) { log.error(t, t); return -1; } }
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[] getNotAsigned(Patrulla p) { Recurso[] res = new Recurso[0]; try {/* ww w. j a v a 2s . com*/ if (p == null || p.getId() == null) { return getByFilter(filter).toArray(new Recurso[0]); } log.debug("getNotAsigned(" + p.getId() + ")"); Session currentSession = getSession(); currentSession.clear(); Criterion rhs = Restrictions.isNull("patrullas"); Criterion lhs = Restrictions.ne("patrullas", currentSession.load(Patrulla.class, p.getId())); Criteria criteria = currentSession.createCriteria(Recurso.class) .add(Restrictions.eq("habilitado", true)).add(Restrictions.or(lhs, rhs)); criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]); for (Recurso r : res) try { r.getPatrullas().getId(); } catch (Throwable t) { } } catch (Throwable t) { log.error(t, 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(Patrulla p) { Recurso[] res = new Recurso[0]; if (p == null || p.getId() == null) { return res; }/*from w ww.j a va2s . c om*/ try { log.debug("getAsigned(" + p.getId() + ")"); Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class).createCriteria("patrullas") .add(Restrictions.eq("id", p.getId())); criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]); for (Recurso r : res) try { r.getPatrullas().getId(); } catch (Throwable t) { } } catch (Throwable t) { log.error(t, 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.REQUIRES_NEW) public Recurso[] getNotAsigned(Flota p) { Recurso[] res = new Recurso[0]; if (p == null || p.getId() == null) { return getByFilter(new Recurso()).toArray(new Recurso[0]); }/*w w w .j a v a 2 s.c o m*/ try { log.debug("getNotAsigned(" + p.getId() + ")"); Session currentSession = getSession(); currentSession.clear(); Criterion rhs = Restrictions.isNull("flotas"); Criterion lhs = Restrictions.ne("flotas", currentSession.load(Patrulla.class, p.getId())); Criteria criteria = currentSession.createCriteria(Recurso.class).add(Restrictions.or(lhs, rhs)); criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]); for (Recurso r : res) try { r.getFlotas().getId(); } catch (Throwable t) { } } catch (Throwable t) { log.error(t, 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.REQUIRES_NEW) public Recurso[] getAsigned(Flota p) { Recurso[] res = new Recurso[0]; if (p == null || p.getId() == null) { return res; }//from ww w .java2 s.c o m try { log.debug("getAsigned(" + p.getId() + ")"); Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class).createCriteria("flotas") .add(Restrictions.eq("id", p.getId())); criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]); for (Recurso r : res) try { r.getFlotas().getId(); } catch (Throwable t) { } } catch (Throwable t) { log.error(t, 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.REQUIRES_NEW) public List<Recurso> getByFilter(Recurso p) { List<Recurso> res = new ArrayList<Recurso>(0); try {//from www. j av a 2s .c o m Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class); if (p.getInfoAdicional() != null) { criteria = criteria.add( Restrictions.ilike("infoAdicional", LogicConstants.getGenericString(p.getInfoAdicional()))); } if (p.getNombre() != null) { criteria = criteria .add(Restrictions.ilike("nombre", LogicConstants.getGenericString(p.getNombre()))); } if (p.getIdentificador() != null) { criteria = criteria.add( Restrictions.ilike("identificador", LogicConstants.getGenericString(p.getIdentificador()))); } if (p.getHabilitado() != null) { criteria = criteria.add(Restrictions.eq("habilitado", p.getHabilitado())); } if (p.idpattern != null && p.idpattern.length() > 0) { criteria.add(Restrictions.sqlRestriction("lpad({alias}.dispositivo :: varchar, " + LONGITUD_ISSI + ", '0') ilike '" + LogicConstants.getGenericString(p.idpattern) + "'")); } if (p.getEstadoEurocop() != null) { criteria = criteria.add(Restrictions.ilike("estadoEurocop", LogicConstants.getGenericString(p.getEstadoEurocop().getIdentificador()))); } if (p.getFlotas() != null) { criteria = criteria.add(Restrictions.eq("flotas", p.getFlotas())); } if (p.getPatrullas() != null) { criteria = criteria.add(Restrictions.eq("patrullas", p.getPatrullas())); } if (p.getTipo() != null) { criteria = criteria .add(Restrictions.ilike("tipo", LogicConstants.getGenericString(p.getTipoReal()))); } log.trace(criteria); res = criteria.addOrder(Order.asc("nombre")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); for (Recurso uniqueResult : res) { 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 res; }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public boolean saveOrUpdate(Recurso p) { boolean res = false; if (p == null) { return res; }//from ww w.ja v a 2 s .c o m try { Session currentSession = getSession(); currentSession.clear(); Recurso entity = null; if (p.getId() == null || (p.getId() != null && this.get(p.getId()) == null)) { entity = p; } else { entity = (Recurso) currentSession.merge(p); if (p.getEstadoEurocop() != null && p.getEstadoEurocop().getId() != null) { entity.setEstadoEurocop( (EstadoRecurso) currentSession.get(EstadoRecurso.class, p.getEstadoEurocop().getId())); } } if (entity == null) { entity = p; } if (entity != null) { entity.setInfoAdicional(p.getInfoAdicional()); entity.setNombre(p.getNombre()); } Patrulla patrulla = null; if (p.getPatrullas() != null) { if (p.getPatrullas().getId() != null) { patrulla = (Patrulla) currentSession.load(Patrulla.class, p.getPatrullas().getId()); } else { patrulla = p.getPatrullas(); } } entity.setPatrullas(patrulla); if (entity.getEstadoEurocop() == null) { entity.setEstadoEurocop((EstadoRecurso) currentSession.get(EstadoRecurso.class, 1l)); } entity.setIdentificador(entity.getNombre()); currentSession.saveOrUpdate(entity); } catch (Throwable t) { log.error(t, t); } return true; }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = false, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public boolean delete(Recurso r) { if (r == null || r.getId() == null) { return false; }//from w w w . ja va2 s. c o m try { final Session currentSession = getSession(); currentSession.clear(); r = this.get(r.getId()); if (r == null) { return true; } this.remove(r.getId()); } catch (Throwable t) { log.error(t, t); return false; } return true; }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Calendar lastUpdated() { Calendar res = Calendar.getInstance(); try {/*from ww w. ja va2 s. c om*/ Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.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.RecursoHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW) public Recurso getByIdentificador(String origen) { Session currentSession = getSession(); try {//www. j av a 2 s . c om currentSession.clear(); Criteria criteria = currentSession.createCriteria(Recurso.class) .add(Restrictions.eq("identificador", origen)); final Recurso uniqueResult = (Recurso) criteria.uniqueResult(); if (uniqueResult != null) { if (uniqueResult.getPatrullas() != null) { uniqueResult.getPatrullas().getId(); } if (uniqueResult.getFlotas() != null) { uniqueResult.getFlotas().getId(); } if (uniqueResult.getEstadoEurocop() != null) { uniqueResult.getEstadoEurocop().getId(); } if (uniqueResult.getIncidencias() != null) { uniqueResult.getIncidencias().getId(); } } return uniqueResult; } catch (Throwable t) { log.error(t, t); return null; } }