DefaultQueryPlanner implements QueryPlanner { @Override public QueryPlan planQuery( Query query ) { return planQuery( query, false ); } @Autowired  DefaultQueryPlanner( SchemaService schemaService ); @Override QueryPlan planQuery( Query query ); @Override QueryPlan planQuery( Query query, boolean persistedOnly ); @Override QueryPath getQueryPath( Schema schema, String path ); @Override Path<?> getQueryPath( Root<?> root, Schema schema, String path );  }
@Test public void verifyPlanQueryReturnsPersistedAndNotPersistedQueries() throws Exception { 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 ); Query query = Query.from( schema, Junction.Type.OR ); query.add( Restrictions.eq( "id", 100L ) ); 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() ); }
@Test public void verifyPlanQueryReturnsNonPersistedQueryWithCriterion() throws Exception { 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", false ); Schema schema = new OrganisationUnitSchemaDescriptor().getSchema(); schema.setPropertyMap( propertyMap ); Query query = Query.from( schema, Junction.Type.OR ); query.add( Restrictions.eq( "name", "test" ) ); query.add( Restrictions.eq( "id", 100 ) ); 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 ); }
@Test public void verifyPlanQueryReturnsNonPersistedQueryWithCriterion2() throws Exception { 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 ); 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 ) ); 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 ); }