[hibernate-commits] Hibernate SVN: r17675 - in sandbox/trunk/lobtest-ee5: lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Oct 9 03:23:34 EDT 2009


Author: dstephan
Date: 2009-10-09 03:23:34 -0400 (Fri, 09 Oct 2009)
New Revision: 17675

Modified:
   sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml
   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:
Updates for HibernateService use case.

Modified: sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml
===================================================================
--- sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml	2009-10-09 06:54:08 UTC (rev 17674)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/hibernate-service.xml	2009-10-09 07:23:34 UTC (rev 17675)
@@ -1,38 +1,45 @@
 <?xml version="1.0"?>
 <server>
 
-<mbean code="org.hibernate.jmx.HibernateService"
-    name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
+	<mbean code="org.hibernate.jmx.HibernateService"
+		name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
 
+		com.redhat.gss.lobtest.jpa.Thing
 
-    <depends>jboss.jca:service=RARDeployer</depends>
-    <depends>jboss.jca:service=LocalTxCM,name=DefaultDS</depends>
+		<depends>jboss.jca:service=RARDeployer
+		</depends>
+		<depends>jboss.jca:service=LocalTxCM,name=DefaultDS
+		</depends>
 
-    <!-- Bind the Hibernate service to JNDI -->
-    <attribute name="JndiName">java:/hibernate/SessionFactory</attribute>
-        <!-- hibernate dialect -->
-    
-    <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
-    <attribute name="Dialect">org.hibernate.dialect.HSQLDialect</attribute>
+		<!-- Bind the Hibernate service to JNDI -->
+		<attribute name="JndiName">java:/hibernate/SessionFactory
+		</attribute>
+		<!-- hibernate dialect -->
 
+		<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect
+		</property>
+		<attribute name="Dialect">org.hibernate.dialect.HSQLDialect
+		</attribute>
 
-    <attribute name="Datasource">java:DefaultDS</attribute>
-    
-    <!-- DataSource properties (end) -->
 
-    <!-- JTA transaction properties (begin) -->
-    <attribute name="TransactionStrategy">
-        org.hibernate.transaction.JTATransactionFactory</attribute>
-    <attribute name="TransactionManagerLookupStrategy">
-        org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
-    <attribute name="FlushBeforeCompletionEnabled">true</attribute>
-    <attribute name="AutoCloseSessionEnabled">true</attribute>
-    
-    <!-- Simple memory-only cache -->
-    <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
+		<attribute name="Datasource">java:DefaultDS</attribute>
 
+		<!-- DataSource properties (end) -->
 
-</mbean>
+		<!-- JTA transaction properties (begin) -->
+		<attribute name="TransactionStrategy">
+			org.hibernate.transaction.JTATransactionFactory</attribute>
+		<attribute name="TransactionManagerLookupStrategy">
+			org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
+		<attribute name="FlushBeforeCompletionEnabled">true</attribute>
+		<attribute name="AutoCloseSessionEnabled">true</attribute>
 
+		<!-- Simple memory-only cache -->
+		<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider
+		</property>
+
+		<attribute name="ClassResources">com.redhat.gss.lobtest.jpa.Thing</attribute>
+	</mbean>
+
 </server>
 

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	2009-10-09 06:54:08 UTC (rev 17674)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingService.java	2009-10-09 07:23:34 UTC (rev 17675)
@@ -16,5 +16,5 @@
     
     public Thing findThingJPA(Long id);
     
-
+    public Thing findThingHibernateMBean(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	2009-10-09 06:54:08 UTC (rev 17674)
+++ sandbox/trunk/lobtest-ee5/lobtest-ejb/src/main/java/com/redhat/gss/lobtest/ejb/ThingServiceBean.java	2009-10-09 07:23:34 UTC (rev 17675)
@@ -7,42 +7,71 @@
 import javax.persistence.PersistenceContext;
 
 import org.hibernate.Session;
+import org.hibernate.SessionFactory;
 
+import javax.naming.InitialContext;
+
 import com.redhat.gss.lobtest.hibernate.HibernateUtil;
 import com.redhat.gss.lobtest.jpa.Thing;
 
 @Stateless
-public class ThingServiceBean implements ThingService {
+public class ThingServiceBean implements ThingService
+{
 
-    @PersistenceContext private EntityManager em;
+	@PersistenceContext
+	private EntityManager em;
 
-    @SuppressWarnings("unchecked")
-    public List<Thing> findAllThingsHibernate() {
-        Session s = HibernateUtil.getSession();
-        return s.createQuery("from Thing").list();
-    }
+	@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();
-    }
+	@SuppressWarnings("unchecked")
+	public List<Thing> findAllThingsJPA()
+	{
+		return em.createQuery("from Thing").getResultList();
+	}
 
-    public Thing findThingHibernate(Long id) {
-        Session s = HibernateUtil.getSession();
-        Thing t = (Thing) s.load(Thing.class, id);
-        System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
-        s.close();
-        return t;
-    }
+	public Thing findThingHibernate(Long id)
+	{
+		Session s = HibernateUtil.getSession();
+		Thing t = (Thing) s.load(Thing.class, id);
+		System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+		s.close();
+		return t;
+	}
 
-    public Thing findThingJPA(Long id) {
-        return em.getReference(Thing.class, id);
-    }
+	public Thing findThingHibernateMBean(Long id) throws Exception
+	{
+		Thing t = null;
+		Session s = null;
+		try
+		{
+			InitialContext ctx = new InitialContext();
+			SessionFactory sf = (SessionFactory) ctx.lookup("java:hibernate/SessionFactory");
+			s = sf.getCurrentSession();
 
-    public Thing setUp() {
-        Thing t1 = new Thing(System.currentTimeMillis(), "One");
-        em.persist(t1);
-        return t1;
-    }
+			t = (Thing) s.load(Thing.class, id);
+			System.out.println("Thing: id=" + t.getId() + " name=" + t.getName() + " class=" + t.getClass());
+		finally
+		{
+			s.close();
+		}
+		return t;
+	}
 
+	public Thing findThingJPA(Long id)
+	{
+		return em.getReference(Thing.class, id);
+	}
+
+	public Thing setUp()
+	{
+		Thing t1 = new Thing(System.currentTimeMillis(), "One");
+		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	2009-10-09 06:54:08 UTC (rev 17674)
+++ sandbox/trunk/lobtest-ee5/lobtest-web/src/main/webapp/basic.jsp	2009-10-09 07:23:34 UTC (rev 17675)
@@ -8,6 +8,7 @@
     out.print("Tests set up.</br>");
     ts.findAllThingsHibernate();
     ts.findThingHibernate(t.getId());
+    //ts.findThingHibernateMBean(t.getId());
 %>
 
 Tests run successfully.



More information about the hibernate-commits mailing list