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