@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() ); } }
/** * 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; }
@Override public Criteria setCacheMode(CacheMode cacheMode) { backingCriteria.setCacheMode(cacheMode); return this; }
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; }
@Override public Criteria setCacheMode(final CacheMode cacheMode) { return criteria.setCacheMode(cacheMode); }
/** * Sets the specified criteria cacheable with NORMAL cache mode. * * @param c */ protected void setCacheable(Criteria c) { c.setCacheable(true); c.setCacheMode(CacheMode.NORMAL); }
/** * @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; }
/** * 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); }
.setLockMode( LockMode.NONE ) .setFlushMode( FlushMode.MANUAL ) .setCacheMode( cacheMode ) .setFetchSize( entityFetchSize ) .scroll( ScrollMode.FORWARD_ONLY );
@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(); }