@Test(expected = ClassCastException.class) public void classCastException() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); group.getList(commentId); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = ClassCastException.class) public void classCastException() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); group.getList(commentId); }
@Test(expected = ClassCastException.class) public void classCastException() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); group.getList(commentId); }
@Test public void array_access() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); Object[] array = group.toArray(); assertEquals(toInt(1), array[0]); assertEquals("post 1", array[1]); assertEquals(toSet(1, 2, 3), array[2]); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), array[3]); }
@Test public void array_access() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); Object[] array = group.toArray(); assertEquals(toInt(1), array[0]); assertEquals("post 1", array[1]); assertEquals(toSet(1, 2, 3), array[2]); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), array[3]); }
@Test public void array_access() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); Object[] array = group.toArray(); assertEquals(toInt(1), array[0]); assertEquals("post 1", array[1]); assertEquals(toSet(1, 2, 3), array[2]); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), array[3]); }
@Test public void group_by_null() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void group_by_null() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test public void first_set_and_list() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
@Test public void group_by_null() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(null); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); assertEquals(toInt(1), group.getOne(postId)); assertEquals("post 1", group.getOne(postName)); assertEquals(toSet(1, 2, 3), group.getSet(commentId)); assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText)); }
public AbstractVersionStoreJdbc(Options options) { this.options = options; versionAndParentColumns = without(concat(options.version.all(), GroupBy.set(options.parent.parentRevision)), options.version.revision); versionAndParents = groupBy(options.version.revision).list(versionAndParentColumns); Expression<?>[] propertyColumns = without(options.property.all(), options.property.revision); properties = groupBy(options.property.revision).as(GroupBy.list(tuple(propertyColumns))); this.cache = options.cacheBuilder.apply(this); this.cacheLoader = this.cache != null ? this.cache::load : this::getOptimizedGraph; }
@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))); } }
@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()); } }
@Test @ExcludeIn({MYSQL, DERBY}) @NoBatooJPA public void groupBy() { QAuthor author = QAuthor.author; QBook book = QBook.book; for (int i = 0; i < 10; i++) { Author a = new Author(); a.setName(String.valueOf(i)); save(a); for (int j = 0; j < 2; j++) { Book b = new Book(); b.setTitle(String.valueOf(i) + " " + String.valueOf(j)); b.setAuthor(a); save(b); } } Map<Long, List<Pair<Long, String>>> map = query() .from(author) .join(author.books, book) .transform(GroupBy .groupBy(author.id) .as(GroupBy.list(QPair.create(book.id, book.title)))); for (Entry<Long, List<Pair<Long, String>>> entry : map.entrySet()) { System.out.println("author = " + entry.getKey()); for (Pair<Long,String> pair : entry.getValue()) { System.out.println(" book = " + pair.getFirst() + "," + pair.getSecond()); } } }
@Test @ExcludeIn(DERBY) public void transform_groupBy_alias() { QCat kitten = new QCat("kitten"); SimplePath<Cat> k = Expressions.path(Cat.class, "k"); Map<Integer, Group> result = query().from(cat).innerJoin(cat.kittens, kitten) .transform(GroupBy.groupBy(cat.id) .as(cat.name, cat.id, GroupBy.list(Projections.constructor(Cat.class, kitten.name, kitten.id).as(k)))); for (Group entry : result.values()) { assertNotNull(entry.getOne(cat.id)); assertNotNull(entry.getOne(cat.name)); assertFalse(entry.getList(k).isEmpty()); } }