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.VehicleRegistration;
8   import ejava.projects.edmv.dao.VehicleDAO;
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 JPAVehicleDAO implements VehicleDAO {
16  	private EntityManager em;
17  	
18  	public void setEntityManager(EntityManager em) {
19  		this.em = em;
20  	}
21  
22  	public void createRegistration(VehicleRegistration registration) {
23          em.persist(registration);
24  	}
25  
26  	@SuppressWarnings("unchecked")
27      public List<VehicleRegistration> getRegistrations(int index, int count)  {
28  	    return (List<VehicleRegistration>)
29  	        em.createQuery("select vr from VehicleRegistration vr")
30  	                             .setFirstResult(index)
31  	                             .setMaxResults(count)
32  	                             .getResultList();
33  	}
34  }