/** * Create an alias for the expression * * @return this as alias */ public Expression<T> as(String alias) { return as(ExpressionUtils.path(getType(), alias)); }
@Test public void oneToOneToMany_projection_as_bean() { List<User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).list(Projections.bean(User.class, userName, Projections.bean(Post.class, postId, postName, set(qComment).as("comments")).as("latestPost")))); assertEquals(2, results.size()); User user = results.get(0); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void oneToOneToMany_projection_as_bean() { Map<String, User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).as(Projections.bean(User.class, userName, Projections.bean(Post.class, postId, postName, set(qComment).as("comments")).as("latestPost")))); assertEquals(2, results.size()); User user = results.get("Jane"); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Test public void oneToOneToMany_projection_as_bean() { CloseableIterator<User> resultsIt = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).iterate(Projections.bean(User.class, userName, Projections.bean(Post.class, postId, postName, set(qComment).as("comments")).as("latestPost")))); List<User> results = IteratorAdapter.asList(resultsIt); assertEquals(2, results.size()); User user = results.get(0); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
/** * Create an alias for the expression * * @return this as alias */ public Expression<T> as(String alias) { return as(ExpressionUtils.path(getType(), alias)); }