use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class QueryUtilsTest method setUp.
@BeforeEach
void setUp() {
schema = new Schema(Attribute.class, "attribute", "attributes");
Property property = new Property(String.class);
property.setName("value1");
property.setSimple(true);
schema.addProperty(property);
property = new Property(String.class);
property.setName("value2");
property.setSimple(false);
schema.addProperty(property);
property = new Property(String.class);
property.setName("value3");
property.setSimple(true);
schema.addProperty(property);
property = new Property(Integer.class);
property.setName("value4");
property.setSimple(true);
schema.addProperty(property);
property = new Property(String.class);
property.setName("value5");
property.setSimple(true);
schema.addProperty(property);
property = new Property(String.class);
property.setName("value6");
property.setSimple(true);
schema.addProperty(property);
property = new Property(String.class);
property.setName("value7");
property.setSimple(true);
schema.addProperty(property);
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class DefaultQueryPlannerTest method verifyPlanQueryReturnsNonPersistedQueryWithCriterion.
/*
* Verifies that when adding criteria on non-persisted fields and using OR
* junction type the planner returns a "non Persisted Query" containing all
* the criteria - since it will execute filter on the entire dataset from
* the target table
*/
@Test
void verifyPlanQueryReturnsNonPersistedQueryWithCriterion() throws Exception {
// Create schema with attributes
final Attribute attribute = new Attribute();
final Map<String, Property> propertyMap = new HashMap<>();
addProperty(propertyMap, attribute, "id", true);
addProperty(propertyMap, attribute, "uid", true);
// note that this is a non-persisted attribute!
addProperty(propertyMap, attribute, "name", false);
Schema schema = new OrganisationUnitSchemaDescriptor().getSchema();
schema.setPropertyMap(propertyMap);
// Add restrictions on a non persisted field
Query query = Query.from(schema, Junction.Type.OR);
// adding a criterion on a non-persisted attribute
query.add(Restrictions.eq("name", "test"));
query.add(Restrictions.eq("id", 100));
// method under test
QueryPlan queryPlan = subject.planQuery(query, false);
Query persistedQuery = queryPlan.getPersistedQuery();
assertTrue(persistedQuery.isPlannedQuery());
assertEquals(persistedQuery.getCriterions().size(), 0);
assertEquals(persistedQuery.getFirstResult().intValue(), 0);
assertEquals(persistedQuery.getMaxResults().intValue(), Integer.MAX_VALUE);
assertEquals(persistedQuery.getRootJunctionType(), Junction.Type.AND);
Query nonPersistedQuery = queryPlan.getNonPersistedQuery();
assertEquals(nonPersistedQuery.getCriterions().size(), 2);
assertTrue(nonPersistedQuery.isPlannedQuery());
assertEquals(nonPersistedQuery.getRootJunctionType(), Junction.Type.OR);
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class QueryTest method createProperty.
private Property createProperty(Class<?> klazz, String name, boolean simple, boolean persisted) {
Property property = new Property(klazz);
property.setName(name);
property.setFieldName(name);
property.setSimple(simple);
property.setPersisted(persisted);
return property;
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class JpaQueryUtilsTest method createSelectOrderExpressionSingle.
@Test
void createSelectOrderExpressionSingle() {
final Property property1 = new Property();
property1.setName("value1");
property1.setSimple(true);
property1.setKlass(String.class);
property1.setPersisted(true);
Assertions.assertEquals("lower(value1)", JpaQueryUtils.createSelectOrderExpression(Collections.singletonList(new Order(property1, Direction.ASCENDING).ignoreCase()), null));
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class JpaQueryUtilsTest method createOrderExpressionAlias.
@Test
void createOrderExpressionAlias() {
final Property property1 = new Property();
property1.setName("value1");
property1.setSimple(true);
property1.setPersisted(true);
Assertions.assertEquals("x.value1 asc", JpaQueryUtils.createOrderExpression(Collections.singletonList(new Order(property1, Direction.ASCENDING)), "x"));
}
Aggregations