I am starting with this from the Web Service Rest and I have encountered the problem when doing a crud with the database.
For example, I need to search for a record but not for its PK but for another field, is it possible to do this? Could you guide me on how to do it? I searched but everything is very confusing
Help please!
This is one of the classes mapped from the Oracle DB, I'm not using frameworks, I only create them with RestFull Web Services from Database.
In this class, I need to filter by mail and password ...
package entidad.servicio;
import entidad.Usuario;
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;
import javax.ws.rs.core.MediaType;
@Stateless
@Path("entidad.usuario")
public class UsuarioFacadeREST extends AbstractFacade<Usuario> {
@PersistenceContext(unitName = "WSPU")
private EntityManager em;
public UsuarioFacadeREST() {
super(Usuario.class);
}
@POST
@Override
@Consumes(MediaType.APPLICATION_JSON)
public void create(Usuario entity) {
super.create(entity);
}
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public void edit(@PathParam("id") Short id, Usuario entity) {
super.edit(entity);
}
@DELETE
@Path("{id}")
public void remove(@PathParam("id") Short id) {
super.remove(super.find(id));
}
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Usuario find(@PathParam("id") Short id) {
return super.find(id);
}
@GET
@Override
@Produces(MediaType.APPLICATION_JSON)
public List<Usuario> findAll() {
return super.findAll();
}
@GET
@Path("{from}/{to}")
@Produces(MediaType.APPLICATION_JSON)
public List<Usuario> findRange(@PathParam("from") Integer from,
@PathParam("to") Integer to) {
return super.findRange(new int[]{from, to});
}
@GET
@Path("count")
@Produces(MediaType.TEXT_PLAIN)
public String countREST() {
return String.valueOf(super.count());
}
@Override
protected EntityManager getEntityManager() {
return em;
}
}