Java Reference
In-Depth Information
As we mentioned earlier, the wizard generates a facade for each generated JPA
entity. In this example, we picked a single table ( CUSTOMER ); therefore, a JPA entity
was created for this table (along with two related tables). The Facade class for the
Customer JPA entity is called CustomerFacadeREST . The code is as follows:
package com.ensode.netbeansbook.jaxrs.service;
import com.ensode.netbeansbook.jaxrs.Customer;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@Stateless
@Path("com.ensode.netbeansbook.jaxrs.customer")
public class CustomerFacadeREST extends AbstractFacade<Customer> {
@PersistenceContext(unitName = "jaxrxPU")
private EntityManager em;
public CustomerFacadeREST() {
super(Customer.class);
}
@POST
@Override
@Consumes({"application/xml", "application/json"})
public void create(Customer entity) {
super.create(entity);
}
@PUT
@Path("{id}")
@Consumes({"application/xml", "application/json"})
public void edit(@PathParam("id") Integer id, Customer entity) {
super.edit(entity);
}
 
Search WWH ::




Custom Search