dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41249
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21008: minor updates to operators
------------------------------------------------------------
revno: 21008
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-11-10 14:53:30 +0700
message:
minor updates to operators
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Type.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.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/CriteriaQueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java 2015-11-05 05:04:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java 2015-11-10 07:53:30 +0000
@@ -220,7 +220,7 @@
Property property = schema.getProperty( restriction.getPath() );
- return restriction.getOperator().getHibernateCriterion( property.getFieldName() );
+ return restriction.getOperator().getHibernateCriterion( property );
}
public org.hibernate.criterion.Order getHibernateOrder( Order order )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Type.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Type.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Type.java 2015-11-10 07:53:30 +0000
@@ -68,8 +68,11 @@
private boolean isSet;
+ private boolean isNull;
+
public Type( Object object )
{
+ isNull = object == null;
isString = String.class.isInstance( object );
isChar = Character.class.isInstance( object );
isByte = Byte.class.isInstance( object );
@@ -85,6 +88,11 @@
isSet = Set.class.isInstance( object );
}
+ public boolean isNull()
+ {
+ return isNull;
+ }
+
public boolean isString()
{
return isString;
@@ -167,6 +175,7 @@
.add( "isCollection", isCollection )
.add( "isList", isList )
.add( "isSet", isSet )
+ .add( "isNull", isNull )
.toString();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java 2015-11-10 07:53:30 +0000
@@ -32,6 +32,7 @@
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +48,9 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.between( propertyName, args.get( 0 ), args.get( 1 ) );
+ return Restrictions.between( property.getFieldName(), args.get( 0 ), args.get( 1 ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java 2015-11-10 07:53:30 +0000
@@ -30,8 +30,11 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.query.QueryException;
+import org.hisp.dhis.query.QueryUtils;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +50,21 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.eq( propertyName, args.get( 0 ) );
+ if ( property.isCollection() )
+ {
+ Integer value = QueryUtils.getValue( Integer.class, args.get( 0 ) );
+
+ if ( value == null )
+ {
+ throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size." );
+ }
+
+ return Restrictions.sizeEq( property.getFieldName(), value );
+ }
+
+ return Restrictions.eq( property.getFieldName(), args.get( 0 ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java 2015-11-10 07:53:30 +0000
@@ -30,8 +30,11 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.query.QueryException;
+import org.hisp.dhis.query.QueryUtils;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +50,21 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.ge( propertyName, args.get( 0 ) );
+ if ( property.isCollection() )
+ {
+ Integer value = QueryUtils.getValue( Integer.class, args.get( 0 ) );
+
+ if ( value == null )
+ {
+ throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size." );
+ }
+
+ return Restrictions.sizeGe( property.getFieldName(), value );
+ }
+
+ return Restrictions.ge( property.getFieldName(), args.get( 0 ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java 2015-11-10 07:53:30 +0000
@@ -30,8 +30,11 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.query.QueryException;
+import org.hisp.dhis.query.QueryUtils;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +50,21 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.gt( propertyName, args.get( 0 ) );
+ if ( property.isCollection() )
+ {
+ Integer value = QueryUtils.getValue( Integer.class, args.get( 0 ) );
+
+ if ( value == null )
+ {
+ throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size." );
+ }
+
+ return Restrictions.sizeGt( property.getFieldName(), value );
+ }
+
+ return Restrictions.gt( property.getFieldName(), args.get( 0 ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java 2015-11-10 07:53:30 +0000
@@ -32,6 +32,7 @@
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +48,9 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.in( propertyName, getValue( Collection.class, args.get( 0 ) ) );
+ return Restrictions.in( property.getFieldName(), getValue( Collection.class, args.get( 0 ) ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java 2015-11-10 07:53:30 +0000
@@ -30,8 +30,11 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.query.QueryException;
+import org.hisp.dhis.query.QueryUtils;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +50,21 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.le( propertyName, args.get( 0 ) );
+ if ( property.isCollection() )
+ {
+ Integer value = QueryUtils.getValue( Integer.class, args.get( 0 ) );
+
+ if ( value == null )
+ {
+ throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size." );
+ }
+
+ return Restrictions.sizeLe( property.getFieldName(), value );
+ }
+
+ return Restrictions.le( property.getFieldName(), args.get( 0 ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java 2015-11-10 07:53:30 +0000
@@ -30,8 +30,11 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.query.QueryException;
+import org.hisp.dhis.query.QueryUtils;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Collection;
import java.util.Date;
@@ -47,9 +50,21 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.lt( propertyName, args.get( 0 ) );
+ if ( property.isCollection() )
+ {
+ Integer value = QueryUtils.getValue( Integer.class, args.get( 0 ) );
+
+ if ( value == null )
+ {
+ throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size." );
+ }
+
+ return Restrictions.sizeLt( property.getFieldName(), value );
+ }
+
+ return Restrictions.lt( property.getFieldName(), args.get( 0 ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java 2015-11-10 07:53:30 +0000
@@ -33,6 +33,7 @@
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -51,15 +52,15 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
if ( caseSensitive )
{
- return Restrictions.like( propertyName, String.valueOf( args.get( 0 ) ), matchMode );
+ return Restrictions.like( property.getFieldName(), String.valueOf( args.get( 0 ) ), matchMode );
}
else
{
- return Restrictions.ilike( propertyName, String.valueOf( args.get( 0 ) ), matchMode );
+ return Restrictions.ilike( property.getFieldName(), String.valueOf( args.get( 0 ) ), matchMode );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java 2015-11-05 03:55:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java 2015-11-10 07:53:30 +0000
@@ -30,6 +30,7 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.schema.Property;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -42,9 +43,9 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.not( super.getHibernateCriterion( propertyName ) );
+ return Restrictions.not( super.getHibernateCriterion( property ) );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java 2015-11-04 09:45:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java 2015-11-10 07:53:30 +0000
@@ -31,6 +31,7 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Date;
@@ -45,9 +46,9 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.isNotNull( propertyName );
+ return Restrictions.isNotNull( property.getFieldName() );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java 2015-11-04 09:45:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java 2015-11-10 07:53:30 +0000
@@ -31,6 +31,7 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.Date;
@@ -45,9 +46,9 @@
}
@Override
- public Criterion getHibernateCriterion( String propertyName )
+ public Criterion getHibernateCriterion( Property property )
{
- return Restrictions.isNull( propertyName );
+ return Restrictions.isNull( property.getFieldName() );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java 2015-11-10 07:03:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java 2015-11-10 07:53:30 +0000
@@ -32,6 +32,7 @@
import org.hisp.dhis.query.QueryUtils;
import org.hisp.dhis.query.Type;
import org.hisp.dhis.query.Typed;
+import org.hisp.dhis.schema.Property;
import java.util.ArrayList;
import java.util.Collections;
@@ -92,7 +93,7 @@
return typed.isValid( klass );
}
- public abstract Criterion getHibernateCriterion( String propertyName );
+ public abstract Criterion getHibernateCriterion( Property property );
public abstract boolean test( Object value );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java 2015-11-09 05:35:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/CriteriaQueryEngineTest.java 2015-11-10 07:53:30 +0000
@@ -34,10 +34,13 @@
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.query.operators.MatchMode;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
import org.jfree.data.time.Year;
+import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +64,8 @@
@Autowired
private IdentifiableObjectManager identifiableObjectManager;
- private void createDataElements()
+ @Before
+ public void createDataElements()
{
DataElement dataElementA = createDataElement( 'A' );
dataElementA.setValueType( ValueType.NUMBER );
@@ -94,6 +98,19 @@
identifiableObjectManager.save( dataElementC );
identifiableObjectManager.save( dataElementF );
identifiableObjectManager.save( dataElementD );
+
+ DataElementGroup dataElementGroupA = createDataElementGroup( 'A' );
+ dataElementGroupA.addDataElement( dataElementA );
+ dataElementGroupA.addDataElement( dataElementB );
+ dataElementGroupA.addDataElement( dataElementC );
+ dataElementGroupA.addDataElement( dataElementD );
+
+ DataElementGroup dataElementGroupB = createDataElementGroup( 'B' );
+ dataElementGroupB.addDataElement( dataElementE );
+ dataElementGroupB.addDataElement( dataElementF );
+
+ identifiableObjectManager.save( dataElementGroupA );
+ identifiableObjectManager.save( dataElementGroupB );
}
private boolean collectionContainsUid( Collection<? extends IdentifiableObject> collection, String uid )
@@ -112,7 +129,6 @@
@Test
public void getAllQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
assertEquals( 6, queryEngine.query( query ).size() );
}
@@ -120,7 +136,6 @@
@Test
public void getMinMaxQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.setFirstResult( 2 );
query.setMaxResults( 10 );
@@ -137,7 +152,6 @@
@Test
public void getEqQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.eq( "id", "deabcdefghA" ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -149,7 +163,6 @@
@Test
public void getNeQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.ne( "id", "deabcdefghA" ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -167,7 +180,6 @@
@Test
public void getLikeQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.like( "name", "F", MatchMode.ANYWHERE ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -179,7 +191,6 @@
@Test
public void getGtQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.gt( "created", Year.parseYear( "2003" ).getStart() ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -194,7 +205,6 @@
@Test
public void getLtQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.lt( "created", Year.parseYear( "2003" ).getStart() ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -208,7 +218,6 @@
@Test
public void getGeQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.ge( "created", Year.parseYear( "2003" ).getStart() ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -224,7 +233,6 @@
@Test
public void getLeQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.le( "created", Year.parseYear( "2003" ).getStart() ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -239,7 +247,6 @@
@Test
public void getBetweenQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.between( "created", Year.parseYear( "2003" ).getStart(), Year.parseYear( "2005" ).getStart() ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -254,7 +261,6 @@
@Test
public void getInQuery()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.in( "id", Lists.newArrayList( "deabcdefghD", "deabcdefghF" ) ) );
List<? extends IdentifiableObject> objects = queryEngine.query( query );
@@ -268,7 +274,6 @@
@Test
public void sortNameDesc()
{
- createDataElements();
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
@@ -288,7 +293,6 @@
@Test
public void sortNameAsc()
{
- createDataElements();
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
@@ -308,7 +312,6 @@
@Test
public void sortCreatedDesc()
{
- createDataElements();
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
@@ -328,7 +331,6 @@
@Test
public void sortCreatedAsc()
{
- createDataElements();
Schema schema = schemaService.getDynamicSchema( DataElement.class );
Query query = Query.from( schema );
@@ -348,7 +350,6 @@
@Test
public void testDoubleEqConjunction()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
Conjunction conjunction = query.conjunction();
@@ -364,7 +365,6 @@
@Test
public void testDoubleEqDisjunction()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
Disjunction disjunction = query.disjunction();
@@ -383,7 +383,6 @@
@Test
public void testDateRange()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) );
@@ -401,7 +400,6 @@
@Test
public void testDateRangeWithConjunction()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
Conjunction conjunction = query.conjunction();
@@ -421,7 +419,6 @@
@Test
public void testIsNull()
{
- createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
query.add( Restrictions.isNull( "categoryCombo" ) );
@@ -436,4 +433,28 @@
assertTrue( collectionContainsUid( objects, "deabcdefghE" ) );
assertTrue( collectionContainsUid( objects, "deabcdefghF" ) );
}
+
+ @Test
+ @Ignore
+ public void testCollectionEqSize4()
+ {
+ Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
+ query.add( Restrictions.eq( "dataElements", 4 ) );
+ List<? extends IdentifiableObject> objects = queryEngine.query( query );
+
+ assertEquals( 1, objects.size() );
+ assertEquals( "abcdefghijA", objects.get( 0 ).getUid() );
+ }
+
+ @Test
+ @Ignore
+ public void testCollectionEqSize2()
+ {
+ Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
+ query.add( Restrictions.eq( "dataElements", 2 ) );
+ List<? extends IdentifiableObject> objects = queryEngine.query( query );
+
+ assertEquals( 1, objects.size() );
+ assertEquals( "abcdefghijB", objects.get( 0 ).getUid() );
+ }
}
=== 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 2015-11-10 06:17:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java 2015-11-10 07:53:30 +0000
@@ -560,7 +560,7 @@
}
@Test
- public void testCollectionSize()
+ public void testCollectionEqSize()
{
Query query = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
query.setObjects( dataElementGroups );