# HG changeset patch # User František Kučera # Date 1265879199 -3600 # Node ID 0f037986bb6baec6dd2048f2b98a2b248510d968 # Parent 88f3012c60a2533b4184493fd8ca872cb95b7fff Hibernate. diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-ear/nbproject/project.properties --- a/java/nekurak.net-ear/nbproject/project.properties Thu Feb 11 08:52:50 2010 +0100 +++ b/java/nekurak.net-ear/nbproject/project.properties Thu Feb 11 10:06:39 2010 +0100 @@ -4,7 +4,7 @@ client.module.uri=nekurak.net-web client.urlPart= debug.classpath=${javac.classpath}::${jar.content.additional}:${run.classpath} -display.browser=true +display.browser=false dist.dir=dist dist.jar=${dist.dir}/${jar.name} endorsed.classpath=\ @@ -30,4 +30,5 @@ reference.nekurak_net-ejb.dist-ear=${project.nekurak_net-ejb}/dist/nekurak.net-ejb.jar reference.nekurak_net-web.dist-ear=${project.nekurak_net-web}/dist/nekurak.net-web.war resource.dir=setup +run.classpath= source.root=. diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-ejb/src/conf/Podnik.hbm.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-ejb/src/conf/Podnik.hbm.xml Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-ejb/src/conf/persistence.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-ejb/src/conf/persistence.xml Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,17 @@ + + + + org.hibernate.ejb.HibernatePersistence + jdbc/nekurak + false + + + + + + + + + + + diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikHibernateDAO.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikHibernateDAO.java Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,31 @@ +package cz.frantovo.nekurak.ejb; + +import cz.frantovo.nekurak.dto.Podnik; +import java.util.Collection; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +/** + * + * @author fiki + */ +@Stateless +public class PodnikHibernateDAO implements PodnikHibernateDAORemote { + + private static final String PU = "nekurak.net-PU"; + + @PersistenceContext(unitName = PU) + private EntityManager em; + + public Collection getPodniky() { + Query dotaz = em.createQuery("FROM " + t(Podnik.class) + " o ORDER BY nazev"); + return dotaz.getResultList(); + } + + + private static String t(Class trida) { + return trida.getSimpleName(); + } +} diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-lib/src/cz/frantovo/nekurak/dto/Podnik.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-lib/src/cz/frantovo/nekurak/dto/Podnik.java Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,38 @@ +package cz.frantovo.nekurak.dto; + +import java.io.Serializable; + +/** + * + * @author fiki + */ +public class Podnik implements Serializable { + + private int id; + private String nazev; + + public Podnik() { + } + + public Podnik(int id, String nazev) { + this.id = id; + this.nazev = nazev; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNazev() { + return nazev; + } + + public void setNazev(String nazev) { + this.nazev = nazev; + } + +} diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-lib/src/cz/frantovo/nekurak/ejb/PodnikHibernateDAORemote.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-lib/src/cz/frantovo/nekurak/ejb/PodnikHibernateDAORemote.java Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,16 @@ +package cz.frantovo.nekurak.ejb; + +import cz.frantovo.nekurak.dto.Podnik; +import java.util.Collection; +import javax.ejb.Remote; + +/** + * + * @author fiki + */ +@Remote +public interface PodnikHibernateDAORemote { + + public Collection getPodniky(); + +} diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-web/src/java/cz/frantovo/nekurak/dto/Podnik.java --- a/java/nekurak.net-web/src/java/cz/frantovo/nekurak/dto/Podnik.java Thu Feb 11 08:52:50 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -package cz.frantovo.nekurak.dto; - -import java.io.Serializable; - -/** - * - * @author fiki - */ -public class Podnik implements Serializable { - - private int id; - private String nazev; - - public Podnik() { - } - - public Podnik(int id, String nazev) { - this.id = id; - this.nazev = nazev; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getNazev() { - return nazev; - } - - public void setNazev(String nazev) { - this.nazev = nazev; - } - -} diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-web/src/java/cz/frantovo/nekurak/web/PodnikyHibernateWeb.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-web/src/java/cz/frantovo/nekurak/web/PodnikyHibernateWeb.java Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,38 @@ +package cz.frantovo.nekurak.web; + +import cz.frantovo.nekurak.dto.Podnik; +import cz.frantovo.nekurak.ejb.PodnikHibernateDAORemote; +import java.io.Serializable; +import java.util.Collection; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +/** + * + * @author fiki + */ +public class PodnikyHibernateWeb implements Serializable { + + private PodnikHibernateDAORemote podnikDAO; + private static final Logger log = Logger.getLogger(PodnikyHibernateWeb.class.getSimpleName()); + + public Collection getPodniky() { + return lookupCilDAO().getPodniky(); + } + + private PodnikHibernateDAORemote lookupCilDAO() { + if (podnikDAO == null) { + try { + Context c = new InitialContext(); + podnikDAO = (PodnikHibernateDAORemote) c.lookup("cz.frantovo.nekurak.ejb.PodnikHibernateDAORemote"); + } catch (NamingException e) { + log.log(Level.SEVERE, "Chyba při hledání PodnikHibernateDAO", e); + throw new RuntimeException(e); + } + } + return podnikDAO; + } +} diff -r 88f3012c60a2 -r 0f037986bb6b java/nekurak.net-web/web/hibernate.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/nekurak.net-web/web/hibernate.jsp Thu Feb 11 10:06:39 2010 +0100 @@ -0,0 +1,42 @@ + + + + + + + + Nekuřák.net + + + +

Nekuřák.net – Hibernate:

+

Načítáme údaje z databáze.

+ +

Seznam podniků načtený pomocí Hibernate:

+ + + + + + + + + + + + + + + + + +
ČísloNázev
+ + + + +