List of usage examples for org.hibernate Query getCacheRegion
String getCacheRegion();
From source file:org.web4thejob.orm.DataReaderServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <E extends Entity> List<E> findByQuery(Query query) { Criteria criteria = toDetachedCriteria(query).getExecutableCriteria(sessionFactory.getCurrentSession()) .setCacheable(query.isCached()); //Issue #21/*from w w w.j av a 2 s. c om*/ criteria.setFlushMode(FlushMode.MANUAL); if (StringUtils.hasText(query.getCacheRegion())) { criteria.setCacheRegion(query.getCacheRegion()); } return criteria.list(); }
From source file:org.web4thejob.orm.DataReaderServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <E extends Entity> E findFirstByQuery(Query query) { Criteria criteria = toDetachedCriteria(query).getExecutableCriteria(sessionFactory.getCurrentSession()) .setMaxResults(1).setCacheable(query.isCached()); if (StringUtils.hasText(query.getCacheRegion())) { criteria.setCacheRegion(query.getCacheRegion()); }/*w ww .ja v a 2 s . c om*/ //Issue #21 criteria.setFlushMode(FlushMode.MANUAL); final List<E> list = criteria.list(); if (list.size() > 0) { return list.get(0); } return null; }
From source file:org.web4thejob.orm.DataReaderServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <E extends Entity> E findUniqueByQuery(Query query) { Criteria criteria = toDetachedCriteria(query).getExecutableCriteria(sessionFactory.getCurrentSession()) .setMaxResults(2).setCacheable(query.isCached()); if (StringUtils.hasText(query.getCacheRegion())) { criteria.setCacheRegion(query.getCacheRegion()); }/*from w ww . j a v a2 s . com*/ //Issue #21 criteria.setFlushMode(FlushMode.MANUAL); final List<E> list = criteria.list(); if (list.size() == 0) { return null; } else if (list.size() == 1) { return list.get(0); } else { throw new DataIntegrityViolationException("expecting unique result but got many"); } }