org.hibernate.Criteria.setCacheRegion()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中org.hibernate.Criteria.setCacheRegion()方法的一些代码示例,展示了Criteria.setCacheRegion()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.setCacheRegion()方法的具体详情如下:
包路径:org.hibernate.Criteria
类名称:Criteria
方法名:setCacheRegion

Criteria.setCacheRegion介绍

[英]Set the name of the cache region to use for query result caching.
[中]设置用于查询结果缓存的缓存区域的名称。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@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);
  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")));
  
  criteria.add(Restrictions.eq("automaticallyAdded", true));
  criteria.setCacheable(true);
  criteria.setCacheRegion("query.Offer");
  return criteria.list();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @param criteria the Criteria object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
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());
  }
  ResourceHolderSupport sessionHolder =
      (ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
  if (sessionHolder != null && sessionHolder.hasTimeout()) {
    criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  }
}

代码示例来源:origin: org.springframework/spring-orm

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @param criteria the Criteria object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
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());
  }
  ResourceHolderSupport sessionHolder =
      (ResourceHolderSupport) TransactionSynchronizationManager.getResource(obtainSessionFactory());
  if (sessionHolder != null && sessionHolder.hasTimeout()) {
    criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  }
}

代码示例来源:origin: TGAC/miso-lims

@Override
public Criteria setCacheRegion(String cacheRegion) {
 backingCriteria.setCacheRegion(cacheRegion);
 return this;
}

代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter

@Override
public Criteria setCacheRegion(final String cacheRegion) {
  criteria.setCacheRegion(cacheRegion);
  return this;
}

代码示例来源:origin: ezbz/projectx

@Override
public Criteria setCacheRegion(final String cacheRegion) {
 return criteria.setCacheRegion(cacheRegion);
}

代码示例来源:origin: stackoverflow.com

Criteria cri = session.createCriteria(tableName.class);
       cri.setCacheRegion("cacheReginName");

代码示例来源:origin: micromata/projectforge

private void setCacheRegion(final Criteria criteria)
{
 criteria.setCacheable(true);
 if (useOwnCriteriaCacheRegion() == false) {
  return;
 }
 criteria.setCacheRegion(this.getClass().getName());
}

代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework

protected void prepareCache(Criteria criteria) {
  if (isCache()) {
    criteria.setCacheable(true);
    criteria.setCacheRegion(getCacheRegion());
  }
}

代码示例来源:origin: riotfamily/riot

@SuppressWarnings("unchecked")
public static void removeEmptyEntries(String bundle) {
  List<MessageBundleEntry> entries = getSession().createCriteria(MessageBundleEntry.class)
    .setCacheable(true)
    .setCacheRegion("messages")
    .add(Restrictions.sizeLe("messages", 1))
    .add(Restrictions.naturalId()
      .set("bundle", bundle))
      .list();
  
  for (MessageBundleEntry entry : entries) {
    entry.delete();
  }
}

代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework

protected void prepareCache(Criteria criteria) {
  if (isCache()) {
    criteria.setCacheable(true);
    criteria.setCacheRegion(getCacheRegion());
  }
}

代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework

protected void prepareCache(Criteria criteria) {
  if (isCache()) {
    criteria.setCacheable(true);
    criteria.setCacheRegion(getCacheRegion());
  }
}

代码示例来源:origin: micromata/projectforge

criteria.setCacheRegion("historyItemCache");
criteria.setProjection(Projections.property("entityId"));
List<Object> idList = criteria.list();

代码示例来源:origin: apache/servicemix-bundles

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @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());
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Prepare the given Criteria object, applying cache settings and/or
 * a transaction timeout.
 * @param criteria the Criteria object to prepare
 * @see #setCacheQueries
 * @see #setQueryCacheRegion
 */
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());
  }
  SessionHolder sessionHolder =
      (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
  if (sessionHolder != null && sessionHolder.hasTimeout()) {
    criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
  }
}

相关文章