List of usage examples for org.hibernate Criteria setCacheMode
public Criteria setCacheMode(CacheMode cacheMode);
From source file:org.openmrs.module.reportingcompatibility.service.db.HibernateReportingCompatibilityDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public Map<Integer, List<DrugOrder>> getDrugOrders(Cohort patients, List<Concept> drugConcepts) throws DAOException { Map<Integer, List<DrugOrder>> ret = new HashMap<Integer, List<DrugOrder>>(); if (patients != null && patients.size() == 0) { return ret; }/*from ww w.j a v a 2s . c o m*/ // First get Map of patientId to orderId for efficiency Map<Integer, Integer> orderIdToPatient = new HashMap<Integer, Integer>(); String sql = "select o.order_id, o.patient_id from orders o, drug_order d where o.order_id = d.order_id"; Query q = sessionFactory.getCurrentSession().createSQLQuery(sql); q.setCacheMode(CacheMode.IGNORE); List<Object[]> l = q.list(); for (Object[] row : l) { orderIdToPatient.put((Integer) row[0], (Integer) row[1]); } // Next get all DrugOrders from the DB Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugOrder.class); criteria.setCacheMode(CacheMode.IGNORE); if (drugConcepts != null) { criteria.add(Restrictions.in("concept", drugConcepts)); } criteria.add(Restrictions.eq("voided", false)); criteria.addOrder(org.hibernate.criterion.Order.asc("startDate")); log.debug("criteria: " + criteria); List<DrugOrder> temp = criteria.list(); // Finally, construct return list based on input Cohort for (DrugOrder regimen : temp) { Integer orderId = regimen.getOrderId(); Integer patientId = orderIdToPatient.get(orderId); if (patients == null || patients.contains(patientId)) { List<DrugOrder> list = ret.get(patientId); if (list == null) { list = new ArrayList<DrugOrder>(); ret.put(patientId, list); } list.add(regimen); } } return ret; }
From source file:org.openmrs.module.reportingcompatibility.service.db.HibernateReportingCompatibilityDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public Map<Integer, List<Relationship>> getRelationships(Cohort patients, RelationshipType relType) { Map<Integer, List<Relationship>> ret = new HashMap<Integer, List<Relationship>>(); Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Relationship.class); criteria.setCacheMode(CacheMode.IGNORE); if (relType != null) criteria.add(Restrictions.eq("relationshipType", relType)); // this "where clause" is only useful if patients were passed in if (patients != null) criteria.createCriteria("personB").add(Restrictions.in("personId", patients.getMemberIds())); criteria.add(Restrictions.eq("voided", false)); log.debug("criteria: " + criteria); List<Relationship> temp = criteria.list(); for (Relationship rel : temp) { Integer ptId = rel.getPersonB().getPersonId(); List<Relationship> rels = ret.get(ptId); if (rels == null) { rels = new ArrayList<Relationship>(); ret.put(ptId, rels);//from w ww .ja va 2s .c om } rels.add(rel); } return ret; }
From source file:org.openmrs.module.reportingcompatibility.service.db.HibernateReportingCompatibilityDAO.java
License:Open Source License
/** * @param patients//from w ww.ja v a 2 s.co m * @param types List<PatientIdentifierTypes> of types to get * @return Map of {@link PatientIdentifier}s */ @SuppressWarnings("unchecked") public Map<Integer, String> getPatientIdentifierByType(Cohort patients, List<PatientIdentifierType> types) { Map<Integer, String> patientIdentifiers = new HashMap<Integer, String>(); // default query Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PatientIdentifier.class); // only get the "identifier" and "patientId" columns ProjectionList projections = Projections.projectionList(); projections.add(Projections.property("identifier")); projections.add(Projections.property("patient.personId")); criteria.setProjection(projections); criteria.setCacheMode(CacheMode.IGNORE); // Add patient restriction if necessary if (patients != null) criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); // all identifiers must be non-voided criteria.add(Restrictions.eq("voided", false)); // Add identifier type filter if (types != null && types.size() > 0) criteria.add(Restrictions.in("identifierType", types)); // Order by ID criteria.addOrder(org.hibernate.criterion.Order.desc("patient.personId")); List<Object[]> rows = criteria.list(); // set up the return map for (Object[] row : rows) { String identifier = (String) row[0]; Integer patientId = (Integer) row[1]; if (!patientIdentifiers.containsKey(patientId)) patientIdentifiers.put(patientId, identifier); } return patientIdentifiers; }
From source file:org.openspaces.persistency.hibernate.iterator.DefaultCriteriaByExampleDataIterator.java
License:Open Source License
protected Iterator createIterator() { session = sessionFactory.openSession(); transaction = session.beginTransaction(); Example example = Example.create(template); Criteria criteria = session.createCriteria(template.getClass()).add(example); criteria.setCacheMode(CacheMode.IGNORE); criteria.setCacheable(false);//w w w.j a va 2 s. c o m criteria.setFlushMode(FlushMode.NEVER); return criteria.list().iterator(); }
From source file:org.openspaces.persistency.hibernate.iterator.DefaultListQueryDataIterator.java
License:Open Source License
protected Iterator createIterator() { session = sessionFactory.openSession(); transaction = session.beginTransaction(); if (entityName != null) { Criteria criteria = session.createCriteria(entityName); criteria.setCacheMode(CacheMode.IGNORE); criteria.setCacheable(false);//from w ww . j av a2s. co m criteria.setFlushMode(FlushMode.NEVER); if (from >= 0) { criteria.setFirstResult(from); criteria.setMaxResults(size); } return criteria.list().iterator(); } else if (sqlQuery != null) { Query query = HibernateIteratorUtils.createQueryFromSQLQuery(sqlQuery, session); if (from >= 0) { query.setFirstResult(from); query.setMaxResults(size); } return query.list().iterator(); } else if (dataSourceSQLQuery != null) { Query query = HibernateIteratorUtils.createQueryFromDataSourceSQLQuery(dataSourceSQLQuery, session); if (from >= 0) { query.setFirstResult(from); query.setMaxResults(size); } return query.list().iterator(); } else { throw new IllegalStateException("Either SQLQuery or entity must be provided"); } }
From source file:org.osiam.storage.dao.GetInternalIdSkeleton.java
License:Open Source License
protected <T> SCIMSearchResult<T> search(Class<T> clazz, String filter, int count, int startIndex, String sortBy, String sortOrder) { Session session = (Session) em.getDelegate(); Criteria criteria = session.createCriteria(clazz); criteria.setReadOnly(true);/* www . ja v a2 s . c o m*/ criteria.setCacheMode(CacheMode.GET); criteria.setCacheable(true); if (filter != null && !filter.isEmpty()) { criteria = criteria.add(filterParser.parse(filter).buildCriterion()); } createAliasesForCriteria(criteria); criteria.setMaxResults(count); long totalResult = getTotalResults(criteria); setSortOrder(sortBy, sortOrder, criteria); criteria.setFirstResult(startIndex); Criteria criteria1 = criteria.setProjection(null).setResultTransformer(Criteria.ROOT_ENTITY); List list = criteria1.list(); return new SCIMSearchResult(list, totalResult); }
From source file:org.yamj.core.database.dao.StagingDao.java
License:Open Source License
public Long getNextStageFileId(FileType fileType, StatusType... statusTypes) { Criteria criteria = currentSession().createCriteria(StageFile.class); criteria.add(Restrictions.eq("fileType", fileType)); criteria.add(Restrictions.in("status", statusTypes)); criteria.setProjection(Projections.min("id")); criteria.setCacheable(true);//from ww w. j av a2 s . c o m criteria.setCacheMode(CacheMode.NORMAL); return (Long) criteria.uniqueResult(); }
From source file:org.yamj.core.database.dao.StagingDao.java
License:Open Source License
public List<StageDirectory> getRootDirectories() { Criteria criteria = currentSession().createCriteria(StageDirectory.class); criteria.add(Restrictions.isNull("parentDirectory")); criteria.setCacheable(true);//from w w w . j a va2s . c om criteria.setCacheMode(CacheMode.NORMAL); return criteria.list(); }
From source file:org.yamj.core.database.dao.StagingDao.java
License:Open Source License
public List<StageDirectory> getChildDirectories(StageDirectory stageDirectory) { if (stageDirectory == null) { return Collections.emptyList(); }/*from w ww . j ava 2s . co m*/ Criteria criteria = currentSession().createCriteria(StageDirectory.class); criteria.add(Restrictions.eq("parentDirectory", stageDirectory)); criteria.setCacheable(true); criteria.setCacheMode(CacheMode.NORMAL); return criteria.list(); }