use of org.baeldung.querydsl.intro.entities.QBlogPost in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenGroupingByTitle_thenReturnsTuples.
@Test
public void whenGroupingByTitle_thenReturnsTuples() {
QBlogPost blogPost = QBlogPost.blogPost;
NumberPath<Long> count = Expressions.numberPath(Long.class, "c");
List<Tuple> userTitleCounts = queryFactory.select(blogPost.title, blogPost.id.count().as(count)).from(blogPost).groupBy(blogPost.title).orderBy(count.desc()).fetch();
assertEquals("Hello World!", userTitleCounts.get(0).get(blogPost.title));
assertEquals(new Long(2), userTitleCounts.get(0).get(count));
assertEquals("My Second Post", userTitleCounts.get(1).get(blogPost.title));
assertEquals(new Long(1), userTitleCounts.get(1).get(count));
}
use of org.baeldung.querydsl.intro.entities.QBlogPost in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenJoiningWithCondition_thenResultCountShouldMatch.
@Test
public void whenJoiningWithCondition_thenResultCountShouldMatch() {
QUser user = QUser.user;
QBlogPost blogPost = QBlogPost.blogPost;
List<User> users = queryFactory.selectFrom(user).innerJoin(user.blogPosts, blogPost).on(blogPost.title.eq("Hello World!")).fetch();
assertEquals(2, users.size());
}
use of org.baeldung.querydsl.intro.entities.QBlogPost in project tutorials by eugenp.
the class QueryDSLIntegrationTest method whenRefiningWithSubquery_thenResultCountShouldMatch.
@Test
public void whenRefiningWithSubquery_thenResultCountShouldMatch() {
QUser user = QUser.user;
QBlogPost blogPost = QBlogPost.blogPost;
List<User> users = queryFactory.selectFrom(user).where(user.id.in(JPAExpressions.select(blogPost.user.id).from(blogPost).where(blogPost.title.eq("Hello World!")))).fetch();
assertEquals(2, users.size());
}