1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.bam.dao.impl;
17
18 import org.kuali.rice.core.api.reflect.ObjectDefinition;
19 import org.kuali.rice.ksb.messaging.bam.BAMTargetEntry;
20 import org.kuali.rice.ksb.messaging.bam.dao.BAMDAO;
21
22 import javax.persistence.EntityManager;
23 import javax.persistence.PersistenceContext;
24 import javax.xml.namespace.QName;
25 import java.util.List;
26
27
28 public class BAMDaoJpaImpl implements BAMDAO {
29
30 private EntityManager entityManager;
31
32 @PersistenceContext
33 public void setEntityManager(EntityManager entityManager) {
34 this.entityManager = entityManager;
35 }
36
37 public void clearBAMTables() {
38 entityManager.createQuery("delete from BAMTargetEntry").executeUpdate();
39 entityManager.createQuery("delete from BAMParam").executeUpdate();
40 }
41
42 public List<BAMTargetEntry> getCallsForService(QName serviceName, String methodName) {
43 return (List<BAMTargetEntry>) entityManager.createQuery("select bte from BAMTargetEntry bte where bte.serviceName = :serviceName and bte.methodName = :methodName").setParameter("serviceName", serviceName.toString()).setParameter("methodName", methodName).getResultList();
44 }
45
46 public void save(BAMTargetEntry bamEntry) {
47 if(bamEntry.getBamId() == null) {
48 entityManager.persist(bamEntry);
49 }
50 else {
51 entityManager.merge(bamEntry);
52 }
53 }
54
55 public List<BAMTargetEntry> getCallsForService(QName serviceName) {
56 return (List<BAMTargetEntry>) entityManager.createQuery("select bte from BAMTargetEntry bte where bte.serviceName = :serviceName").setParameter("serviceName", serviceName.toString()).getResultList();
57 }
58
59 public List<BAMTargetEntry> getCallsForRemotedClasses(ObjectDefinition objDef) {
60 QName qname = new QName(objDef.getApplicationId(), objDef.getClassName());
61 return (List<BAMTargetEntry>) entityManager.createQuery("select bte from BAMTargetEntry bte where bte.serviceName like :serviceName%").setParameter("serviceName", qname.toString()).getResultList();
62 }
63
64 public List<BAMTargetEntry> getCallsForRemotedClasses(ObjectDefinition objDef, String methodName) {
65 QName qname = new QName(objDef.getApplicationId(), objDef.getClassName());
66 return (List<BAMTargetEntry>) entityManager.createQuery("select bte from BAMTargetEntry bte where bte.serviceName like :serviceName% and bte.methodName = :methodName").setParameter("serviceName", qname.toString()).setParameter("methodName", methodName).getResultList();
67 }
68
69 }