View Javadoc
1   package ejava.projects.esales.jpa;
2   
3   import java.util.List;
4   
5   import javax.persistence.EntityManager;
6   
7   import ejava.projects.esales.bo.Account;
8   import ejava.projects.esales.dao.AccountDAO;
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 JPAAccountDAO implements AccountDAO {
16  	private EntityManager em;
17  	
18  	public void setEntityManager(EntityManager em) {
19  		this.em = em;
20  	}
21  
22  	public void createAccount(Account account) {
23          em.persist(account);
24  	}
25  
26  	@SuppressWarnings("unchecked")
27  	public List<Account> getAccounts(int index, int count) {
28  	    return (List<Account>)em.createQuery("select a from Account a")
29  	                             .setFirstResult(index)
30  	                             .setMaxResults(count)
31  	                             .getResultList();
32  	}
33  }