1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actionlist.dao.impl;
17
18 import org.kuali.rice.kew.actionlist.dao.ActionListDAO;
19 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
20
21 import javax.persistence.EntityGraph;
22 import javax.persistence.EntityManager;
23 import javax.persistence.TypedQuery;
24 import java.util.Arrays;
25 import java.util.List;
26
27
28
29
30
31
32 public class ActionListDAOJpaImpl implements ActionListDAO {
33
34 protected EntityManager entityManager;
35
36 public void setEntityManager(EntityManager entityManager) {
37 this.entityManager = entityManager;
38 }
39
40
41
42
43 @Override
44 public int getCount(String principalId) {
45 TypedQuery<Long> query = entityManager.createNamedQuery("ActionItem.DistinctDocumentsForPrincipalId",Long.class);
46 query.setParameter("principalId",principalId);
47 return query.getSingleResult().intValue();
48 }
49
50
51
52
53 @Override
54 public List<Object> getMaxActionItemDateAssignedAndCountForUser(String principalId) {
55 TypedQuery<Object[]> query = (TypedQuery<Object[]>) entityManager.createNamedQuery("ActionItem.GetMaxDateAndCountForPrincipalId", (new Object[0]).getClass() );
56 query.setParameter("principalId",principalId);
57 return Arrays.asList( query.getSingleResult() );
58 }
59
60
61
62
63 @Override
64 public DocumentRouteHeaderValue getMinimalRouteHeader(String documentId) {
65
66 EntityGraph<DocumentRouteHeaderValue> entityGraph =
67 (EntityGraph<DocumentRouteHeaderValue>) entityManager.createEntityGraph("DocumentRouteHeaderValue.ActionListAttributesOnly");
68 TypedQuery<DocumentRouteHeaderValue> query = entityManager.createQuery("SELECT rh FROM DocumentRouteHeaderValue rh WHERE rh.documentId = :documentId", DocumentRouteHeaderValue.class );
69
70
71
72 query.setHint("javax.persistence.fetchgraph", entityGraph);
73 query.setParameter("documentId", documentId);
74 List<DocumentRouteHeaderValue> result = query.getResultList();
75 if ( result.isEmpty() ) {
76 return null;
77 }
78 return result.get(0);
79 }
80
81 }