Changeset 4785 for openmrs/branches/complex-obs/src/api/org/openmrs/api/db/hibernate/HibernateCohortDAO.java
- Timestamp:
- 07/02/08 19:40:36 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/complex-obs/src/api/org/openmrs/api/db/hibernate/HibernateCohortDAO.java
r4417 r4785 18 18 import org.apache.commons.logging.Log; 19 19 import org.apache.commons.logging.LogFactory; 20 import org.hibernate.Criteria; 20 21 import org.hibernate.Query; 21 22 import org.hibernate.SessionFactory; 23 import org.hibernate.criterion.Order; 24 import org.hibernate.criterion.Restrictions; 22 25 import org.openmrs.Cohort; 23 26 import org.openmrs.api.db.CohortDAO; … … 28 31 * 29 32 * @see CohortDAO 33 * @see org.openmrs.api.context.Context 34 * @see org.openmrs.api.CohortService 30 35 */ 31 36 public class HibernateCohortDAO implements CohortDAO { … … 35 40 private SessionFactory sessionFactory; 36 41 37 public HibernateCohortDAO() { } 38 42 /** 43 * Auto generated method comment 44 * 45 * @param sessionFactory 46 */ 39 47 public void setSessionFactory(SessionFactory sessionFactory) { 40 48 this.sessionFactory = sessionFactory; 41 49 } 42 50 51 /** 52 * @see org.openmrs.api.db.CohortDAO#getCohort(java.lang.Integer) 53 */ 43 54 public Cohort getCohort(Integer id) throws DAOException { 44 55 return (Cohort) sessionFactory.getCurrentSession().get(Cohort.class, id); 45 56 } 46 57 47 public List<Cohort> getCohortsContainingPatientId(Integer patientId) throws DAOException { 58 /** 59 * @see org.openmrs.api.db.CohortDAO#getCohortsContainingPatientId(java.lang.Integer) 60 */ 61 @SuppressWarnings("unchecked") 62 public List<Cohort> getCohortsContainingPatientId(Integer patientId) throws DAOException { 48 63 Query query = sessionFactory.getCurrentSession().createQuery("from Cohort c where :patientId in elements(c.memberIds) order by name"); 49 64 query.setInteger("patientId", patientId); … … 70 85 * @see org.openmrs.api.db.CohortDAO#getAllCohorts(boolean) 71 86 */ 87 @SuppressWarnings("unchecked") 72 88 public List<Cohort> getAllCohorts(boolean includeVoided) throws DAOException { 73 String hql = "from Cohort order by name"; 89 Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Cohort.class); 90 91 criteria.addOrder(Order.asc("name")); 92 74 93 if (!includeVoided) 75 hql += " where voided = false"; 76 return (List<Cohort>) sessionFactory.getCurrentSession().createQuery(hql).list(); 94 criteria.add(Restrictions.eq("voided", false)); 95 96 return (List<Cohort>) criteria.list(); 77 97 } 78 98 … … 81 101 */ 82 102 public Cohort getCohort(String name) { 83 return (Cohort) sessionFactory.getCurrentSession().createQuery("from Cohort where name = :name").setString("name", name).uniqueResult(); 103 Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Cohort.class); 104 105 criteria.add(Restrictions.eq("name", name)); 106 107 return (Cohort) criteria.uniqueResult(); 84 108 } 85 109