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

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

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

Criteria.setCacheMode介绍

[英]Override the cache mode for this particular query.
[中]覆盖此特定查询的缓存模式。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Override
  protected Object getResults(Session s, boolean isSingleResult) throws Exception {
    Criteria criteria = getCriteria( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() );
    return ( isSingleResult ? criteria.uniqueResult() : criteria.list() );
  }
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * Create the criteria for fetching all encounters based on cohort
 *
 * @param patients
 * @return a map of patient with their encounters
 */
private Criteria createEncounterCriteria(Cohort patients) {
  Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class);
  criteria.setCacheMode(org.hibernate.CacheMode.IGNORE);
  
  // only include this where clause if patients were passed in
  if (patients != null) {
    ArrayList<Integer> patientIds = new ArrayList<>();
    patients.getMemberships().forEach(m -> patientIds.add(m.getPatientId()));
    criteria.add(Restrictions.in("patient.personId", patientIds));
  }
  
  criteria.add(Restrictions.eq("voided", false));
  
  criteria.addOrder(Order.desc("patient.personId"));
  criteria.addOrder(Order.desc("encounterDatetime"));
  return criteria;
}

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

@Override
public Criteria setCacheMode(CacheMode cacheMode) {
 backingCriteria.setCacheMode(cacheMode);
 return this;
}

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

public CriteriaReportSource(Criteria c) {
  this.c = c;
  this.sr = c.setCacheMode(CacheMode.IGNORE)
        .scroll(ScrollMode.FORWARD_ONLY);
}

public boolean next() {
  if (sr.next()) {
    currentObject = sr.get(0);
    return true;
  }
  return false;
}

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

@Override
public Criteria setCacheMode(final CacheMode cacheMode) {
 return criteria.setCacheMode(cacheMode);
}

代码示例来源:origin: com.github.mrstampy/hit

/**
 * Sets the specified criteria cacheable with NORMAL cache mode.
 * 
 * @param c
 */
protected void setCacheable(Criteria c) {
 c.setCacheable(true);
 c.setCacheMode(CacheMode.NORMAL);
}

代码示例来源:origin: openmrs/openmrs-module-webservices.rest

/**
 * @see org.openmrs.module.webservices.rest.web.api.RestHelperService#getPatients(Collection)
 */
@Override
@SuppressWarnings("unchecked")
public List<Patient> getPatients(Collection<Integer> patientIds) {
  List<Patient> ret = new ArrayList<Patient>();
  
  if (!patientIds.isEmpty()) {
    Criteria criteria = getSession().createCriteria(Patient.class);
    criteria.setCacheMode(CacheMode.IGNORE);
    criteria.add(Restrictions.in("patientId", patientIds));
    criteria.add(Restrictions.eq("voided", false));
    List<Patient> temp = criteria.list();
    for (Patient p : temp) {
      ret.add(p);
    }
  }
  
  return ret;
}

代码示例来源:origin: at.chrl/chrl-orm

/**
 * crates a Stream with given {@link Criteria} crit
 * 
 * @param crit
 *            - given Criteria
 * @return new {@link Stream} with given ResultSet
 */
public <T> Stream<T> stream(Criteria crit) {
  if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus()))
    session.beginTransaction();
  if (loggingEnabled)
    logQuery(false);
  
  return StreamSupport.<T> stream(Spliterators.spliteratorUnknownSize(
      new QueryIterator<T>(crit.setCacheMode(CacheMode.IGNORE)
          .setFlushMode(FlushMode.MANUAL), this, false),
      Spliterator.ORDERED | Spliterator.DISTINCT), false);
}

代码示例来源:origin: hibernate/hibernate-search

.setLockMode( LockMode.NONE )
.setFlushMode( FlushMode.MANUAL )
.setCacheMode( cacheMode )
.setFetchSize( entityFetchSize )
.scroll( ScrollMode.FORWARD_ONLY );

代码示例来源:origin: sk.seges.corpis/corpis-dao-impl

@SuppressWarnings("unchecked")
private List<T> doFindByCriteria(DetachedCriteria criteria, Page page, Set<String> existingAliases,
    boolean addFilterables, boolean cacheable) {
  Criteria executable = criteria.getExecutableCriteria((Session) entityManager.getDelegate());
  if (existingAliases != null) {
    if (addFilterables) {
      enrichCriteriaWithFilterables(page, executable, existingAliases);
    }
    // projectables are needed only forexecutable final select, not for
    // count
    enrichCriteriaWithProjectables(page, executable, existingAliases);
  }
  enrichCriteriaWithSortables(page, executable, existingAliases);
  executable.setFirstResult(page.getStartIndex());
  if (!retrieveAllResults(page)) {
    // Restrict the selection only when page size has meaningful value.
    executable.setMaxResults(page.getPageSize());
  }
  executable.setCacheable(cacheable);
  if (cacheable) {
    executable.setCacheMode(CacheMode.NORMAL);
  }
  List<T> list = setSpecialSortCriteria(executable);
  if (list != null){
    return list;
  }
  return executable.list();
}

相关文章