Matthias Andreas Benkard | 0c009e8 | 2021-02-26 07:23:27 +0100 | [diff] [blame^] | 1 | package eu.mulk.demos.blog; |
| 2 | |
| 3 | import java.util.List; |
| 4 | import javax.transaction.Transactional; |
| 5 | import javax.ws.rs.GET; |
| 6 | import javax.ws.rs.Path; |
| 7 | import javax.ws.rs.Produces; |
| 8 | import javax.ws.rs.core.MediaType; |
| 9 | |
| 10 | @Path("/posts") |
| 11 | public class PostResource { |
| 12 | |
| 13 | @GET |
| 14 | @Produces(MediaType.TEXT_PLAIN) |
| 15 | @Transactional |
| 16 | public List<Post> getAll() { |
| 17 | return Post.findAll().list(); |
| 18 | } |
| 19 | |
| 20 | @GET |
| 21 | @Produces(MediaType.TEXT_PLAIN) |
| 22 | @Transactional |
| 23 | @Path("/q1") |
| 24 | public List<Post> getAllWithComments() { |
| 25 | return Post.find(""" |
| 26 | SELECT p FROM Post p |
| 27 | LEFT JOIN FETCH p.comments |
| 28 | """).list(); |
| 29 | } |
| 30 | |
| 31 | @GET |
| 32 | @Produces(MediaType.TEXT_PLAIN) |
| 33 | @Transactional |
| 34 | @Path("/q2") |
| 35 | public List<Post> getAllWithCommentsAndCategories() { |
| 36 | return Post.find(""" |
| 37 | SELECT p FROM Post p |
| 38 | LEFT JOIN FETCH p.comments |
| 39 | LEFT JOIN FETCH p.categories |
| 40 | """).list(); |
| 41 | } |
| 42 | |
| 43 | } |