-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersFacadeREST.java
More file actions
89 lines (77 loc) · 2.04 KB
/
UsersFacadeREST.java
File metadata and controls
89 lines (77 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.javaee7.chapter08.service;
import java.math.BigDecimal;
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 org.javaee7.entity.Users;
/**
*
* @author Juneau
*/
@Stateless
@Path("org.javaee7.entity.users")
public class UsersFacadeREST extends AbstractFacade<Users> {
@PersistenceContext(unitName = "IntroToJavaEE7PU")
private EntityManager em;
public UsersFacadeREST() {
super(Users.class);
}
@POST
@Override
@Consumes({"application/xml", "application/json"})
public void create(Users entity) {
super.create(entity);
}
@PUT
@Override
@Consumes({"application/xml", "application/json"})
public void edit(Users entity) {
super.edit(entity);
}
@DELETE
@Path("{id}")
public void remove(@PathParam("id") BigDecimal id) {
super.remove(super.find(id));
}
@GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public Users find(@PathParam("id") BigDecimal id) {
return super.find(id);
}
@GET
@Override
@Produces({"application/xml", "application/json"})
public List<Users> findAll() {
return super.findAll();
}
@GET
@Path("{from}/{to}")
@Produces({"application/xml", "application/json"})
public List<Users> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
return super.findRange(new int[]{from, to});
}
@GET
@Path("count")
@Produces("text/plain")
public String countREST() {
return String.valueOf(super.count());
}
@Override
protected EntityManager getEntityManager() {
return em;
}
}