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.kuali.rice.core.jpa.criteria.Criteria; |
25 | |
import org.kuali.rice.core.jpa.criteria.QueryByCriteria; |
26 | |
import org.kuali.rice.core.util.OrmUtils; |
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 | OrmUtils.populateAutoIncValue(helpEntry, entityManager); |
39 | 0 | entityManager.persist(helpEntry); |
40 | |
} else { |
41 | 0 | entityManager.merge(helpEntry); |
42 | |
} |
43 | 0 | } |
44 | |
|
45 | |
public void deleteEntry(HelpEntry helpEntry) { |
46 | 0 | HelpEntry reattatched = entityManager.merge(helpEntry); |
47 | 0 | entityManager.remove(reattatched); |
48 | 0 | } |
49 | |
|
50 | |
public HelpEntry findById(Long helpId) { |
51 | 0 | return (HelpEntry) entityManager.createNamedQuery("HelpEntry.FindById").setParameter("helpId", helpId).getSingleResult(); |
52 | |
} |
53 | |
|
54 | |
public List search(HelpEntry helpEntry) { |
55 | 0 | Criteria crit = new Criteria("HelpEntry", "he"); |
56 | |
|
57 | 0 | if (helpEntry.getHelpId() != null && helpEntry.getHelpId().longValue() != 0) { |
58 | 0 | crit.eq("helpId", helpEntry.getHelpId()); |
59 | |
} |
60 | |
|
61 | 0 | if (!this.isStringEmpty(helpEntry.getHelpName())) { |
62 | 0 | crit.rawJpql("UPPER(he.helpName) like '%" + helpEntry.getHelpName().toUpperCase() + "%'"); |
63 | |
} |
64 | |
|
65 | 0 | if (!this.isStringEmpty(helpEntry.getHelpText())) { |
66 | 0 | crit.rawJpql("UPPER(he.helpText) like '%" + helpEntry.getHelpText().toUpperCase() + "%'"); |
67 | |
} |
68 | |
|
69 | 0 | if (!this.isStringEmpty(helpEntry.getHelpKey())) { |
70 | 0 | crit.rawJpql("UPPER(he.helpKey) like '%" + helpEntry.getHelpKey().toUpperCase() + "%'"); |
71 | |
} |
72 | |
|
73 | 0 | return new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
74 | |
} |
75 | |
|
76 | |
private boolean isStringEmpty(String string) { |
77 | 0 | if ((string == null) || string.trim().equals("")) { |
78 | 0 | return true; |
79 | |
} |
80 | 0 | return false; |
81 | |
} |
82 | |
|
83 | |
public HelpEntry findByKey(String helpKey){ |
84 | 0 | return (HelpEntry) entityManager.createNamedQuery("HelpEntry.FindByKey").setParameter("helpKey", helpKey).getSingleResult(); |
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 | |
|
95 | |
} |