List of usage examples for org.hibernate Query setCacheRegion
Query<R> setCacheRegion(String cacheRegion);
From source file:org.springframework.orm.hibernate4.HibernateTemplateTests.java
License:Apache License
@Test public void testFindByNamedQueryWithCacheableAndCacheRegion() { Query query = mock(Query.class); List list = new ArrayList(); given(session.getNamedQuery("some query name")).willReturn(query); given(query.setCacheable(true)).willReturn(query); given(query.setCacheRegion("myCacheRegion")).willReturn(query); given(query.list()).willReturn(list); hibernateTemplate.setCacheQueries(true); hibernateTemplate.setQueryCacheRegion("myCacheRegion"); List result = hibernateTemplate.findByNamedQuery("some query name"); assertTrue("Correct list", result == list); verify(query).setCacheable(true);/*from www. ja v a 2s . c o m*/ verify(query).setCacheRegion("myCacheRegion"); }
From source file:org.workin.persistence.hibernate.v4.dao.Hibernate4DaoSupport.java
License:Apache License
/** * @description ??Query//from w w w .ja v a 2 s . c o m * @author <a href="mailto:code727@gmail.com">?</a> * @param query */ protected void prepareQuery(Query query) { if (this.cacheConfiguration != null) { if (this.cacheConfiguration.isCacheQueries()) { query.setCacheable(true); if (StringUtils.isNotBlank(this.cacheConfiguration.getQueryCacheRegion())) { query.setCacheRegion(this.cacheConfiguration.getQueryCacheRegion()); } } if (this.cacheConfiguration.getFetchSize() > 0) query.setFetchSize(this.cacheConfiguration.getFetchSize()); if (this.cacheConfiguration.getMaxResults() > 0) query.setMaxResults(this.cacheConfiguration.getMaxResults()); } }