AccessRightFacade.java
1.88 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
package fi.insomnia.bortal.facade;
import fi.insomnia.bortal.enums.Permission;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import fi.insomnia.bortal.model.AccessRight;
import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.Role;
@Stateless
@LocalBean
public class AccessRightFacade extends IntegerPkGenericFacade<AccessRight> {
@PersistenceContext
private EntityManager em;
public AccessRightFacade() {
super(AccessRight.class);
}
protected EntityManager getEm() {
return em;
}
/*
* public AccessRight findOrCreateByName(String target) {
*
* // Fetch access right by name TypedQuery<AccessRight> q =
* em.createQuery("SELECT a FROM AccessRight a WHERE a.name = :name",
* AccessRight.class); q.setParameter("name", target); AccessRight right =
* null; right = this.getSingleNullableResult(q);
*
* // Might not exist yet -> create if (right == null) { right = new
* AccessRight(); right.setName(target); em.persist(right); }
*
* return right; }
*/
public AccessRight findByPermission(Permission target) {
// Fetch access right by name
TypedQuery<AccessRight> q = em.createNamedQuery("AccessRight.findByName", AccessRight.class);
q.setParameter("name", target.name());
AccessRight right = null;
right = this.getSingleNullableResult(q);
if (right == null) {
right = new AccessRight(target.name());
right.setDescription(target.getDescription());
create(right);
}
return right;
}
public void find(LanEvent e, Role r) {
throw new NotImplementedException();
}
}