Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package wipb.jee.clientdemo.ejb;
- import java.util.List;
- import javax.annotation.sql.DataSourceDefinition;
- import javax.ejb.Stateless;
- import javax.persistence.EntityManager;
- import javax.persistence.PersistenceContext;
- import javax.persistence.TypedQuery;
- import wipb.jee.clientdemo.model.Book;
- @DataSourceDefinition(
- name="java:global/DemoDS",
- className="org.apache.derby.jdbc.ClientDataSource",
- minPoolSize = 1,
- initialPoolSize = 1,
- portNumber = 1527,
- serverName = "localhost",
- user = "app",
- password = "app",
- databaseName = "testdb11"
- )
- @Stateless
- public class BookDao {
- @PersistenceContext(unitName = "wipb_ee-std-client-demo-ejb_ejb_1.0PU")
- private EntityManager em;
- public void save(Book book) {
- em.persist(book);
- }
- public List<Book> findAll() {
- TypedQuery<Book> q = em.createNamedQuery("Book.findAll", Book.class);
- return q.getResultList();
- }
- public void remove(Long id) {
- em.remove(em.getReference(Book.class, id));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement