Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
06/02/08 21:18:46 (7 months ago)
Author:
bmckown
Message:

complex-obs branch: Web layer can now add/edit/delete ConceptComplex. Changed API ConceptComplex to more closely resemble ConceptNumeric. Removed last traces of the obsolete ConceptComplexHandler (we use ComplexObsHandler).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/src/api/org/openmrs/api/db/hibernate/HibernateConceptDAO.java

    r4417 r4517  
    7373                this.sessionFactory = sessionFactory; 
    7474        } 
    75          
    76         public ConceptComplex saveConcept(ConceptComplex concept) throws DAOException { 
    77                 if (concept.getConceptId() == null || concept.getConceptId() < 1) 
    78                         concept.setConceptId(this.getNextAvailableId()); 
    79                 sessionFactory.getCurrentSession().saveOrUpdate(concept); 
    80                 return concept; 
    81         } 
    82          
     75                 
     76        /** 
     77         * @see org.openmrs.api.db.ConceptDAO#getConceptComplex(java.lang.Integer) 
     78         */ 
    8379        public ConceptComplex getConceptComplex(Integer conceptId) { 
    84                 return (ConceptComplex)sessionFactory.getCurrentSession().get(ConceptComplex.class, conceptId); 
     80                ConceptComplex cc; 
     81                Object obj = sessionFactory.getCurrentSession().get(ConceptComplex.class, conceptId); 
     82                // If Concept has already been read & cached, we may get back a Concept instead of 
     83                // ConceptComplex.  If this happens, we need to clear the object from the cache 
     84                // and re-fetch it as a ConceptComplex 
     85                if (obj != null && !obj.getClass().equals(ConceptComplex.class)) { 
     86                        sessionFactory.getCurrentSession().evict(obj); // remove from cache 
     87                        // session.get() did not work here, we need to perform a query to get a ConceptComplex 
     88                        Query query = sessionFactory.getCurrentSession().createQuery("from ConceptComplex where conceptId = :conceptId") 
     89                                .setParameter("conceptId", conceptId); 
     90                        obj = query.uniqueResult(); 
     91                } 
     92                cc = (ConceptComplex)obj; 
     93 
     94                return cc; 
    8595        } 
    8696