Define a named parameter (:status) in a named query:

import javax.persistence.*;

@Entity
@Access(AccessType.FIELD)
@Table(name = PartnerInitialLoad.TABLE_NAME)
@NamedQueries({
  @NamedQuery(
      name = FIND_PARTNER_BY_STATUS ,
      query =
          "select p from PartnerInitialLoad p where p.status = :status order by p.partnernummer asc")
})
public class PartnerInitialLoad {
  public static final String TABLE_NAME = "T_PARTNER_INITIAL_LOAD";

  public static final String FIND_MAX_PARTNERNUMMER = "findMaxPartnernummer";
  public static final String FIND_PARTNER_BY_STATUS = "findPartnerByStatus";

  public static final String PARAM_STATUS = "status"; //the value here has to match the one in jpql, here "status"

 // further entity details emitted for brevity
}

Then, set the named parameter in the created TypedQuery (em.createNamedQuery) with the setParameter method, which expects the name of the parameter (should match the one defined in the @NamedQuery) and its value:

@Stateless
public class PartnerInitialLoadRepository {

  @Inject private EntityManager em;

  public List<PartnerInitialLoad> getPartnersByStatus(Integer chunkSize, String status) {
    var query =
        em.createNamedQuery(PartnerInitialLoad.FIND_UNPROCESSED_PARTNER, PartnerInitialLoad.class);
    query.setParameter(PartnerInitialLoad.PARAM_STATUS, status);
    query.setMaxResults(chunkSize);

    return query.getResultList();
  }
}

Same principle applies, if we create a collection-valued named parameters, to generate for example a SELECT IN clause sql as in the following snippet:

  public List<PartnerInitialLoad> getPartnersWithStatusInList(Integer chunkSize, List<String> statusList) {
   String sql="select p from PartnerInitialLoad p where p.status IN (:statusList) order by p.partnernummer asc"
    var query =
        em.createQuery(sql, PartnerInitialLoad.class);
    query.setParameter("statusList", status);
    query.setMaxResults(chunkSize);

    return query.getResultList();
  }

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Use created(URI location) of the javax.ws.rs.core.Response class. Usually when you return the 201 HTTP Status Code, you should return a location header with the location where the new REST resource is available.

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.*;

@Path("messages")
@Stateless
@Tag(name = "Message")
public class MessageRestResource {

  @Inject private MessageService messageService;

  @POST
  @Consumes(MediaType.TEXT_PLAIN)
  @Operation(summary = "Create message")
  @ApiResponses({
    @ApiResponse(
        responseCode = "201",
        description = "Message successfully created."),
    @ApiResponse(responseCode = "403", description = "Forbidden")
  })
  public Response createMessage(
      @Parameter(description = "Message") String message, @Context UriInfo uriInfo)
      throws JAXBException {
    Message created = messageService.createMessage(message);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    builder.path(created.getUuid().toString());
    return Response.created(builder.build()).build();
  }

In the snippet the UriBuilder method builder.path(created.getUuid().toString()) appends the identifier of the newly created message (uuid) to the absolute path of the request, which was obtained from the uriInfo


Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Use the ok() method of the javax.ws.rs.core.Reponse class to create a ReponseBuilder with a status of 200 (OK), or the ok(Object entity) to return OK with data

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("comparison")
@Stateless
@Tag(name = "Comparison")
public class ComparisonRestResource {

  @Inject private ComparisonService comparisonService;

  @HEAD
  @Operation(
      summary = "Ping HEAD",
      description = "Check availability of the resource. ")
  @ApiResponses(@ApiResponse(responseCode = "200", description = "Service is reachable via HTTP"))
  public Response head() {
    return Response.ok().build();
  }

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  @Operation(
      summary = "Ping GET",
      description = "Check availability of the example resource. ")
  @ApiResponses(@ApiResponse(responseCode = "200", description = "Service is reachable via HTTP"))
  public Response ping() {
    return Response.ok("pong").build();
  }
}

Note that the ok() methods shown before are just shortcuts for

return Response
        .status(Response.Status.OK)
        .build()

and

return Response
        .status(Response.Status.OK)
        .entity("pong")
        .build()

respectively.


Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

If you don’t know exactly the deployment name in the current context you can use the following command to list all deployments:

kubectl get deploy

You should get a list of deployments similar to the following:

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
pdv-location-batch-test                    0/1     1            0           2m12s
connector-partner-service                  1/1     1            1           330d

The use kubectl delete deploy <deployment name> to delete the deployment , in our case pdv-location-batch-test

kubectl delete deploy pdv-location-batch-test

You should get something similar to the following:

deployment.apps "pdv-lokation-batch-test" deleted

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Use the $ sign to define the variable $variable_name: variable_value. Below we define anthracite-gray colour in the _colors.scss file used in the Codever project. Then we reference the variable in the class definition:

$anthracite-gray: #4A5054;

.anthracite-gray {
  color: $anthracite-gray;
}

Reference - https://sass-lang.com/documentation/variables


Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏