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