author | František Kučera <franta-hg@frantovo.cz> |
Sun, 20 Jun 2010 14:46:47 +0200 | |
changeset 145 | 0efefbf5f8b6 |
parent 96 | 9f6225d83611 |
permissions | -rw-r--r-- |
franta-hg@75 | 1 |
package cz.frantovo.nekurak.dao; |
franta-hg@75 | 2 |
|
franta-hg@75 | 3 |
import cz.frantovo.nekurak.dto.Clanek; |
franta-hg@75 | 4 |
import java.util.Collection; |
franta-hg@75 | 5 |
import javax.ejb.LocalBean; |
franta-hg@75 | 6 |
import javax.ejb.Stateless; |
franta-hg@75 | 7 |
import javax.persistence.EntityManager; |
franta-hg@75 | 8 |
import javax.persistence.PersistenceContext; |
franta-hg@75 | 9 |
import javax.persistence.Query; |
franta-hg@75 | 10 |
|
franta-hg@75 | 11 |
/** |
franta-hg@75 | 12 |
* |
franta-hg@75 | 13 |
* @author fiki |
franta-hg@75 | 14 |
*/ |
franta-hg@75 | 15 |
@Stateless |
franta-hg@75 | 16 |
@LocalBean |
franta-hg@75 | 17 |
public class ClanekDAO { |
franta-hg@75 | 18 |
|
franta-hg@145 | 19 |
@PersistenceContext(unitName = DAO.PU) |
franta-hg@145 | 20 |
private EntityManager em; |
franta-hg@75 | 21 |
|
franta-hg@145 | 22 |
public Clanek getClanek(int id) { |
franta-hg@145 | 23 |
return em.find(Clanek.class, id); |
franta-hg@145 | 24 |
} |
franta-hg@75 | 25 |
|
franta-hg@145 | 26 |
public Collection<Clanek> getClanky() { |
franta-hg@145 | 27 |
Query dotaz = em.createQuery("FROM " + DAO.t(Clanek.class) + " c ORDER BY id"); |
franta-hg@145 | 28 |
return dotaz.getResultList(); |
franta-hg@145 | 29 |
} |
franta-hg@75 | 30 |
|
franta-hg@145 | 31 |
public int zalozClanek(Clanek clanek) { |
franta-hg@145 | 32 |
em.persist(clanek); |
franta-hg@145 | 33 |
return clanek.getId(); |
franta-hg@145 | 34 |
} |
franta-hg@75 | 35 |
|
franta-hg@145 | 36 |
public void upravClanek(Clanek clanek) { |
franta-hg@145 | 37 |
System.out.println("XXXXXXX: upravuji článek: " + clanek.getId()); |
franta-hg@145 | 38 |
em.merge(clanek); |
franta-hg@145 | 39 |
} |
franta-hg@94 | 40 |
|
franta-hg@145 | 41 |
public void smazClanek(Clanek clanek) { |
franta-hg@145 | 42 |
clanek = em.merge(clanek); |
franta-hg@145 | 43 |
em.remove(clanek); |
franta-hg@145 | 44 |
} |
franta-hg@75 | 45 |
} |