dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36055
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18461: switch to using CacheMap for EventService caching
------------------------------------------------------------
revno: 18461
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-03-03 15:07:29 +0700
message:
switch to using CacheMap for EventService caching
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.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-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-03-03 05:06:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-03-03 08:07:29 +0000
@@ -59,8 +59,10 @@
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.program.ProgramStatus;
import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.system.callable.IdentifiableObjectCallable;
import org.hisp.dhis.system.notification.NotificationLevel;
import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.system.util.CachingMap;
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.system.util.DebugUtils;
import org.hisp.dhis.system.util.ValidationUtils;
@@ -151,13 +153,13 @@
private static final ObjectMapper objectMapper = new ObjectMapper();
- private Map<String, OrganisationUnit> organisationUnitCache = new HashMap<>();
-
- private Map<String, Program> programCache = new HashMap<>();
-
- private Map<String, ProgramStage> programStageCache = new HashMap<>();
-
- private Map<String, DataElement> dataElementCache = new HashMap<>();
+ private CachingMap<String, OrganisationUnit> organisationUnitCache = new CachingMap<>();
+
+ private CachingMap<String, Program> programCache = new CachingMap<>();
+
+ private CachingMap<String, ProgramStage> programStageCache = new CachingMap<>();
+
+ private CachingMap<String, DataElement> dataElementCache = new CachingMap<>();
private List<Program> accessiblePrograms = new ArrayList<>();
@@ -1051,67 +1053,16 @@
private Program getProgram( String programId )
{
- if ( StringUtils.isEmpty( programId ) )
- {
- return null;
- }
-
- if ( !programCache.containsKey( programId ) )
- {
- Program program = manager.get( Program.class, programId );
-
- if ( program == null )
- {
- return null;
- }
-
- programCache.put( programId, program );
- }
-
- return programCache.get( programId );
+ return programCache.get( programId, new IdentifiableObjectCallable<>( manager, Program.class, programId ) );
}
private ProgramStage getProgramStage( String programStageId )
{
- if ( StringUtils.isEmpty( programStageId ) )
- {
- return null;
- }
-
- if ( !programStageCache.containsKey( programStageId ) )
- {
- ProgramStage programStage = manager.get( ProgramStage.class, programStageId );
-
- if ( programStage == null )
- {
- return null;
- }
-
- programStageCache.put( programStageId, programStage );
- }
-
- return programStageCache.get( programStageId );
+ return programStageCache.get( programStageId, new IdentifiableObjectCallable<>( manager, ProgramStage.class, programStageId ) );
}
private DataElement getDataElement( String dataElementId )
{
- if ( StringUtils.isEmpty( dataElementId ) )
- {
- return null;
- }
-
- if ( !dataElementCache.containsKey( dataElementId ) )
- {
- DataElement dataElement = manager.get( DataElement.class, dataElementId );
-
- if ( dataElement == null )
- {
- return null;
- }
-
- dataElementCache.put( dataElementId, dataElement );
- }
-
- return dataElementCache.get( dataElementId );
+ return dataElementCache.get( dataElementId, new IdentifiableObjectCallable<>( manager, DataElement.class, dataElementId ) );
}
}