1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.dao.impl; |
17 |
|
|
18 |
|
import java.util.List; |
19 |
|
|
20 |
|
import javax.persistence.EntityManager; |
21 |
|
import javax.persistence.Query; |
22 |
|
|
23 |
|
import org.kuali.student.common.dao.CrudDao; |
24 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
25 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 10 |
Complexity Density: 0.53 |
|
26 |
|
public abstract class AbstractCrudDaoImpl implements CrudDao { |
27 |
|
|
28 |
|
protected EntityManager em; |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
30 |
0
|
public EntityManager getEm() {... |
31 |
0
|
return em; |
32 |
|
} |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0
|
public void setEm(EntityManager em) {... |
35 |
0
|
this.em = em; |
36 |
|
} |
37 |
|
|
38 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
39 |
0
|
@Override... |
40 |
|
public <T> T fetch(Class<T> clazz, String key) throws DoesNotExistException { |
41 |
0
|
T entity = em.find(clazz, key); |
42 |
0
|
if (entity == null) { |
43 |
0
|
throw new DoesNotExistException("No entity for key '" + key + "' found for " + clazz); |
44 |
|
} |
45 |
0
|
return entity; |
46 |
|
} |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
48 |
0
|
@SuppressWarnings("unchecked")... |
49 |
|
@Override |
50 |
|
public <T> List<T> find(Class<T> clazz){ |
51 |
|
|
52 |
0
|
String className = clazz.getSimpleName(); |
53 |
|
|
54 |
0
|
Query q = em.createQuery("SELECT x FROM "+className+" x"); |
55 |
0
|
return (List<T>) q.getResultList(); |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
58 |
0
|
@Override... |
59 |
|
public <T> T create(T entity) { |
60 |
0
|
em.persist(entity); |
61 |
0
|
return entity; |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
64 |
0
|
@Override... |
65 |
|
public <T> void delete(Class<T> clazz, String key) throws DoesNotExistException { |
66 |
0
|
T entity = em.find(clazz, key); |
67 |
0
|
if (entity == null) { |
68 |
0
|
throw new DoesNotExistException("No such key '" + key + "' for " + clazz); |
69 |
|
} |
70 |
0
|
em.remove(entity); |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0
|
@Override... |
74 |
|
public void delete(Object entity) { |
75 |
0
|
em.remove(entity); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
78 |
0
|
@Override... |
79 |
|
public <T> T update(T entity) { |
80 |
0
|
T updated = em.merge(entity); |
81 |
|
|
82 |
0
|
em.flush(); |
83 |
0
|
return updated; |
84 |
|
} |
85 |
|
} |