List of usage examples for org.hibernate Criteria setCacheRegion
public Criteria setCacheRegion(String cacheRegion);
From source file:br.gov.jfrj.siga.model.dao.ModeloDao.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> List<T> consultar(final T exemplo, final String[] excluir) { final Criteria crit = getSessao().createCriteria(exemplo.getClass()); final Example example = Example.create(exemplo); if (excluir != null) { for (final String exclude : excluir) { example.excludeProperty(exclude); }//from w w w . jav a 2s . co m } crit.add(example); if (getCacheRegion() != null) { crit.setCacheable(true); crit.setCacheRegion(getCacheRegion()); } return crit.list(); }
From source file:br.gov.jfrj.siga.model.dao.ModeloDao.java
License:Open Source License
@SuppressWarnings("unchecked") protected <T> List<T> findAndCacheByCriteria(String cacheRegion, Class<T> clazz, final Criterion... criterion) { final Criteria crit = getSessao().createCriteria(clazz); for (final Criterion c : criterion) { crit.add(c);/*from w w w .j a v a 2s .co m*/ } if (cacheRegion != null) { crit.setCacheable(true); crit.setCacheRegion(cacheRegion); } return crit.list(); }
From source file:com.jdon.persistence.hibernate.HibernateTemplate.java
License:Apache License
/** * Prepare the given Criteria object, applying cache settings and/or a * transaction timeout.//from w w w. ja v a2s . co m * * @param criteria * the Criteria object to prepare * @see #setCacheQueries * @see #setQueryCacheRegion * @see SessionProviderHolder#applyTransactionTimeout */ protected void prepareCriteria(Criteria criteria) { if (isCacheQueries()) { criteria.setCacheable(true); if (getQueryCacheRegion() != null) { criteria.setCacheRegion(getQueryCacheRegion()); } } if (getFetchSize() > 0) { criteria.setFetchSize(getFetchSize()); } if (getMaxResults() > 0) { criteria.setMaxResults(getMaxResults()); } }
From source file:org.broadleafcommerce.core.offer.dao.OfferDaoImpl.java
License:Apache License
@Override public List<Offer> readOffersByAutomaticDeliveryType() { //TODO change this to a JPA criteria Criteria criteria = ((HibernateEntityManager) em).getSession().createCriteria(OfferImpl.class); Date myDate = getCurrentDateAfterFactoringInDateResolution(); Calendar c = Calendar.getInstance(); c.setTime(myDate);/*from ww w . j a v a 2 s .c om*/ c.add(Calendar.DATE, +1); criteria.add(Restrictions.lt("startDate", c.getTime())); c = Calendar.getInstance(); c.setTime(myDate); c.add(Calendar.DATE, -1); criteria.add(Restrictions.or(Restrictions.isNull("endDate"), Restrictions.gt("endDate", c.getTime()))); criteria.add(Restrictions.or(Restrictions.eq("archiveStatus.archived", 'N'), Restrictions.isNull("archiveStatus.archived"))); // Automatically Added or (Automatically Added is null and deliveryType is Automatic) criteria.add(Restrictions.or(Restrictions.eq("automaticallyAdded", true), Restrictions .and(Restrictions.isNull("automaticallyAdded"), Restrictions.eq("deliveryType", "AUTOMATIC")))); criteria.setCacheable(true); criteria.setCacheRegion("query.Offer"); return criteria.list(); }
From source file:org.codehaus.grepo.query.hibernate.generator.CriteriaGeneratorBase.java
License:Apache License
protected void applyCachingSetting(HibernateQueryOptions queryOptions, HibernateQueryExecutionContext context, Criteria criteria) { if (HibernateGeneratorUtils.isCachingEnabled(queryOptions, context)) { criteria.setCacheable(true);//from ww w . j a v a2 s . c o m String cacheRegion = HibernateGeneratorUtils.getCacheRegion(queryOptions, context); if (cacheRegion != null) { criteria.setCacheRegion(cacheRegion); } } }
From source file:org.faster.orm.service.hibernate.HibernateDaoSupport.java
License:Open Source License
@SuppressWarnings("rawtypes") protected List fetchPage(final DetachedCriteria criteria, final int page, final int limit, QueryOption queryOption) {//from w w w . j a v a 2 s . c o m renderCriteria(criteria); Criteria executableCriteria = criteria.getExecutableCriteria(getSession()); if (queryOption != null) { executableCriteria.setCacheable(queryOption.isCacheEnabled()); if (cacheRegion != null) { executableCriteria.setCacheRegion(cacheRegion); } } if (page >= 1) { executableCriteria.setFirstResult((page - 1) * limit); } if (limit > 0) { executableCriteria.setMaxResults(limit); } return executableCriteria.list(); }
From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java
License:Apache License
protected void prepareCache(Criteria criteria) { if (isCache()) { criteria.setCacheable(true);/*from w ww.j a v a2 s. com*/ criteria.setCacheRegion(getCacheRegion()); } }
From source file:org.projectforge.core.BaseDao.java
License:Open Source License
@SuppressWarnings("unchecked") private void getHistoryEntries(final Session session, final BaseSearchFilter filter, final Set<Integer> idSet, final Class<?> clazz, final boolean searchStringInHistory) { if (log.isDebugEnabled() == true) { log.debug("Searching in " + clazz); }// ww w . j a va 2s .c o m // First get all history entries matching the filter and the given class. final String className = ClassUtils.getShortClassName(clazz); if (searchStringInHistory == true) { final StringBuffer buf = new StringBuffer(); buf.append("(+className:").append(className); if (filter.getStartTimeOfModification() != null || filter.getStopTimeOfModification() != null) { final DateFormat df = new SimpleDateFormat(DateFormats.LUCENE_TIMESTAMP_MINUTE); df.setTimeZone(DateHelper.UTC); buf.append(" +timestamp:["); if (filter.getStartTimeOfModification() != null) { buf.append(df.format(filter.getStartTimeOfModification())); } else { buf.append("000000000000"); } buf.append(" TO "); if (filter.getStopTimeOfModification() != null) { buf.append(df.format(filter.getStopTimeOfModification())); } else { buf.append("999999999999"); } buf.append("]"); } if (filter.getModifiedByUserId() != null) { buf.append(" +userName:").append(filter.getModifiedByUserId()); } buf.append(") AND ("); final String searchString = buf.toString() + modifySearchString(filter.getSearchString()) + ")"; try { final FullTextSession fullTextSession = Search.getFullTextSession(getSession()); final org.apache.lucene.search.Query query = createFullTextQuery(HISTORY_SEARCH_FIELDS, null, searchString); if (query == null) { // An error occured: return; } final FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, HistoryEntry.class); fullTextQuery.setCacheable(true); fullTextQuery.setCacheRegion("historyItemCache"); fullTextQuery.setProjection("entityId"); final List<Object[]> result = fullTextQuery.list(); if (result != null && result.size() > 0) { for (final Object[] oa : result) { idSet.add((Integer) oa[0]); } } } catch (final Exception ex) { final String errorMsg = "Lucene error message: " + ex.getMessage() + " (for " + this.getClass().getSimpleName() + ": " + searchString + ")."; filter.setErrorMessage(errorMsg); log.info(errorMsg); } } else { final Criteria criteria = session.createCriteria(HistoryEntry.class); setCacheRegion(criteria); criteria.add(Restrictions.eq("className", className)); if (filter.getStartTimeOfModification() != null && filter.getStopTimeOfModification() != null) { criteria.add(Restrictions.between("timestamp", filter.getStartTimeOfModification(), filter.getStopTimeOfModification())); } else if (filter.getStartTimeOfModification() != null) { criteria.add(Restrictions.ge("timestamp", filter.getStartTimeOfModification())); } else if (filter.getStopTimeOfModification() != null) { criteria.add(Restrictions.le("timestamp", filter.getStopTimeOfModification())); } if (filter.getModifiedByUserId() != null) { criteria.add(Restrictions.eq("userName", filter.getModifiedByUserId().toString())); } criteria.setCacheable(true); criteria.setCacheRegion("historyItemCache"); criteria.setProjection(Projections.property("entityId")); final List<Integer> idList = criteria.list(); if (idList != null && idList.size() > 0) { for (final Integer id : idList) { idSet.add(id); } } } }
From source file:org.projectforge.core.BaseDao.java
License:Open Source License
private void setCacheRegion(final Criteria criteria) { criteria.setCacheable(true);//from w w w.j ava 2 s. com if (useOwnCriteriaCacheRegion() == false) { return; } criteria.setCacheRegion(this.getClass().getName()); }
From source file:org.springframework.orm.hibernate3.HibernateTemplate.java
License:Apache License
/** * Prepare the given Criteria object, applying cache settings and/or * a transaction timeout./* w ww. j a v a 2s . c om*/ * @param criteria the Criteria object to prepare * @see #setCacheQueries * @see #setQueryCacheRegion * @see SessionFactoryUtils#applyTransactionTimeout */ protected void prepareCriteria(Criteria criteria) { if (isCacheQueries()) { criteria.setCacheable(true); if (getQueryCacheRegion() != null) { criteria.setCacheRegion(getQueryCacheRegion()); } } if (getFetchSize() > 0) { criteria.setFetchSize(getFetchSize()); } if (getMaxResults() > 0) { criteria.setMaxResults(getMaxResults()); } SessionFactoryUtils.applyTransactionTimeout(criteria, getSessionFactory()); }