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.framework.persistence.platform.DatabasePlatform; |
27 | |
import org.kuali.rice.core.api.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 | 0 | public class UserOptionsDaoJpaImpl implements UserOptionsDAO { |
34 | |
|
35 | |
@PersistenceContext |
36 | |
private EntityManager entityManager; |
37 | |
|
38 | |
public Long getNewOptionIdForActionList() { |
39 | 0 | return getPlatform().getNextValSQL("KREW_ACTN_LIST_OPTN_S", entityManager); |
40 | |
} |
41 | |
|
42 | |
protected DatabasePlatform getPlatform() { |
43 | 0 | return (DatabasePlatform) GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM); |
44 | |
} |
45 | |
|
46 | |
public List findByUserQualified(String principalId, String likeString) { |
47 | 0 | 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 | 0 | List<UserOptions> userOptions = (List<UserOptions>) entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList(); |
52 | 0 | for (UserOptions uo : userOptions) { |
53 | 0 | entityManager.remove(uo); |
54 | |
} |
55 | 0 | } |
56 | |
|
57 | |
public Collection findByWorkflowUser(String principalId) { |
58 | 0 | return entityManager.createNamedQuery("UserOptions.FindByWorkflowId").setParameter("workflowId", principalId).getResultList(); |
59 | |
} |
60 | |
|
61 | |
public void save(UserOptions userOptions) { |
62 | 0 | if (userOptions.getOptionId() == null) { |
63 | 0 | entityManager.persist(userOptions); |
64 | |
} else { |
65 | 0 | entityManager.merge(userOptions); |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
public void save(Collection<UserOptions> userOptions) { |
70 | 0 | if (userOptions != null) for (UserOptions option : userOptions) { |
71 | 0 | save(option); |
72 | |
} |
73 | 0 | } |
74 | |
|
75 | |
public void deleteUserOptions(UserOptions userOptions) { |
76 | 0 | UserOptions reattatched = entityManager.merge(userOptions); |
77 | 0 | entityManager.remove(reattatched); |
78 | 0 | } |
79 | |
|
80 | |
public UserOptions findByOptionId(String optionId, String principalId) { |
81 | 0 | return (UserOptions) entityManager.createNamedQuery("UserOptions.FindByOptionId").setParameter("optionId", optionId).setParameter("workflowId", principalId).getSingleResult(); |
82 | |
} |
83 | |
|
84 | |
public Collection findByOptionValue(String optionId, String optionValue) { |
85 | 0 | return entityManager.createNamedQuery("UserOptions.FindByOptionValue").setParameter("optionId", optionId).setParameter("optionValue", optionValue).getResultList(); |
86 | |
} |
87 | |
|
88 | |
public EntityManager getEntityManager() { |
89 | 0 | return this.entityManager; |
90 | |
} |
91 | |
|
92 | |
public void setEntityManager(EntityManager entityManager) { |
93 | 0 | this.entityManager = entityManager; |
94 | 0 | } |
95 | |
} |