List of usage examples for org.hibernate Session clear
void clear();
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public Integer getTotal() { try {//w ww . ja v a2s . c om org.hibernate.Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Patrulla.class).setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); return count.intValue(); } catch (Throwable t) { log.error("Error en getTotal()", t); return -1; } }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Patrulla> getByFilter(Patrulla p) { List<Patrulla> res = new ArrayList<Patrulla>(0); try {/*from w ww. java2s. c om*/ Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Patrulla.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()))); res = criteria.addOrder(Order.asc("nombre")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } catch (Throwable t) { log.error(t, t); } return res; }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Patrulla> getAll() { List<Patrulla> res = new ArrayList<Patrulla>(0); try {// www . j av a2 s . co m Session currentSession = getSession(); currentSession.clear(); res = currentSession.createCriteria(Patrulla.class).addOrder(Order.asc("nombre")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } catch (Throwable e) { log.error(e, e); } return res; }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Patrulla> getAllTests() { List<Patrulla> res = new ArrayList<Patrulla>(0); try {// w w w . j av a 2 s . c om Session currentSession = getSession(); currentSession.clear(); res = currentSession.createCriteria(Patrulla.class).addOrder(Order.asc("nombre")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); for (Patrulla p : res) for (Recurso r : p.getRecursos()) r.getId(); } catch (Throwable e) { log.error(e, e); } return res; }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public Patrulla find(String p) { Patrulla res = null;//w w w . j a v a2s .c o m try { Session currentSession = getSession(); currentSession.clear(); res = (Patrulla) currentSession.createCriteria(Patrulla.class).add(Restrictions.ilike("nombre", p)) .setMaxResults(1).uniqueResult(); } catch (Throwable t) { log.error(t, t); } return res; }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public boolean saveOrUpdate(Patrulla p) { boolean res = false; if (p == null) return res; log.debug("Saving " + p); try {/*w ww . j a v a 2 s .c om*/ Session currentSession = getSession(); currentSession.clear(); Patrulla entity = null; if (p.getId() != null && this.get(p.getId()) != null) entity = (Patrulla) currentSession.merge(p); else entity = p; if (p.getRecursos() != null) for (Recurso r : p.getRecursos()) { if (r.getId() != null) { r = (Recurso) currentSession.get(Recurso.class, r.getId()); r.setPatrullas(entity); currentSession.saveOrUpdate(r); } } currentSession.saveOrUpdate(entity); log.debug(p + " saved"); return true; } catch (Throwable t) { log.error(t, t); return false; } }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public void removeRecursos(Patrulla p) { if (p == null || p.getId() == null) return;//from w w w.j a v a 2 s . c om try { Session currentSession = getSession(); currentSession.clear(); p = this.get(p.getId()); if (p != null && p.getRecursos() != null) { for (Recurso r : p.getRecursos()) { try { r.setPatrullas(null); currentSession.saveOrUpdate(r); } catch (Throwable t) { log.error("No pude eliminar el recurso de la patrulla", t); } } } } catch (Throwable t) { log.error(t, t); } }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<String> getAllNames() { List<String> icons = new ArrayList<String>(0); try {//from w ww. j a v a 2s .co m Session currentSession = getSession(); currentSession.clear(); icons = (List<String>) currentSession.createCriteria(Patrulla.class) .setProjection(Projections.property("nombre")).addOrder(Order.asc("nombre")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); } catch (Throwable t) { log.error(t, t); } return icons; }
From source file:es.emergya.bbdd.dao.PatrullaHome.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 va 2 s . c o m Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Patrulla.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.PatrullaHome.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = Throwable.class) public Patrulla find(Long id) { try {/*from www. j a va 2 s .co m*/ Session currentSession = getSession(); currentSession.clear(); return (Patrulla) currentSession.createCriteria(Patrulla.class).add(Restrictions.eq("id", id)) .uniqueResult(); } catch (Throwable t) { log.error(t, t); } return null; }