1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.useroptions.dao.impl;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22
23 import javax.persistence.EntityManager;
24 import javax.persistence.PersistenceContext;
25
26 import org.kuali.rice.core.database.platform.DatabasePlatform;
27 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
28 import org.kuali.rice.core.util.RiceConstants;
29 import org.kuali.rice.kew.useroptions.UserOptions;
30 import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO;
31
32
33 public class UserOptionsDaoJpaImpl implements UserOptionsDAO {
34
35 @PersistenceContext
36 private EntityManager entityManager;
37
38 public Long getNewOptionIdForActionList() {
39 return getPlatform().getNextValSQL("KREW_ACTN_LIST_OPTN_S", entityManager);
40 }
41
42 protected DatabasePlatform getPlatform() {
43 return (DatabasePlatform) GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
44 }
45
46 public List findByUserQualified(String principalId, String likeString) {
47 return new ArrayList(entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList());
48 }
49
50 public void deleteByUserQualified(String principalId, String likeString) {
51 List<UserOptions> userOptions = (List<UserOptions>) entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList();
52 for (UserOptions uo : userOptions) {
53 entityManager.remove(uo);
54 }
55 }
56
57 public Collection findByWorkflowUser(String principalId) {
58 return entityManager.createNamedQuery("UserOptions.FindByWorkflowId").setParameter("workflowId", principalId).getResultList();
59 }
60
61 public void save(UserOptions userOptions) {
62 if (userOptions.getOptionId() == null) {
63 entityManager.persist(userOptions);
64 } else {
65 entityManager.merge(userOptions);
66 }
67 }
68
69 public void save(Collection<UserOptions> userOptions) {
70 if (userOptions != null) for (UserOptions option : userOptions) {
71 save(option);
72 }
73 }
74
75 public void deleteUserOptions(UserOptions userOptions) {
76 UserOptions reattatched = entityManager.merge(userOptions);
77 entityManager.remove(reattatched);
78 }
79
80 public UserOptions findByOptionId(String optionId, String principalId) {
81 return (UserOptions) entityManager.createNamedQuery("UserOptions.FindByOptionId").setParameter("optionId", optionId).setParameter("workflowId", principalId).getSingleResult();
82 }
83
84 public Collection findByOptionValue(String optionId, String optionValue) {
85 return entityManager.createNamedQuery("UserOptions.FindByOptionValue").setParameter("optionId", optionId).setParameter("optionValue", optionValue).getResultList();
86 }
87
88 public EntityManager getEntityManager() {
89 return this.entityManager;
90 }
91
92 public void setEntityManager(EntityManager entityManager) {
93 this.entityManager = entityManager;
94 }
95 }