Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
03/26/08 23:04:03 (10 months ago)
Author:
bmckown
Message:

Fixed bug from ticket #657 and added JUnit test.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/src/api/org/openmrs/api/db/hibernate/HibernatePersonDAO.java

    r3685 r3732  
    3636import org.openmrs.Relationship; 
    3737import org.openmrs.RelationshipType; 
    38 import org.openmrs.User; 
    3938import org.openmrs.api.context.Context; 
    4039import org.openmrs.api.db.DAOException; 
     
    298297        @SuppressWarnings("unchecked") 
    299298        public List<Relationship> getRelationships(Person person, boolean showVoided) throws DAOException { 
    300                 Query query = null; 
    301                 List<Relationship> relationships = new Vector<Relationship>(); 
    302                  
    303                 if (person == null) 
    304                         return relationships; 
    305                  
    306                 String voided = showVoided ? "" : " and voided = 0 "; 
    307                  
    308                 query = sessionFactory.getCurrentSession().createQuery( 
    309                         "from Relationship r where r.personA = :p1 or r.personB = :p2 " + voided + " order by r.relationshipId asc " 
    310                 ) 
    311                 .setParameter("p1", person) 
    312                 .setParameter("p2", person); 
    313                  
    314                 if (query != null) 
    315                         relationships = query.list();  
    316                          
    317                 return relationships; 
     299 
     300                Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Relationship.class, "r") 
     301                .add(Expression.or(Expression.eq("personA", person), Expression.eq("personB", person))); 
     302                 
     303                if (!showVoided) { 
     304                        criteria.add(Expression.eq("voided", showVoided)); 
     305                } 
     306                 
     307                return criteria.list(); 
    318308        } 
    319309