java/nekurak.net-web/src/java/cz/frantovo/nekurak/web/PodnikyHibernateWeb.java
author František Kučera <franta-hg@frantovo.cz>
Thu Feb 11 10:06:39 2010 +0100 (2010-02-11)
changeset 28 0f037986bb6b
permissions -rw-r--r--
Hibernate.
     1 package cz.frantovo.nekurak.web;
     2 
     3 import cz.frantovo.nekurak.dto.Podnik;
     4 import cz.frantovo.nekurak.ejb.PodnikHibernateDAORemote;
     5 import java.io.Serializable;
     6 import java.util.Collection;
     7 import java.util.logging.Level;
     8 import java.util.logging.Logger;
     9 import javax.naming.Context;
    10 import javax.naming.InitialContext;
    11 import javax.naming.NamingException;
    12 
    13 /**
    14  *
    15  * @author fiki
    16  */
    17 public class PodnikyHibernateWeb implements Serializable {
    18 
    19     private PodnikHibernateDAORemote podnikDAO;
    20     private static final Logger log = Logger.getLogger(PodnikyHibernateWeb.class.getSimpleName());
    21 
    22     public Collection<Podnik> getPodniky() {
    23 	return lookupCilDAO().getPodniky();
    24     }
    25 
    26     private PodnikHibernateDAORemote lookupCilDAO() {
    27 	if (podnikDAO == null) {
    28 	    try {
    29 		Context c = new InitialContext();
    30 		podnikDAO = (PodnikHibernateDAORemote) c.lookup("cz.frantovo.nekurak.ejb.PodnikHibernateDAORemote");
    31 	    } catch (NamingException e) {
    32 		log.log(Level.SEVERE, "Chyba při hledání PodnikHibernateDAO", e);
    33 		throw new RuntimeException(e);
    34 	    }
    35 	}
    36 	return podnikDAO;
    37     }
    38 }