Search in sources :

Example 1 with OrganisationUnitSchemaDescriptor

use of org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor in project dhis2-core by dhis2.

the class DefaultQueryPlannerTest method verifyPlanQueryReturnsPersistedAndNotPersistedQueries.

@Test
void verifyPlanQueryReturnsPersistedAndNotPersistedQueries() 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);
    Schema schema = new OrganisationUnitSchemaDescriptor().getSchema();
    schema.setPropertyMap(propertyMap);
    // Add restriction
    Query query = Query.from(schema, Junction.Type.OR);
    query.add(Restrictions.eq("id", 100L));
    // method under test
    QueryPlan queryPlan = subject.planQuery(query, true);
    Query persistedQuery = queryPlan.getPersistedQuery();
    assertTrue(persistedQuery.isPlannedQuery());
    assertEquals(persistedQuery.getCriterions().size(), 1);
    assertEquals(persistedQuery.getFirstResult().intValue(), 0);
    assertEquals(persistedQuery.getMaxResults().intValue(), Integer.MAX_VALUE);
    assertEquals(persistedQuery.getRootJunctionType(), Junction.Type.OR);
    Query nonPersistedQuery = queryPlan.getNonPersistedQuery();
    assertEquals(nonPersistedQuery.getCriterions().size(), 0);
    assertTrue(nonPersistedQuery.isPlannedQuery());
}
Also used : OrganisationUnitSchemaDescriptor(org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor) Query(org.hisp.dhis.query.Query) Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 2 with OrganisationUnitSchemaDescriptor

use of org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor in project dhis2-core by dhis2.

the class DefaultQueryPlannerTest method verifyPlanQueryReturnsNonPersistedQueryWithCriterion2.

@Test
void verifyPlanQueryReturnsNonPersistedQueryWithCriterion2() 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);
    addProperty(propertyMap, attribute, "name", true);
    Schema schema = new OrganisationUnitSchemaDescriptor().getSchema();
    schema.setPropertyMap(propertyMap);
    // Add restrictions on a non persisted field
    Query query = Query.from(schema, Junction.Type.AND);
    query.setMaxResults(10);
    query.setFirstResult(500);
    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(), 2);
    assertEquals(persistedQuery.getFirstResult().intValue(), 500);
    assertEquals(persistedQuery.getMaxResults().intValue(), 10);
    assertEquals(persistedQuery.getRootJunctionType(), Junction.Type.AND);
    Query nonPersistedQuery = queryPlan.getNonPersistedQuery();
    assertEquals(nonPersistedQuery.getCriterions().size(), 0);
    assertTrue(nonPersistedQuery.isPlannedQuery());
    assertEquals(nonPersistedQuery.getRootJunctionType(), Junction.Type.AND);
}
Also used : OrganisationUnitSchemaDescriptor(org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor) Query(org.hisp.dhis.query.Query) Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 3 with OrganisationUnitSchemaDescriptor

use of org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor 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);
}
Also used : OrganisationUnitSchemaDescriptor(org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor) Query(org.hisp.dhis.query.Query) Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)3 Attribute (org.hisp.dhis.attribute.Attribute)3 Query (org.hisp.dhis.query.Query)3 Property (org.hisp.dhis.schema.Property)3 Schema (org.hisp.dhis.schema.Schema)3 OrganisationUnitSchemaDescriptor (org.hisp.dhis.schema.descriptors.OrganisationUnitSchemaDescriptor)3 Test (org.junit.jupiter.api.Test)3