← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13274: IdentifiableObjectManager, initializing maps of stores manually. Working around a problem with be...

 

------------------------------------------------------------
revno: 13274
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-17 12:18:54 +0100
message:
  IdentifiableObjectManager, initializing maps of stores manually. Working around a problem with bean initialization order in spring.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.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/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2013-12-16 17:21:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2013-12-17 11:18:54 +0000
@@ -28,15 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
-import org.hisp.dhis.common.NameableObject.NameableProperty;
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.annotation.PostConstruct;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -47,6 +38,14 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
+import org.hisp.dhis.common.NameableObject.NameableProperty;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
 /**
  * @author Lars Helge Overland
  */
@@ -66,30 +65,6 @@
 
     private Map<Class<NameableObject>, GenericNameableObjectStore<NameableObject>> nameableObjectStoreMap;
 
-    @PostConstruct
-    public void init()
-    {
-        identifiableObjectStoreMap = new HashMap<Class<IdentifiableObject>, GenericIdentifiableObjectStore<IdentifiableObject>>();
-
-        for ( GenericIdentifiableObjectStore<IdentifiableObject> store : identifiableObjectStores )
-        {
-            if ( store != null && store.getClazz() != null )
-            {
-                identifiableObjectStoreMap.put( store.getClazz(), store );
-            }
-        }
-
-        nameableObjectStoreMap = new HashMap<Class<NameableObject>, GenericNameableObjectStore<NameableObject>>();
-
-        for ( GenericNameableObjectStore<NameableObject> store : nameableObjectStores )
-        {
-            if ( store != null && store.getClazz() != null )
-            {
-                nameableObjectStoreMap.put( store.getClazz(), store );
-            }
-        }
-    }
-
     //--------------------------------------------------------------------------
     // IdentifiableObjectManager implementation
     //--------------------------------------------------------------------------
@@ -571,8 +546,14 @@
         }
     }
 
+    //--------------------------------------------------------------------------
+    // Supportive methods
+    //--------------------------------------------------------------------------
+
     private <T extends IdentifiableObject> GenericIdentifiableObjectStore<IdentifiableObject> getIdentifiableObjectStore( Class<T> clazz )
     {
+        initMaps();
+        
         GenericIdentifiableObjectStore<IdentifiableObject> store = identifiableObjectStoreMap.get( clazz );
 
         if ( store == null )
@@ -590,6 +571,8 @@
 
     private <T extends NameableObject> GenericNameableObjectStore<NameableObject> getNameableObjectStore( Class<T> clazz )
     {
+        initMaps();
+        
         GenericNameableObjectStore<NameableObject> store = nameableObjectStoreMap.get( clazz );
 
         if ( store == null )
@@ -604,4 +587,26 @@
 
         return store;
     }
+
+    private void initMaps()
+    {
+        if ( identifiableObjectStoreMap != null )
+        {
+            return; // Already initialized
+        }
+        
+        identifiableObjectStoreMap = new HashMap<Class<IdentifiableObject>, GenericIdentifiableObjectStore<IdentifiableObject>>();
+
+        for ( GenericIdentifiableObjectStore<IdentifiableObject> store : identifiableObjectStores )
+        {
+            identifiableObjectStoreMap.put( store.getClazz(), store );
+        }
+
+        nameableObjectStoreMap = new HashMap<Class<NameableObject>, GenericNameableObjectStore<NameableObject>>();
+
+        for ( GenericNameableObjectStore<NameableObject> store : nameableObjectStores )
+        {
+            nameableObjectStoreMap.put( store.getClazz(), store );
+        }
+    }
 }

=== 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	2013-12-16 15:18:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-12-17 11:18:54 +0000
@@ -55,7 +55,6 @@
     <property name="jdbcTemplate" ref="jdbcTemplate" />
   </bean>
 
-  <!--@author Ovidiu Rosu <rosu.ovi@xxxxxxxxx>-->
   <bean id="org.hisp.dhis.filter.MetaDataFilterStore" class="org.hisp.dhis.metadatafilter.hibernate.HibernateMetaDataFilterStore">
     <property name="clazz" value="org.hisp.dhis.filter.MetaDataFilter" />
     <property name="sessionFactory" ref="sessionFactory" />