daily pastebin goal
10%
SHARE
TWEET

bookDAO

a guest May 31st, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package wipb.jee.clientdemo.ejb;
  7.  
  8. import java.util.List;
  9. import javax.annotation.sql.DataSourceDefinition;
  10. import javax.ejb.Stateless;
  11. import javax.persistence.EntityManager;
  12. import javax.persistence.PersistenceContext;
  13. import javax.persistence.TypedQuery;
  14. import wipb.jee.clientdemo.model.Book;
  15.  
  16.  
  17. @DataSourceDefinition(
  18.         name="java:global/DemoDS",
  19.         className="org.apache.derby.jdbc.ClientDataSource",
  20.         minPoolSize = 1,
  21.         initialPoolSize = 1,
  22.         portNumber = 1527,
  23.         serverName = "localhost",
  24.         user = "app",
  25.         password = "app",
  26.         databaseName = "testdb11"      
  27. )
  28. @Stateless
  29. public class BookDao {
  30.     @PersistenceContext(unitName = "wipb_ee-std-client-demo-ejb_ejb_1.0PU")
  31.     private EntityManager em;
  32.    
  33.     public void save(Book book) {
  34.         em.persist(book);
  35.     }
  36.  
  37.     public List<Book> findAll() {
  38.         TypedQuery<Book> q = em.createNamedQuery("Book.findAll", Book.class);
  39.         return q.getResultList();
  40.     }
  41.  
  42.     public void remove(Long id) {
  43.         em.remove(em.getReference(Book.class, id));
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top