Class UpdateMethodImplementor

java.lang.Object
io.quarkus.rest.data.panache.deployment.methods.StandardMethodImplementor
io.quarkus.rest.data.panache.deployment.methods.UpdateMethodImplementor
All Implemented Interfaces:
MethodImplementor

public final class UpdateMethodImplementor extends StandardMethodImplementor
  • Constructor Details

    • UpdateMethodImplementor

      public UpdateMethodImplementor(io.quarkus.deployment.Capabilities capabilities)
  • Method Details

    • implementInternal

      protected void implementInternal(io.quarkus.gizmo.ClassCreator classCreator, ResourceMetadata resourceMetadata, ResourceProperties resourceProperties, io.quarkus.gizmo.FieldDescriptor resourceField)
      Generate JAX-RS UPDATE method. The RESTEasy Classic version exposes RestDataResource.update(Object, Object). Expose RestDataResource.update(Object, Object) via JAX-RS method. Generated code looks more or less like this:
       
           @PUT
           @Path("{id}")
           @Consumes({"application/json"})
           @Produces({"application/json"})
           @LinkResource(
               rel = "update",
               entityClassName = "com.example.Entity"
           )
           public Response update(@PathParam("id") ID id, Entity entityToSave) {
               try {
                   Object newEntity = updateExecutor.execute(() -> {
                       if (resource.get(id) == null) {
                           return resource.update(id, entityToSave);
                       } else {
                           resource.update(id, entityToSave);
                           return null;
                       }
                   });
      
                   if (newEntity == null) {
                       return Response.status(204).build();
                   } else {
                       String location = new ResourceLinksProvider().getSelfLink(newEntity);
                       if (location != null) {
                           ResponseBuilder responseBuilder = Response.status(201);
                           responseBuilder.entity(newEntity);
                           responseBuilder.location(URI.create(location));
                           return responseBuilder.build();
                       } else {
                           throw new RuntimeException("Could not extract a new entity URL")
                       }
                   }
               } catch (Throwable t) {
                   throw new RestDataPanacheException(t);
               }
           }
       
       
      The RESTEasy Reactive version exposes ReactiveRestDataResource.update(Object, Object).
       
           @PUT
           @Path("{id}")
           @Consumes({"application/json"})
           @Produces({"application/json"})
           @LinkResource(
               rel = "update",
               entityClassName = "com.example.Entity"
           )
           public Uni<Response> update(@PathParam("id") ID id, Entity entityToSave) {
               return resource.get(id).flatMap(entity -> {
                   if (entity == null) {
                       return Uni.createFrom().item(Response.status(204).build());
                   } else {
                       return resource.update(id, entityToSave).map(savedEntity -> {
                           String location = new ResourceLinksProvider().getSelfLink(savedEntity);
                           if (location != null) {
                               ResponseBuilder responseBuilder = Response.status(201);
                               responseBuilder.entity(savedEntity);
                               responseBuilder.location(URI.create(location));
                               return responseBuilder.build();
                           } else {
                               throw new RuntimeException("Could not extract a new entity URL")
                           }
                       });
                   }
               }).onFailure().invoke(t -> throw new RestDataPanacheException(t));
           }
       
       
      Specified by:
      implementInternal in class StandardMethodImplementor
    • getResourceMethodName

      protected String getResourceMethodName()
      Description copied from class: StandardMethodImplementor
      Get a name of a method which this controller uses to access data.
      Specified by:
      getResourceMethodName in class StandardMethodImplementor