dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42714
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21803: Change scanner logic in PreheatService to only scan for wanted properties once for collections
------------------------------------------------------------
revno: 21803
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-01-25 11:52:11 +0700
message:
Change scanner logic in PreheatService to only scan for wanted properties once for collections
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.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/preheat/DefaultPreheatService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-01-25 04:37:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-01-25 04:52:11 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.google.common.collect.Sets;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.schema.Property;
@@ -117,93 +118,84 @@
}
@Override
+ public Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectForReferences( Object object, PreheatIdentifier identifier )
+ {
+ return scanObjectsForReferences( Sets.newHashSet( object ), identifier );
+ }
+
+ @Override
@SuppressWarnings( "unchecked" )
- public Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectForReferences( Object object, PreheatIdentifier identifier )
+ public Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectsForReferences( Set<Object> objects, PreheatIdentifier identifier )
{
Map<Class<? extends IdentifiableObject>, Set<String>> map = new HashMap<>();
- if ( object == null )
+ if ( objects.isEmpty() )
{
return map;
}
- Schema schema = schemaService.getDynamicSchema( object.getClass() );
+ Schema schema = schemaService.getDynamicSchema( objects.iterator().next().getClass() );
List<Property> properties = schema.getProperties().stream()
.filter( p -> p.isPersisted() && p.isOwner() && (PropertyType.REFERENCE == p.getPropertyType() || PropertyType.REFERENCE == p.getItemPropertyType()) )
.collect( Collectors.toList() );
properties.forEach( p -> {
- if ( !p.isCollection() )
- {
- Class<? extends IdentifiableObject> klass = (Class<? extends IdentifiableObject>) p.getKlass();
- if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() );
- Object reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() );
-
- if ( reference != null )
- {
- IdentifiableObject identifiableObject = (IdentifiableObject) reference;
-
- if ( PreheatIdentifier.UID == identifier )
- {
- if ( identifiableObject.getUid() != null )
- {
- map.get( klass ).add( identifiableObject.getUid() );
- }
- }
- else if ( PreheatIdentifier.CODE == identifier )
- {
- if ( identifiableObject.getCode() != null )
- {
- map.get( klass ).add( identifiableObject.getCode() );
- }
- }
- }
- }
- else
- {
- Class<? extends IdentifiableObject> klass = (Class<? extends IdentifiableObject>) p.getItemKlass();
- if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() );
- Collection<IdentifiableObject> reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() );
-
- for ( IdentifiableObject identifiableObject : reference )
- {
- if ( PreheatIdentifier.UID == identifier )
- {
- if ( identifiableObject.getUid() != null )
- {
- map.get( klass ).add( identifiableObject.getUid() );
- }
- }
- else if ( PreheatIdentifier.CODE == identifier )
- {
- if ( identifiableObject.getCode() != null )
- {
- map.get( klass ).add( identifiableObject.getCode() );
- }
- }
- }
- }
+ for ( Object object : objects )
+ {
+ if ( !p.isCollection() )
+ {
+ Class<? extends IdentifiableObject> klass = (Class<? extends IdentifiableObject>) p.getKlass();
+ if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() );
+ Object reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() );
+
+ if ( reference != null )
+ {
+ IdentifiableObject identifiableObject = (IdentifiableObject) reference;
+
+ if ( PreheatIdentifier.UID == identifier )
+ {
+ if ( identifiableObject.getUid() != null )
+ {
+ map.get( klass ).add( identifiableObject.getUid() );
+ }
+ }
+ else if ( PreheatIdentifier.CODE == identifier )
+ {
+ if ( identifiableObject.getCode() != null )
+ {
+ map.get( klass ).add( identifiableObject.getCode() );
+ }
+ }
+ }
+ }
+ else
+ {
+ Class<? extends IdentifiableObject> klass = (Class<? extends IdentifiableObject>) p.getItemKlass();
+ if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() );
+ Collection<IdentifiableObject> reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() );
+
+ for ( IdentifiableObject identifiableObject : reference )
+ {
+ if ( PreheatIdentifier.UID == identifier )
+ {
+ if ( identifiableObject.getUid() != null )
+ {
+ map.get( klass ).add( identifiableObject.getUid() );
+ }
+ }
+ else if ( PreheatIdentifier.CODE == identifier )
+ {
+ if ( identifiableObject.getCode() != null )
+ {
+ map.get( klass ).add( identifiableObject.getCode() );
+ }
+ }
+ }
+ }
+ }
+
} );
return map;
}
-
- @Override
- public Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectsForReferences( Set<Object> objects, PreheatIdentifier identifier )
- {
- Map<Class<? extends IdentifiableObject>, Set<String>> referenceMap = new HashMap<>();
-
- for ( Object object : objects )
- {
- Map<Class<? extends IdentifiableObject>, Set<String>> references = scanObjectForReferences( object, identifier );
-
- for ( Class<? extends IdentifiableObject> klass : references.keySet() )
- {
- if ( !referenceMap.containsKey( klass ) ) referenceMap.put( klass, new HashSet<>() );
- referenceMap.get( klass ).addAll( references.get( klass ) );
- }
- }
-
- return referenceMap;
- }
}