← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22004: minor optimization, cache DEFAULTS in id object manager

 

------------------------------------------------------------
revno: 22004
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-02-19 12:11:32 +0700
message:
  minor optimization, cache DEFAULTS in id object manager
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/java/org/hisp/dhis/node/Preset.java


--
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	2016-02-18 07:59:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2016-02-19 05:11:32 +0000
@@ -72,6 +72,8 @@
 {
     private static final Log log = LogFactory.getLog( DefaultIdentifiableObjectManager.class );
 
+    private final Map<Class<? extends IdentifiableObject>, IdentifiableObject> DEFAULTS = new HashMap<>();
+
     @Autowired
     private Set<GenericIdentifiableObjectStore<? extends IdentifiableObject>> identifiableObjectStores;
 
@@ -1113,13 +1115,15 @@
     @Override
     public Map<Class<? extends IdentifiableObject>, IdentifiableObject> getDefaults()
     {
-        Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = new HashMap<>();
-        defaults.put( DataElementCategory.class, getByName( DataElementCategory.class, "default" ) );
-        defaults.put( DataElementCategoryCombo.class, getByName( DataElementCategoryCombo.class, "default" ) );
-        defaults.put( DataElementCategoryOption.class, getByName( DataElementCategoryOption.class, "default" ) );
-        defaults.put( DataElementCategoryOptionCombo.class, getByName( DataElementCategoryOptionCombo.class, "default" ) );
+        if ( DEFAULTS.isEmpty() )
+        {
+            DEFAULTS.put( DataElementCategory.class, getByName( DataElementCategory.class, "default" ) );
+            DEFAULTS.put( DataElementCategoryCombo.class, getByName( DataElementCategoryCombo.class, "default" ) );
+            DEFAULTS.put( DataElementCategoryOption.class, getByName( DataElementCategoryOption.class, "default" ) );
+            DEFAULTS.put( DataElementCategoryOptionCombo.class, getByName( DataElementCategoryOptionCombo.class, "default" ) );
+        }
 
-        return defaults;
+        return DEFAULTS;
     }
 
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/Preset.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/Preset.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/Preset.java	2016-02-19 05:11:32 +0000
@@ -38,6 +38,7 @@
 public enum Preset
 {
     ID( "id", Lists.newArrayList( "id" ) ),
+    CODE( "code", Lists.newArrayList( "code" ) ),
     ID_NAME( "idName", Lists.newArrayList( "id", "displayName" ) ),
     ALL( "all", Lists.newArrayList( "*" ) ),
     IDENTIFIABLE( "identifiable", Lists.newArrayList( "id", "name", "code", "created", "lastUpdated", "href" ) ),