[jboss-svn-commits] JBL Code SVN: r30108 - labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 11 12:37:55 EST 2009


Author: whitingjr
Date: 2009-11-11 12:37:55 -0500 (Wed, 11 Nov 2009)
New Revision: 30108

Modified:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java
Log:
Modified sample test case to use EntityManager and Hibernate native API to control the transaction demarcation.

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java	2009-11-11 17:36:40 UTC (rev 30107)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java	2009-11-11 17:37:55 UTC (rev 30108)
@@ -32,8 +32,6 @@
 
 import org.apache.log4j.Logger;
 import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.hibernate.ejb.EntityManagerImpl;
 import org.testng.Assert;
 import org.testng.annotations.Parameters;
@@ -97,23 +95,13 @@
    public void testBody() throws Exception {
 
        // Start a unit of work (manually, no container)
-       //getUserTransaction().begin();
-      Session session = null;
-      Transaction transaction = null;
+      EntityManager em = null;
+      EntityManagerImpl emImpl = null;
       try
       {
-         /*
-         session = getSessionFactory().openSession();
-         
-         transaction = session.beginTransaction();
-         */
-         EntityManager em = getEntityManagerFactory().createEntityManager();
-         
-         
-          EntityManagerImpl emImpl = (EntityManagerImpl)em;
-          logger.debug("Transaction status ["+emImpl.getSession().getTransaction().isActive()+"]");
-          
-          em.joinTransaction();
+         em = getEntityManagerFactory().createEntityManager();
+          emImpl = (EntityManagerImpl)em;
+          emImpl.getSession().beginTransaction();
    
           // Prepare the DAOs (manually, no Seam)
           ItemDAO itemDAO = new ItemDAOBean();
@@ -143,17 +131,17 @@
    
           // Don't forget to take the return value, this is basically a merge()
           newItem = itemDAO.makePersistent(newItem);
-          session.flush();
           em.flush();
+          emImpl.getSession().getTransaction().commit();
+          Assert.assertFalse(emImpl.getSession().getTransaction().isActive());
           
-          transaction.commit(); // End the unit of work
-          
           // Direct SQL query for database state in auto-commit mode
           EntityManager emtest = null;
           try
           {
              
              emtest = getEntityManagerFactory().createEntityManager();
+             //Assert.assertTrue(emtest.getTransaction().isActive());
              Object[] result = (Object[])
                      emtest.createNativeQuery(
                              "select INITIAL_PRICE as IP," +
@@ -173,38 +161,30 @@
           }
           finally 
           {
-             if (null != em)
-             {
-                em.close();
-             }
              if (null != emtest)
              {
+                Assert.assertTrue(emtest.isOpen());
                 emtest.close();
+                Assert.assertFalse(emtest.isOpen());
              }
           }
-          
       }
       catch (HibernateException e) {
          logger.error(e.getMessage(), e);
-         if (null != transaction)
-         {
-            transaction.rollback();
-         }
          throw e;
       }
       catch (PersistenceException pe)
       {
          logger.error(pe.getMessage(), pe);
-         if (null != transaction)
-         {
-            transaction.rollback();
-         }
          throw pe;
       }
-      finally {
-         if (null != session)
+      finally 
+      {
+         if (null != em)
          {
-            session.close();
+            Assert.assertTrue(em.isOpen());
+            em.close();
+            Assert.assertFalse(em.isOpen());
          }
       }
    }



More information about the jboss-svn-commits mailing list