View Javadoc
1   package ejava.projects.eleague.jpa;
2   
3   import java.util.List;
4   
5   import javax.persistence.EntityManager;
6   
7   import ejava.projects.eleague.bo.Venue;
8   import ejava.projects.eleague.dao.ClubDAO;
9   import ejava.projects.eleague.dao.ClubDAOException;
10  
11  /**
12   * This class provides a sparse example of a JPA DAO for the class project.
13   * It is put in place here to demonstrate some of the end-to-end use cases,
14   */
15  public class JPAClubDAO implements ClubDAO {
16  	private EntityManager em;
17  	
18  	/**
19  	 * This method injects an entity manager to be used by all DAO methods.
20  	 * @param em
21  	 */
22  	public void setEntityManager(EntityManager em) {
23  		this.em = em;
24  	}
25  
26  	@Override
27  	public void createVenue(Venue venue) {
28          em.persist(venue);
29  	}
30  
31  	@Override
32      public List<Venue> getVenues(int index, int count) 
33          throws ClubDAOException {
34  	    return em.createQuery("select v from Venue v", Venue.class)
35  	                             .setFirstResult(index)
36  	                             .setMaxResults(count)
37  	                             .getResultList();
38  	}
39  }