[jboss-cvs] jboss-portal/test/src/main/org/jboss/portal/test/framework/embedded ...
Julien Viet
julien at jboss.com
Sun Jul 30 08:36:25 EDT 2006
User: julien
Date: 06/07/30 08:36:25
Modified: test/src/main/org/jboss/portal/test/framework/embedded
HibernateSupport.java
Log:
JBPORTAL-973 : Portlet instance container integration testing
JBPORTAL-972 : Portlet stateful invoker testing
Revision Changes Path
1.6 +38 -31 jboss-portal/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HibernateSupport.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- HibernateSupport.java 17 Jul 2006 12:27:13 -0000 1.5
+++ HibernateSupport.java 30 Jul 2006 12:36:24 -0000 1.6
@@ -30,13 +30,14 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Settings;
+import javax.transaction.Synchronization;
import java.util.Properties;
import java.util.Collection;
import java.util.Iterator;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class HibernateSupport
{
@@ -179,24 +180,6 @@
{
System.out.println("Warning : commited a transaction for the test case");
}
-
- //
- if (session != null)
- {
- session = null;
- }
- try
- {
- System.out.println("Warning : closing session for the test case");
- if (currentSession.isOpen())
- {
- currentSession.close();
- }
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- }
}
}
catch (HibernateException e)
@@ -227,16 +210,19 @@
{
throw new IllegalStateException("No current transaction");
}
- if (session != null)
- {
- session = null;
- }
try
{
Transaction tx = currentSession.getTransaction();
+ if (tx.isActive())
+ {
tx.commit();
return true;
}
+ else
+ {
+ return false;
+ }
+ }
catch (TransactionException e)
{
e.printStackTrace();
@@ -258,10 +244,6 @@
{
throw new IllegalStateException("No current transaction");
}
- if (session != null)
- {
- session = null;
- }
try
{
Transaction tx = currentSession.getTransaction();
@@ -280,7 +262,22 @@
{
return session;
}
- return factory.getCurrentSession();
+
+ //
+ session = factory.getCurrentSession();
+ Transaction tx = session.getTransaction();
+ tx.registerSynchronization(new Synchronization()
+ {
+ public void beforeCompletion()
+ {
+ }
+ public void afterCompletion(int i)
+ {
+ session = null;
+ }
+ });
+
+ return session;
}
catch (HibernateException e)
{
@@ -295,7 +292,17 @@
throw new IllegalStateException("Cannot have more than one active session");
}
session = factory.openSession();
- session.beginTransaction();
+ Transaction tx = session.beginTransaction();
+ tx.registerSynchronization(new Synchronization()
+ {
+ public void beforeCompletion()
+ {
+ }
+ public void afterCompletion(int i)
+ {
+ session = null;
+ }
+ });
return session;
}
}
More information about the jboss-cvs-commits
mailing list