Author: stliu
Date: 2010-01-01 12:43:25 -0500 (Fri, 01 Jan 2010)
New Revision: 18378
Modified:
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
Log:
retrive to r18376 due to the last wrong commit
Modified:
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java
===================================================================
---
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java 2010-01-01
17:32:13 UTC (rev 18377)
+++
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java 2010-01-01
17:43:25 UTC (rev 18378)
@@ -12,13 +12,13 @@
public Thing findThingHibernate(Long id);
-// public List<Thing> findAllThingsJPA();
-//
-// public Thing findThingJPA(Long id);
-//
-// public Thing findThingJPAjndi(Long id) throws Exception;
-//
-// public Thing findThingHibernateMBean(Long id) throws Exception;
-//
-// public Thing findThingJPAThruHibernate(Long id);
+ public List<Thing> findAllThingsJPA();
+
+ public Thing findThingJPA(Long id);
+
+ public Thing findThingJPAjndi(Long id) throws Exception;
+
+ public Thing findThingHibernateMBean(Long id) throws Exception;
+
+ public Thing findThingJPAThruHibernate(Long id);
}
Modified:
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java
===================================================================
---
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java 2010-01-01
17:32:13 UTC (rev 18377)
+++
sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java 2010-01-01
17:43:25 UTC (rev 18378)
@@ -2,7 +2,6 @@
import java.util.List;
-import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@@ -15,21 +14,53 @@
import com.redhat.gss.lobtest.hibernate.HibernateUtil;
import com.redhat.gss.lobtest.jpa.Thing;
-@Stateful
+@Stateless
public class ThingServiceBean implements ThingService
{
+ @PersistenceContext(unitName="lobtest-jpa")
+ private EntityManager em;
-
@SuppressWarnings("unchecked")
public List<Thing> findAllThingsHibernate()
{
Session s = HibernateUtil.getSession();
return s.createQuery("from Thing").list();
}
+
+ @SuppressWarnings("unchecked")
+ public List<Thing> findAllThingsJPA()
+ {
+ return em.createQuery("from Thing").getResultList();
+ }
+
+ // Use Cae A-1
+ public Thing findThingJPA(Long id)
+ {
+ Thing t = em.getReference(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" +
t.getName() + " class=" + t.getClass());
+ return t;
+ }
+ //Use Case A-2
+ public Thing findThingJPAjndi(Long id) throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ EntityManager em = (EntityManager) ctx.lookup("persistence/EntityManager");
+ Thing t = em.getReference(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" +
t.getName() + " class=" + t.getClass());
+ return t;
+ }
+
+ //Use Case A-3
+ public Thing findThingJPAThruHibernate(Long id)
+ {
+ Session s = (Session)em.getDelegate();
+ Thing t = (Thing) s.load(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" +
t.getName() + " class=" + t.getClass());
+ return t;
+ }
-
// Use Case B-1
public Thing findThingHibernate(Long id)
{
@@ -41,26 +72,24 @@
}
// Use Case B-2
-// public Thing findThingHibernateMBean(Long id) throws Exception
-// {
-// Thing t = null;
-// Session s = null;
-// InitialContext ctx = new InitialContext();
-// SessionFactory sf = (SessionFactory)
ctx.lookup("java:/hibernate/LobTestSessionFactory");
-// s = sf.getCurrentSession();
-//
-// t = (Thing) s.load(Thing.class, id);
-// System.out.println("Thing: id=" + t.getId() + " name=" +
t.getName() + " class=" + t.getClass());
-// return t;
-// }
+ public Thing findThingHibernateMBean(Long id) throws Exception
+ {
+ Thing t = null;
+ Session s = null;
+ InitialContext ctx = new InitialContext();
+ SessionFactory sf = (SessionFactory)
ctx.lookup("java:/hibernate/LobTestSessionFactory");
+ s = sf.getCurrentSession();
+ t = (Thing) s.load(Thing.class, id);
+ System.out.println("Thing: id=" + t.getId() + " name=" +
t.getName() + " class=" + t.getClass());
+ return t;
+ }
+
public Thing setUp()
{
Thing t1 = new Thing(System.currentTimeMillis(), "One");
- Session s= HibernateUtil.getSession();
- s.persist( t1 );
- //em.persist(t1);
+ em.persist(t1);
return t1;
}
Modified: sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2010-01-01 17:32:13
UTC (rev 18377)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp 2010-01-01 17:43:25
UTC (rev 18378)
@@ -14,15 +14,35 @@
System.out.println("basic.jsp from query: Thing: id=" + t.getId() + "
name=" + t.getName() + " class=" + t.getClass());
}
- %>
+ t = ts.findThingJPA(t.getId());
+ System.out.println("A-1 - basic.jsp from ts.findThingJPA(): Thing: id=" +
t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("A-1 - basic.jsp from ts.findThingJPA(): Thing: id=" +
t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ %>
</br>
-
+ <%
+ t = ts.findThingJPAjndi(t.getId());
+ System.out.println("A-2 - basic.jsp from ts.findJPAjndi(): Thing: id=" +
t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+ out.println("A-2 - basic.jsp from ts.findJPAjndi(): Thing: id=" + t.getId()
+ " name=" + t.getName() + " class=" + t.getClass());
+ %>
+ </br>
+ <%
+ t = ts.findThingJPAThruHibernate(t.getId());
+ System.out.println("A-3 - basic.jsp from ts.findThingJPAThruHibernate(): Thing:
id=" + t.getId() + " name=" + t.getName() + " class=" +
t.getClass());
+ out.println("A-3 - basic.jsp from ts.findThingJPAThruHibernate(): Thing:
id=" + t.getId() + " name=" + t.getName() + " class=" +
t.getClass());
+ %>
+ </br>
<%
t = ts.findThingHibernate(t.getId());
System.out.println("B-1 - basic.jsp from ts.findThingHibernate(): Thing:
id=" + t.getId() + " name=" + t.getName() + " class=" +
t.getClass());
out.println("B-1 - basic.jsp from ts.findThingHibernate(): Thing: id=" +
t.getId() + " name=" + t.getName() + " class=" + t.getClass());
%>
</br>
-
+ <%
+ t = ts.findThingHibernateMBean(t.getId());
+ System.out.println("B-2 - basic.jsp from ts.findThingHibernateMBean(): Thing:
id=" + t.getId() + " name=" + t.getName() + " class=" +
t.getClass());
+ out.println("B-2 - basic.jsp from ts.findThingHibernateMBean(): Thing: id="
+ t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+
+
+%>
</br>
Tests run successfully.
Show replies by date