/** * Get missing entries via pagination. * @param location * @param pageIndex starts from 0 * @param pageSize how many entries in each page * @return */ @Override public Set<String> getMissing( Location location, int pageIndex, int pageSize ) { logger.debug( "[NFC] getMissing for {} start, pageIndex: {}, pageSize: {}", location, pageIndex, pageSize ); Set<String> paths = new HashSet<>(); pageSize = getProperPageSize(pageSize); long offset = pageIndex * pageSize; Query query = queryFactory.from( NfcConcreteResourceWrapper.class ) .startOffset( offset ) .maxResults( pageSize ) .orderBy( "path" ) .having( "location" ) .eq( ( (KeyedLocation) location ).getKey().toString() ) .toBuilder() .build(); List<NfcConcreteResourceWrapper> matches = query.list(); matches.forEach( resource -> paths.add( resource.getPath() ) ); logger.debug( "[NFC] getMissing complete, count: {}", matches.size() ); return paths; }
public void testGroupingWithFilter() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .select("name") .having("name").eq("John") .groupBy("name") .having("name").eq("John") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals("John", list.get(0)[0]); }
@Override public Map<Location, Set<String>> getAllMissing( int pageIndex, int pageSize ) { logger.debug( "[NFC] getAllMissing start, pageIndex: {}, pageSize: {}", pageIndex, pageSize ); Map<Location, Set<String>> result = new HashMap<>(); pageSize = getProperPageSize(pageSize); long offset = pageIndex * pageSize; Query query = queryFactory.from( NfcConcreteResourceWrapper.class ) .startOffset( offset ) .maxResults( pageSize ) .orderBy( "location" ) .orderBy( "path" ) .build(); List<NfcConcreteResourceWrapper> all = query.list(); for ( NfcConcreteResourceWrapper entry : all ) { String loc = entry.getLocation(); StoreKey storeKey = fromString( loc ); Set<String> paths = result.computeIfAbsent( new NfcKeyedLocation( storeKey ), k -> new HashSet<>() ); paths.add( entry.getPath() ); } logger.debug( "[NFC] getAllMissing complete, size: {}", all.size() ); return result; }
@Override public Set<String> getMissing( final Location location ) { logger.debug( "[NFC] getMissing for {} start", location ); Set<String> paths = new HashSet<>(); Query query = queryFactory.from( NfcConcreteResourceWrapper.class ) .maxResults( maxResultSetSize ) .having( "location" ) .eq( ( (KeyedLocation) location ).getKey().toString() ) .toBuilder() .build(); List<NfcConcreteResourceWrapper> matches = query.list(); matches.forEach( resource -> paths.add( resource.getPath() )); logger.debug( "[NFC] getMissing complete, count: {}", matches.size() ); return paths; }
@Override public Map<Location, Set<String>> getAllMissing() { logger.debug( "[NFC] getAllMissing start" ); Map<Location, Set<String>> result = new HashMap<>(); Query query = queryFactory.from( NfcConcreteResourceWrapper.class ) .maxResults( maxResultSetSize ) .build(); List<NfcConcreteResourceWrapper> all = query.list(); for ( NfcConcreteResourceWrapper entry : all ) { String loc = entry.getLocation(); StoreKey storeKey = fromString( loc ); Set<String> paths = result.computeIfAbsent( new NfcKeyedLocation( storeKey ), k -> new HashSet<>() ); paths.add( entry.getPath() ); } logger.debug( "[NFC] getAllMissing complete, size: {}", all.size() ); return result; }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN014026: The expression 'surname' must be part of an aggregate function or it should be included in the GROUP BY clause") public void testGroupBy3() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .select("name") .groupBy("name") .orderBy("surname") .build(); q.list(); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028515: Cannot have aggregate functions in the WHERE clause : MIN.") public void testRejectAggregationsInWhereClause() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .select("name") .having("name").eq(min("addresses.street")) .build(); q.list(); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028503:.*") public void testInvalidEmbeddedAttributeQuery() { QueryFactory qf = getQueryFactory(); QueryBuilder queryBuilder = qf.from(getModelFactory().getUserImplClass()) .select("addresses"); Query q = queryBuilder.build(); q.list(); // exception expected }
public void testSampleDomainQuery1() { QueryFactory qf = getQueryFactory(); // all male users Query q = qf.from(getModelFactory().getUserImplClass()) .orderBy("name", SortOrder.ASC) .having("gender").eq(User.Gender.MALE) .build(); List<User> list = q.list(); assertEquals(2, list.size()); assertEquals("John", list.get(0).getName()); assertEquals("Spider", list.get(1).getName()); }
public void testUnorderedPagination7() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .startOffset(1).maxResults(10) .build(); List<User> list = q.list(); assertEquals(3, q.getResultSize()); assertEquals(2, list.size()); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN014024: The property path 'addresses.street' cannot be used in the ORDER BY clause because it is multi-valued") public void testOrderByMustNotAcceptRepeatedProperty() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .select("name") .orderBy("addresses.street") .build(); q.list(); }
public void testContainsAny1() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .orderBy("id", SortOrder.ASC) .having("accountIds").containsAny(2, 3) .build(); List<User> list = q.list(); assertEquals(2, list.size()); assertEquals(1, list.get(0).getId()); assertEquals(2, list.get(1).getId()); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN014023: Using the multi-valued property path 'addresses.street' in the GROUP BY clause is not currently supported") public void testGroupByMustNotAcceptRepeatedProperty() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .select(min("name")) .groupBy("addresses.street") .build(); q.list(); }
public void testOrderedPagination4() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .orderBy("id", SortOrder.ASC) .maxResults(5) .build(); List<User> list = q.list(); assertEquals(3, q.getResultSize()); assertEquals(3, list.size()); }
public void testOrderedPagination5() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .orderBy("id", SortOrder.ASC) .startOffset(20) .build(); List<User> list = q.list(); assertEquals(3, q.getResultSize()); assertEquals(0, list.size()); }
public void testSortByDate() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("creationDate", SortOrder.DESC) .build(); List<Account> list = q.list(); assertEquals(3, list.size()); assertEquals(3, list.get(0).getId()); assertEquals(2, list.get(1).getId()); assertEquals(1, list.get(2).getId()); }
/** * Using grouping and aggregation with continuous query is not allowed. */ @Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = ".*ISPN028509:.*") public void testDisallowGroupingAndAggregation() { Query query = Search.getQueryFactory(cache()).from(Person.class) .select(max("age")) .having("age").gte(20) .build(); ContinuousQuery<Object, Object> cq = Search.getContinuousQuery(cache()); cq.addContinuousQueryListener(query, new CallCountingCQResultListener<>()); }