Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @GET
- @Path("/{id:[0-9][0-9]*}")
- @Produces("application/json")
- public Response findById(@PathParam("id") Long id, @Context Request request) {
- TypedQuery<User> findByIdQuery = em
- .createQuery(
- "SELECT DISTINCT u FROM User u WHERE u.id = :entityId ORDER BY u.id",
- User.class);
- findByIdQuery.setParameter("entityId", id);
- User entity;
- try {
- entity = findByIdQuery.getSingleResult();
- } catch (NoResultException nre) {
- entity = null;
- }
- CacheControl cacheControl = new CacheControl();
- cacheControl.setMaxAge(86400);
- EntityTag etag = new EntityTag(Integer.toString(entity.hashCode()));
- ResponseBuilder builder = request.evaluatePreconditions(etag);
- if (builder == null) {
- builder = Response.ok(entity);
- builder.tag(etag);
- }
- builder.cacheControl(cacheControl);
- return builder.build();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement