@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; }
@Test public void testWithDifferentFactory2() { QueryFactory qf1 = new DummyQueryFactory(); QueryFactory qf2 = new DummyQueryFactory(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("ISPN014809: The given condition was created by another factory"); qf1.from("MyDummyType") .having("attr1").eq("1") .and(qf2.having("attr2").eq("2")); // exception expected }
@Override public long getSize( StoreKey storeKey ) { Query query = queryFactory.from( NfcConcreteResourceWrapper.class ) .select( Expression.count( "path" ) ) .having( "location" ) .eq( storeKey.toString() ) .toBuilder() .build(); List<Object> result = query.list(); Object[] count = (Object[]) result.get( 0 ); return (Long) count[0]; }
@Test public void testWithDifferentFactory3() { QueryFactory qf1 = new DummyQueryFactory(); QueryFactory qf2 = new DummyQueryFactory(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("ISPN014809: The given condition was created by another factory"); qf1.from("MyDummyType") .having("attr1").eq("1") .or(qf2.having("attr2").eq("2")); // exception expected }
@Override public List<KObject> findById(String index, String id) throws IOException { checkNotEmpty("index", index); checkNotEmpty("id", id); List<String> types = this.infinispanContext.getTypes(index); return types .stream() .map(type -> this.getQueryFactory(index) .from(type) .having(MetaObject.META_OBJECT_ID) .eq(id) .build() .list()) .flatMap(x -> x.stream()) .map(x -> (KObject) x) .collect(toList()); }
@Override public List<KObject> findById(String index, String id) throws IOException { checkNotEmpty("index", index); checkNotEmpty("id", id); List<String> types = this.infinispanContext.getTypes(index); return types .stream() .map(type -> this.getQueryFactory(index) .from(type) .having(MetaObject.META_OBJECT_ID) .eq(id) .build() .list()) .flatMap(x -> x.stream()) .map(x -> (KObject) x) .collect(toList()); }
public void testEqNonIndexedType() { QueryFactory qf = getQueryFactory(); Query q = qf.from(NotIndexed.class) .having("notIndexedField").eq("testing 123") .build(); List<NotIndexed> list = q.list(); assertEquals(1, list.size()); assertEquals("testing 123", list.get(0).notIndexedField); }
/** * Test querying for a field - direct access to field. */ public void testField() throws Exception { QueryFactory queryFactory = Search.getQueryFactory(cache); Query query = queryFactory.from(Person.class) .having("driverLicenseId").eq("ZZ3141592") .build(); List<Person> matches = query.list(); assertEquals(1, matches.size()); }
/** * Test querying for an inherited indexed field - interface method implemented in class. */ public void testInheritedField3() throws Exception { QueryFactory queryFactory = Search.getQueryFactory(cache); Query query = queryFactory.from(Person.class) .having("gender").eq("M") .build(); List<Person> matches = query.list(); assertEquals(1, matches.size()); }
/** * Test querying for an inherited indexed field - interface method with inherited implementation. */ public void testInheritedField2() throws Exception { QueryFactory queryFactory = Search.getQueryFactory(cache); Query query = queryFactory.from(Person.class) .having("name").eq("William") .build(); List<Person> matches = query.list(); assertEquals(1, matches.size()); }
/** * Test querying for an inherited indexed field - method inherited from superclass. */ public void testInheritedField4() throws Exception { QueryFactory queryFactory = Search.getQueryFactory(cache); Query query = queryFactory.from(Person.class) .having("surname").eq("Shakespeare") .build(); List<Person> matches = query.list(); assertEquals(1, matches.size()); }
/** * 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 testDuplicateBooleanProjection() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("id", "isDebit", "isDebit") .having("description").eq("Hotel") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).length); assertEquals(3, list.get(0)[0]); assertEquals(true, list.get(0)[1]); assertEquals(true, list.get(0)[2]); }
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]); }
public void testEqSentence() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("description").eq("John Doe's first bank account") .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).getId()); }