View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }