java/HibernateDemo1/HibernateDemo1-war/src/java/cz/frantovo/hibernateDemo1/SeznamCilu.java
changeset 4 58552ccfe6c8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/HibernateDemo1/HibernateDemo1-war/src/java/cz/frantovo/hibernateDemo1/SeznamCilu.java	Sat Mar 14 23:15:33 2009 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +package cz.frantovo.hibernateDemo1;
     1.5 +
     1.6 +import cz.frantovo.hibernateDemo1.CilDAORemote;
     1.7 +import cz.frantovo.hibernateDemo1.dto.Cil;
     1.8 +import java.util.Collection;
     1.9 +import java.util.logging.Level;
    1.10 +import java.util.logging.Logger;
    1.11 +import javax.naming.Context;
    1.12 +import javax.naming.InitialContext;
    1.13 +import javax.naming.NamingException;
    1.14 +
    1.15 +/**
    1.16 + * Webová Beana pro zobrazení seznamu cílů.
    1.17 + * Volá EJB, které tento seznam získá z databáze
    1.18 + * @author fiki
    1.19 + */
    1.20 +public class SeznamCilu {
    1.21 +
    1.22 +    private CilDAORemote cilDAO;
    1.23 +    private static final Logger log = Logger.getLogger(SeznamCilu.class.getSimpleName());
    1.24 +
    1.25 +    public Collection<Cil> getCile() {
    1.26 +        return lookupCilDAO().getCile();
    1.27 +    }
    1.28 +
    1.29 +    private CilDAORemote lookupCilDAO() {
    1.30 +        if (cilDAO == null) {
    1.31 +            try {
    1.32 +                Context c = new InitialContext();
    1.33 +                cilDAO = (CilDAORemote) c.lookup("cz.frantovo.hibernateDemo1.CilDAORemote");
    1.34 +            } catch (NamingException e) {
    1.35 +                log.log(Level.SEVERE, "Chyba při hledání CilDAO", e);
    1.36 +                throw new RuntimeException(e);
    1.37 +            }
    1.38 +        }
    1.39 +        return cilDAO;
    1.40 +    }
    1.41 +}