← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 974: Improved performance in method addOrganisationUnitHierarchy

 

------------------------------------------------------------
revno: 974
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-11-03 19:32:48 +0100
message:
  Improved performance in method addOrganisationUnitHierarchy
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2009-11-03 14:25:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2009-11-03 18:32:48 +0000
@@ -47,7 +47,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitStore;
-import org.hisp.dhis.source.SourceStore;
+import org.hisp.dhis.system.objectmapper.OrganisationUnitHierarchyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
 
 /**
  * @author Kristian Nordal
@@ -74,13 +75,13 @@
         this.statementManager = statementManager;
     }
 
-    private SourceStore sourceStore;
+    private JdbcTemplate jdbcTemplate;
 
-    public void setSourceStore( SourceStore sourceStore )
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
     {
-        this.sourceStore = sourceStore;
+        this.jdbcTemplate = jdbcTemplate;
     }
-    
+
     // -------------------------------------------------------------------------
     // OrganisationUnit
     // -------------------------------------------------------------------------
@@ -149,37 +150,32 @@
      * @param date The date to assign to the organisation unit hierarchy
      * @return Id of the organisation unit hierarchy
      */
+    @SuppressWarnings( "unchecked" )
     public int addOrganisationUnitHierarchy( Date date )
     {
         Session session = sessionFactory.getCurrentSession();
 
-        // -----------------------------------------------------------------
+        // ---------------------------------------------------------------------
         // Removes any hierarchies registered on the same date
-        // -----------------------------------------------------------------
+        // ---------------------------------------------------------------------
 
         removeOrganisationUnitHierarchies( date );
 
-        Collection<OrganisationUnit> units = sourceStore.getAllSources( OrganisationUnit.class );
+        final String sql = "SELECT organisationunitid, parentid FROM organisationunit";
 
+        List<Integer[]> units = jdbcTemplate.query( sql, new OrganisationUnitHierarchyRowMapper() );
+        
         Map<Integer, Integer> structure = new HashMap<Integer, Integer>( units.size() );
 
-        // -----------------------------------------------------------------
-        // Fills the array with id / parentId pairs for all organisation
-        // units
-        // -----------------------------------------------------------------
+        // ---------------------------------------------------------------------
+        // Fills the array with id / parentId pairs for all organisation units
+        // ---------------------------------------------------------------------
 
-        for ( OrganisationUnit unit : units )
+        for ( Integer[] unit : units )
         {
-            if ( unit.getParent() != null )
-            {
-                structure.put( unit.getId(), unit.getParent().getId() );
-            }
-            else
-            {
-                structure.put( unit.getId(), 0 );
-            }
+            structure.put( unit[0], unit[1] );
         }
-
+        
         OrganisationUnitHierarchy organisationUnitHierarchy = new OrganisationUnitHierarchy( date, structure );
 
         return (Integer) session.save( organisationUnitHierarchy );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2009-11-03 14:44:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2009-11-03 18:32:48 +0000
@@ -154,8 +154,7 @@
     class="org.hisp.dhis.organisationunit.hibernate.HibernateOrganisationUnitStore">
     <property name="sessionFactory" ref="sessionFactory"/>
     <property name="statementManager" ref="statementManager"/>
-    <property name="sourceStore"
-      ref="org.hisp.dhis.source.SourceStore"/>
+    <property name="jdbcTemplate" ref="jdbcTemplate"/>
   </bean>
 
   <bean id="org.hisp.dhis.organisationunit.OrganisationUnitGroupStore"