protected void setUpCacheOnCriteria(Criteria criteria, SearchTemplate searchTemplate) { if (searchTemplate.isCacheable()) { criteria.setCacheable(true); if (searchTemplate.hasCacheRegion()) { criteria.setCacheRegion(searchTemplate.getCacheRegion()); } else { criteria.setCacheRegion(getCacheRegion()); } } }
/** * prepare query based on criteria * * @param session hib session * @return the query */ private Criteria attachCriteriaInfo(Session session) { Criteria query = null; if (StringUtils.isBlank(this.entityName)) { if (StringUtils.isBlank(this.alias)) { query = session.createCriteria(this.persistentClass); } else { query = session.createCriteria(this.persistentClass, alias); } } else { query = session.createCriteria(this.entityName); } // add criterions if (this.criterions != null) { query.add(this.criterions); } boolean secondLevelCaching = HibUtils.secondLevelCaching( ByCriteriaStatic.this.cacheable, ByCriteriaStatic.this.queryOptions); query.setCacheable(secondLevelCaching); if (secondLevelCaching) { String secondLevelCacheRegion = HibUtils.secondLevelCacheRegion( ByCriteriaStatic.this.cacheRegion, ByCriteriaStatic.this.queryOptions); if (!StringUtils.isBlank(secondLevelCacheRegion)) { query.setCacheRegion(secondLevelCacheRegion); } } QuerySort querySort = this.queryOptions == null ? null : this.queryOptions.getQuerySort(); if (querySort != null) { List<QuerySortField> sorts = querySort.getQuerySortFields(); for (QuerySortField theSort : GrouperUtil.nonNull(sorts)) { Order order = theSort.isAscending() ? Order.asc(theSort.getColumn()) : Order.desc(theSort.getColumn()); query.addOrder(order); } } QueryPaging queryPaging = this.queryOptions == null ? null : this.queryOptions.getQueryPaging(); if (queryPaging != null) { // GRP-1024: sql server problems with paging page number when not initted if (queryPaging.getFirstIndexOnPage() < 0) { query.setFirstResult(0); } else { query.setFirstResult(queryPaging.getFirstIndexOnPage()); } query.setMaxResults(queryPaging.getPageSize()); } return query; }