dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42314
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21635: rewrote logic for getting deep values in in-memory engine
------------------------------------------------------------
revno: 21635
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-01-07 15:48:29 +0700
message:
rewrote logic for getting deep values in in-memory engine
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.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/query/InMemoryQueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/InMemoryQueryEngine.java 2016-01-07 08:48:29 +0000
@@ -34,6 +34,7 @@
import org.hisp.dhis.schema.Property;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.system.util.HibernateUtils;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,7 +46,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-public class InMemoryQueryEngine<T extends IdentifiableObject>
+public class InMemoryQueryEngine<T extends IdentifiableObject>
implements QueryEngine<T>
{
@Autowired
@@ -241,7 +242,16 @@
throw new QueryException( "No property found for path " + path );
}
- object = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
+ if ( property.isCollection() )
+ {
+ currentSchema = schemaService.getDynamicSchema( property.getItemKlass() );
+ }
+ else
+ {
+ currentSchema = schemaService.getDynamicSchema( property.getKlass() );
+ }
+
+ object = collect( object, property );
if ( i == (paths.length - 1) )
{
@@ -253,36 +263,37 @@
return object;
}
- if ( property.isCollection() )
- {
- currentSchema = schemaService.getDynamicSchema( property.getItemKlass() );
- }
- else
- {
- currentSchema = schemaService.getDynamicSchema( property.getKlass() );
- }
-
- if ( property.isCollection() && i == (paths.length - 2) )
- {
- property = currentSchema.getProperty( paths[paths.length - 1] );
-
- if ( property == null )
- {
- throw new QueryException( "No property found for path " + path );
- }
-
- Collection<?> collection = (Collection<?>) object;
- List<Object> items = new ArrayList<>();
-
- for ( Object item : collection )
- {
- items.add( ReflectionUtils.invokeMethod( item, property.getGetterMethod() ) );
- }
-
- return items;
- }
}
throw new QueryException( "No values found for path " + path );
}
+
+ private Object collect( Object object, Property property )
+ {
+ object = HibernateUtils.unwrap( object );
+
+ if ( Collection.class.isInstance( object ) )
+ {
+ Collection<?> collection = (Collection<?>) object;
+ List<Object> items = new ArrayList<>();
+
+ for ( Object item : collection )
+ {
+ Object collect = collect( item, property );
+
+ if ( Collection.class.isInstance( collect ) )
+ {
+ items.addAll( ((Collection) collect) );
+ }
+ else
+ {
+ items.add( collect );
+ }
+ }
+
+ return items;
+ }
+
+ return ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2016-01-05 10:16:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2016-01-07 08:48:29 +0000
@@ -560,6 +560,18 @@
}
@Test
+ public void testCollectionDeep()
+ {
+ Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
+ query.setObjects( dataElementGroups );
+
+ query.add( Restrictions.like( "dataElements.dataElementGroups.name", "A", MatchMode.END ) );
+ List<? extends IdentifiableObject> objects = queryEngine.query( query );
+
+ System.err.println( "xyz: " + objects );
+ }
+
+ @Test
public void testCollectionEqSize()
{
Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );