View Javadoc
1   package ejava.projects.edmv.jpa;
2   
3   import java.util.List;
4   
5   import javax.persistence.EntityManager;
6   
7   import ejava.projects.edmv.bo.Person;
8   import ejava.projects.edmv.dao.PersonDAO;
9   
10  /**
11   * This class provides a _sparse_ example of a JPA DAO for the class project.
12   * It is put in place here to demonstrate some of the end-to-end use cases,
13   *
14   */
15  public class JPAPersonDAO implements PersonDAO {
16  	private EntityManager em;
17  	
18  	public void setEntityManager(EntityManager em) {
19  		this.em = em;
20  	}
21  
22  	public void createPerson(Person person) {
23          em.persist(person);
24  	}
25  	
26  	public Person getPerson(long id) {
27  	    return em.find(Person.class, id);
28  	}
29  
30  	@SuppressWarnings("unchecked")
31      public List<Person> getPeople(int index, int count)  {
32  	    return (List<Person>)em.createQuery("select p from Person p")
33  	                             .setFirstResult(index)
34  	                             .setMaxResults(count)
35  	                             .getResultList();
36  	}
37  }