[jboss-svn-commits] JBL Code SVN: r31509 - in labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance: resource and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Feb 9 06:33:43 EST 2010
Author: whitingjr
Date: 2010-02-09 06:33:43 -0500 (Tue, 09 Feb 2010)
New Revision: 31509
Modified:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java
Log:
Refactored classes.
Cleaned up the flushing of data.
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java 2010-02-09 11:32:40 UTC (rev 31508)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java 2010-02-09 11:33:43 UTC (rev 31509)
@@ -25,9 +25,7 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
-import javax.transaction.Synchronization;
-import org.apache.log4j.Logger;
import org.hibernate.Transaction;
import org.hibernate.ejb.EntityManagerImpl;
import org.jboss.jbossts.performance.configuration.ConcurrentTaskConfiguration;
@@ -35,6 +33,14 @@
import org.jboss.tm.TransactionLocal;
import org.testng.Assert;
+/**
+ *
+ * This object performs a read and write on two resources using native SQL. The
+ * sql query uses the EntityManager to execute the query.
+ *
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
public class JDBCTask extends RecursiveTask
{
@@ -55,8 +61,7 @@
Transaction transaction =emA.getSession().beginTransaction();
TransactionLocal session = new TransactionLocal();
- transaction.registerSynchronization(new SessionSynchronization(emA, transaction, true));
- transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
+// transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
session.set(emA);
Object[] usrA = (Object[])findUsingResourceA(emA, readSQL);//discard details
@@ -79,7 +84,7 @@
null, "anotheruser at mail.tld", "Ben"+time, "Foocity", "Foostreet", "22222", "User", "secret", 0, "anotheruser110"+this.threadId, version.intValue()+1, this.threadId, version.intValue());
writeUserB(emB, writeSQLResB);
- emA.getSession().getTransaction().commit();
+ transaction.commit();
Assert.assertFalse(emA.isOpen());
}
private void writeUserA(final EntityManager em, final String sql)
@@ -95,14 +100,6 @@
Query query = em.createNativeQuery(sql);
Assert.assertEquals(1, query.executeUpdate()) ;
}
- private void resourceAFlush(EntityManager entityManager)
- {
- entityManager.flush();
- }
- private void resourceBFlush(EntityManager entityManager)
- {
- entityManager.flush();
- }
private Object findUsingResourceA(final EntityManager em, final String sql)
{
return findUsingResource(em, sql);
@@ -125,30 +122,4 @@
{
return this.emfB;
}
- public class SessionSynchronization implements Synchronization
- {
- private final Logger logger = Logger.getLogger(SessionSynchronization.class);
- private EntityManager manager;
- private boolean closeAtTxCompletion;
-
- public SessionSynchronization(EntityManager session, Transaction tx, boolean close)
- {
- this.manager = session;
- closeAtTxCompletion = close;
- }
-
- public void beforeCompletion()
- {
- }
-
- public void afterCompletion(int status)
- {
- if (closeAtTxCompletion)
- {
- logger.debug("************** closing entity managersession **************");
- manager.close();
- }
- }
- }
-
}
\ No newline at end of file
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java 2010-02-09 11:32:40 UTC (rev 31508)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java 2010-02-09 11:33:43 UTC (rev 31509)
@@ -3,12 +3,11 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
-import javax.transaction.Synchronization;
-import org.apache.log4j.Logger;
import org.hibernate.Transaction;
import org.hibernate.ejb.EntityManagerImpl;
import org.jboss.jbossts.performance.configuration.ConcurrentTaskConfiguration;
+import org.jboss.jbossts.performance.synchronization.SessionSynchronization;
import org.jboss.jbossts.performance.task.RecursiveTask;
import org.jboss.tm.TransactionLocal;
import org.testng.Assert;
@@ -23,7 +22,7 @@
* is used to co-ordinate a distributed transaction.
* The implementation is a little clunky but it does what's necessary. The requirement
* was to avoid depending on using an EJB container and use the Hibernate APIs and internals
- * to switch between native and xa functionality without code changes.
+ * to switch between native and xa functionality avoiding code changes.
*
* @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
* @version $Revision: 1.1 $
@@ -52,7 +51,8 @@
TransactionLocal session = new TransactionLocal();
/* emA automatically has a synch established because it is associated with the em factory A.
- * Whereas emB isn't and therefore the JDBCContext for B needs a synch added to flush updates. */
+ * Whereas emB isn't and therefore the EM persistence context for B needs a synch added to
+ * flush updates. */
transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
/**
@@ -85,7 +85,7 @@
emB.merge(userB);
/* the commit call will cause hibernate to check for changes to entities,
* flushing any changes in the queue (write behind) before commit. */
- emA.getSession().getTransaction().commit();
+ transaction.commit();
}
public EntityManagerFactory getEMFactoryA()
@@ -99,43 +99,10 @@
}
/**
- * This class provides a synchronziation of the second resource when the first commits.
- * @author whitingjr
- *
- */
- public class SessionSynchronization implements Synchronization
- {
- private final Logger logger = Logger.getLogger(SessionSynchronization.class);
- private EntityManager manager;
- private boolean closeAtTxCompletion;
-
- public SessionSynchronization(EntityManager session, Transaction tx, boolean close)
- {
- this.manager = session;
- closeAtTxCompletion = close;
- }
-
- public void beforeCompletion()
- {
- /* This implementatino assumes everything is ok and various statuses no not need checking.*/
- this.manager.flush();
- }
-
- public void afterCompletion(int status)
- {
- if (closeAtTxCompletion)
- {
- logger.debug("************** closing entity managersession **************");
- manager.close();
- }
- }
- }
-
- /**
* This method exists purely for the profiler to separate resource duration
*
*/
- private void resourceAFlush(EntityManager entityManager)
+/* private void resourceAFlush(EntityManager entityManager)
{
entityManager.flush();
}
@@ -143,7 +110,7 @@
{
entityManager.flush();
}
- private User findUsingResourceA(UserDAOBeanMultiResource daoBean)
+*/ private User findUsingResourceA(UserDAOBeanMultiResource daoBean)
{
return daoBean.findById(this.threadId, false);
}
More information about the jboss-svn-commits
mailing list