1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.help.dao.impl; |
18 | |
|
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.persistence.EntityManager; |
22 | |
import javax.persistence.PersistenceContext; |
23 | |
|
24 | |
import org.apache.commons.lang.StringUtils; |
25 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
26 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
27 | |
import org.kuali.rice.kew.help.HelpEntry; |
28 | |
import org.kuali.rice.kew.help.dao.HelpDAO; |
29 | |
|
30 | |
|
31 | 0 | public class HelpDaoJpaImpl implements HelpDAO { |
32 | |
|
33 | |
@PersistenceContext(unitName="kew-unit") |
34 | |
private EntityManager entityManager; |
35 | |
|
36 | |
public void save(HelpEntry helpEntry) { |
37 | 0 | if (helpEntry.getHelpId() == null) { |
38 | 0 | entityManager.persist(helpEntry); |
39 | |
} else { |
40 | 0 | entityManager.merge(helpEntry); |
41 | |
} |
42 | 0 | } |
43 | |
|
44 | |
public void deleteEntry(HelpEntry helpEntry) { |
45 | 0 | HelpEntry reattatched = entityManager.merge(helpEntry); |
46 | 0 | entityManager.remove(reattatched); |
47 | 0 | } |
48 | |
|
49 | |
public HelpEntry findById(String helpId) { |
50 | 0 | return (HelpEntry) entityManager.createNamedQuery("HelpEntry.FindById").setParameter("helpId", helpId).getSingleResult(); |
51 | |
} |
52 | |
|
53 | |
public List search(HelpEntry helpEntry) { |
54 | 0 | Criteria crit = new Criteria("HelpEntry", "he"); |
55 | |
|
56 | 0 | if (helpEntry.getHelpId() != null && !StringUtils.equals(helpEntry.getHelpId(),"0")) { |
57 | 0 | crit.eq("helpId", helpEntry.getHelpId()); |
58 | |
} |
59 | |
|
60 | 0 | if (!this.isStringEmpty(helpEntry.getHelpName())) { |
61 | 0 | crit.rawJpql("UPPER(he.helpName) like '%" + helpEntry.getHelpName().toUpperCase() + "%'"); |
62 | |
} |
63 | |
|
64 | 0 | if (!this.isStringEmpty(helpEntry.getHelpText())) { |
65 | 0 | crit.rawJpql("UPPER(he.helpText) like '%" + helpEntry.getHelpText().toUpperCase() + "%'"); |
66 | |
} |
67 | |
|
68 | 0 | if (!this.isStringEmpty(helpEntry.getHelpKey())) { |
69 | 0 | crit.rawJpql("UPPER(he.helpKey) like '%" + helpEntry.getHelpKey().toUpperCase() + "%'"); |
70 | |
} |
71 | |
|
72 | 0 | return new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
73 | |
} |
74 | |
|
75 | |
private boolean isStringEmpty(String string) { |
76 | 0 | if ((string == null) || string.trim().equals("")) { |
77 | 0 | return true; |
78 | |
} |
79 | 0 | return false; |
80 | |
} |
81 | |
|
82 | |
public HelpEntry findByKey(String helpKey){ |
83 | 0 | return (HelpEntry) entityManager.createNamedQuery("HelpEntry.FindByKey").setParameter("helpKey", helpKey).getSingleResult(); |
84 | |
} |
85 | |
|
86 | |
public EntityManager getEntityManager() { |
87 | 0 | return this.entityManager; |
88 | |
} |
89 | |
|
90 | |
public void setEntityManager(EntityManager entityManager) { |
91 | 0 | this.entityManager = entityManager; |
92 | 0 | } |
93 | |
|
94 | |
} |