@Test public void signature() { StringPath str = Expressions.stringPath("str"); NumberPath<BigDecimal> bigd = Expressions.numberPath(BigDecimal.class, "bigd"); ResultTransformer<Map<String, SortedMap<BigDecimal, SortedMap<BigDecimal, Map<String, String>>>>> resultTransformer = GroupBy.groupBy(str).as( GroupBy.sortedMap(bigd, GroupBy.sortedMap(bigd, GroupBy.map(str, str), Ordering.natural().nullsLast()), Ordering.natural().nullsFirst())); assertNotNull(resultTransformer); }
@Test public void map_sorted() { Map<Integer, Group> results = MAP_RESULTS.transform( groupBy(postId).as(postName, sortedMap(commentId, commentText))); Group group = results.get(1); Iterator<Map.Entry<Integer, String>> it = group.getMap(commentId, commentText).entrySet().iterator(); assertEquals(1, it.next().getKey().intValue()); assertEquals(2, it.next().getKey().intValue()); assertEquals(3, it.next().getKey().intValue()); }
@Override public Map<User, List<ArtifactVersionNotification>> listNotificationsToSend() { JPAQuery<Void> query = new JPAQuery<>(getEntityManager()); return query.from(qArtifactVersionNotification) .where(qArtifactVersionNotification.status.eq(ArtifactVersionNotificationStatus.PENDING)) .orderBy(qArtifactVersionNotification.user.id.asc(), qArtifactVersionNotification.id.asc()) .transform(GroupBy.groupBy(qArtifactVersionNotification.user).as(GroupBy.list(qArtifactVersionNotification))); } }
public EntityVersionStoreJdbc(EntityStoreOptions<Id, M, V> options) { super(options); Expression<?>[] values = concat(versionAndParentColumns, options.sinceVersion.localOrdinal); versionAndParentsSince = groupBy(options.version.revision).list(values); }
@Test public void set_by_sorted() { Map<Integer, Group> results = BASIC_RESULTS_UNORDERED .transform(groupBy(postId).as(postName, sortedSet(commentId))); Group group = results.get(1); Iterator<Integer> it = group.getSet(commentId).iterator(); assertEquals(1, it.next().intValue()); assertEquals(2, it.next().intValue()); assertEquals(3, it.next().intValue()); }
/** * Create a new aggregating map expression using a backing LinkedHashMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K, V, U> AbstractGroupExpression<Pair<K, V>, Map<K, U>> map(Expression<K> key, GroupExpression<V, U> value) { return map(new GOne<K>(key), value); }
/** * Create a new aggregating map expression using a backing TreeMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K, V, T extends Comparable<? super T>> AbstractGroupExpression<Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value) { return sortedMap(key, new GOne<V>(value)); }
@Test public void transform_via_groupByProjection() { Map<Integer, Post> results = POST_W_COMMENTS2.transform( new GroupByProjection<Integer, Post>(postId, postName, set(qComment)) { @Override protected Post transform(Group group) { return new Post( group.getOne(postId), group.getOne(postName), group.getSet(qComment)); } }); Post post = results.get(1); assertNotNull(post); assertEquals(toInt(1), post.getId()); assertEquals("post 1", post.getName()); assertEquals(toSet(comment(1), comment(2), comment(3)), post.getComments()); }
Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s")}); args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str"))); args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num"))); args.put(Number.class, 1); args.put(Operator.class, Ops.AND);
@Test @ExcludeIn(DERBY) public void transform_groupBy() { QCat kitten = new QCat("kitten"); Map<Integer, Cat> result = query().from(cat).innerJoin(cat.kittens, kitten) .transform(GroupBy.groupBy(cat.id) .as(Projections.constructor(Cat.class, cat.name, cat.id, GroupBy.list(Projections.constructor(Cat.class, kitten.name, kitten.id))))); for (Cat entry : result.values()) { assertEquals(1, entry.getKittens().size()); } }
@Override public Map<String, Long> countByBookType(Workspace workspace) { QBook qBook = QBook.book; Map<String, Long> result = from(qBook).where(qBook.workspace.eq(workspace)) .groupBy(qBook.type) .transform(GroupBy.groupBy(qBook.type).as(qBook.count())); return result; }
@Test public void map_sorted_reverse() { Map<Integer, Group> results = MAP_RESULTS.transform( groupBy(postId).as(postName, sortedMap(commentId, commentText, Ordering.natural().reverse()))); Group group = results.get(1); Iterator<Map.Entry<Integer, String>> it = group.getMap(commentId, commentText).entrySet().iterator(); assertEquals(3, it.next().getKey().intValue()); assertEquals(2, it.next().getKey().intValue()); assertEquals(1, it.next().getKey().intValue()); }
@Test public void set_by_sorted_reverse() { Map<Integer, Group> results = BASIC_RESULTS_UNORDERED .transform(groupBy(postId).as(postName, sortedSet(commentId, Ordering.natural().reverse()))); Group group = results.get(1); Iterator<Integer> it = group.getSet(commentId).iterator(); assertEquals(3, it.next().intValue()); assertEquals(2, it.next().intValue()); assertEquals(1, it.next().intValue()); }
/** * Create a new aggregating map expression using a backing LinkedHashMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K, V, T> AbstractGroupExpression<Pair<K, V>, Map<T, V>> map(GroupExpression<K, T> key, Expression<V> value) { return map(key, new GOne<V>(value)); }
/** * Create a new aggregating map expression using a backing TreeMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K extends Comparable<? super K>, V, U> AbstractGroupExpression<Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) { return sortedMap(new GOne<K>(key), value); }