1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actiontaken.dao.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kew.actiontaken.dao.ActionTakenDao;
20 import org.kuali.rice.kew.api.action.ActionType;
21
22 import javax.persistence.EntityManager;
23 import javax.persistence.NoResultException;
24 import javax.persistence.TypedQuery;
25 import java.sql.Timestamp;
26
27
28
29
30
31
32
33 public class ActionTakenDaoJpa implements ActionTakenDao {
34
35 private EntityManager entityManager;
36
37 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenDaoJpa.class);
38
39 public static final String GET_LAST_ACTION_TAKEN_DATE_NAME = "ActionTakenValue.getLastActionTakenDate";
40 public static final String GET_LAST_ACTION_TAKEN_DATE_QUERY =
41 "SELECT max(a.actionDate) from ActionTakenValue a where a.documentId = :documentId and a.actionTaken=:actionTaken";
42
43 public Timestamp getLastActionTakenDate(String documentId, ActionType actionType) {
44 if (StringUtils.isBlank(documentId) || actionType == null) {
45 throw new IllegalArgumentException("Both documentId and actionType must be non-null");
46 }
47 TypedQuery<Timestamp> query =
48 entityManager.createNamedQuery(GET_LAST_ACTION_TAKEN_DATE_NAME, Timestamp.class);
49 query.setParameter("documentId", documentId);
50 query.setParameter("actionTaken", actionType.getCode());
51 try {
52 return query.getSingleResult();
53 } catch (NoResultException e) {
54 return null;
55 }
56 }
57
58 public EntityManager getEntityManager() {
59 return this.entityManager;
60 }
61
62 public void setEntityManager(EntityManager entityManager) {
63 this.entityManager = entityManager;
64 }
65
66 }