KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > util > JTAHelper


1 //$Id: JTAHelper.java,v 1.3 2005/07/06 22:21:34 epbernard Exp $
2
package org.hibernate.util;
3
4 import javax.transaction.Status JavaDoc;
5 import javax.transaction.SystemException JavaDoc;
6 import javax.transaction.TransactionManager JavaDoc;
7
8 import org.hibernate.TransactionException;
9 import org.hibernate.engine.SessionFactoryImplementor;
10
11 /**
12  * @author Gavin King
13  */

14 public final class JTAHelper {
15
16     private JTAHelper() {}
17
18     public static boolean isRollback(int status) {
19         return status==Status.STATUS_MARKED_ROLLBACK ||
20             status==Status.STATUS_ROLLING_BACK ||
21             status==Status.STATUS_ROLLEDBACK;
22     }
23
24     public static boolean isInProgress(int status) {
25         return status==Status.STATUS_ACTIVE ||
26             status==Status.STATUS_MARKED_ROLLBACK;
27     }
28
29     /**
30      * Return true if a JTA transaction is in progress
31      * and false in *every* other cases (including in a JDBC transaction).
32      */

33     public static boolean isTransactionInProgress(SessionFactoryImplementor factory) {
34         TransactionManager JavaDoc tm = factory.getTransactionManager();
35         try {
36             return ( tm!=null && isTransactionInProgress( tm.getTransaction() ) );
37         }
38         catch (SystemException JavaDoc se) {
39             throw new TransactionException( "could not obtain JTA Transaction", se );
40         }
41     }
42
43     public static boolean isTransactionInProgress(javax.transaction.Transaction JavaDoc tx) throws SystemException JavaDoc {
44         return tx != null && JTAHelper.isInProgress( tx.getStatus() );
45     }
46 }
47
Popular Tags