View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.example.geomail.dao.impl;
8   
9   import org.mule.example.geomail.dao.Sender;
10  import org.mule.example.geomail.dao.SenderDao;
11  
12  import java.util.Collection;
13  
14  import javax.persistence.EntityManager;
15  import javax.persistence.PersistenceContext;
16  
17  import org.springframework.transaction.annotation.Transactional;
18  
19  @Transactional
20  public class SenderDaoImpl implements SenderDao
21  {
22      private EntityManager entityManager;
23  
24      public Collection getSenders()
25      {
26          return getEntityManager().createQuery("SELECT sender FROM Sender sender").getResultList();
27      }
28  
29      public Sender getSender(String senderId)
30      {
31          return getEntityManager().find(Sender.class, senderId);
32      }
33  
34      public void addSender(Sender sender)
35      {
36          getEntityManager().persist(sender);
37      }
38  
39      public EntityManager getEntityManager()
40      {
41          return entityManager;
42      }
43  
44      @PersistenceContext
45      public void setEntityManager(EntityManager entityManager)
46      {
47          this.entityManager = entityManager;
48      }
49  }