java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/dao/PodnikDAO.java
author František Kučera <franta-hg@frantovo.cz>
Wed Apr 14 00:12:32 2010 +0200 (2010-04-14)
changeset 100 01be78803f73
parent 67 fa7e30dee3b3
child 107 e8371105fcc8
permissions -rw-r--r--
Webové služby, zjišťování souřadnic podniků.
     1 package cz.frantovo.nekurak.dao;
     2 
     3 import cz.frantovo.nekurak.dto.Podnik;
     4 import java.util.Collection;
     5 import java.util.Date;
     6 import javax.ejb.LocalBean;
     7 import javax.ejb.Stateless;
     8 import javax.persistence.EntityManager;
     9 import javax.persistence.PersistenceContext;
    10 import javax.persistence.Query;
    11 
    12 /**
    13  *
    14  * @author fiki
    15  */
    16 @Stateless
    17 @LocalBean
    18 public class PodnikDAO {
    19 
    20     @PersistenceContext(unitName = DAO.PU)
    21     private EntityManager em;
    22 
    23     public Collection<Podnik> getPodniky() {
    24 	Query dotaz = em.createQuery("FROM " + DAO.t(Podnik.class) + " o ORDER BY datum DESC");
    25 	return dotaz.getResultList();
    26     }
    27 
    28     /**
    29      * @return podniky, které nemají souřadnice (null, null)
    30      */
    31     public Collection<Podnik> getPodnikyBezSouradnic() {
    32 	Query dotaz = em.createQuery("FROM " + DAO.t(Podnik.class) + " o WHERE sirka IS NULL AND delka IS NULL");
    33 	return dotaz.getResultList();
    34     }
    35 
    36     public Podnik getPodnik(int id) {
    37 	return em.find(Podnik.class, id);
    38     }
    39 
    40     public void zaloz(Podnik p) {
    41 	if (p.getDatum() == null) {
    42 	    p.setDatum(new Date());
    43 	}
    44 
    45 	em.persist(p);
    46     }
    47 
    48     public void uloz(Podnik p) {
    49 	if (p.getDatum() == null) {
    50 	    p.setDatum(new Date());
    51 	}
    52 
    53 	em.merge(p);
    54     }
    55 }