View Javadoc

1   /*
2    * Atlassian Source Code Template.
3    * User: Administrator
4    * Created: Oct 18, 2002
5    * Time: 12:29:13 PM
6    * CVS Revision: $Revision: 1.3 $
7    * Last CVS Commit: $Date: 2005/10/10 12:07:06 $
8    * Author of last CVS Commit: $Author: amazkovoi $
9    */
10  package com.atlassian.core.ofbiz.util;
11  
12  import org.ofbiz.core.entity.GenericTransactionException;
13  import org.ofbiz.core.entity.TransactionUtil;
14  import com.atlassian.core.ofbiz.CoreFactory;
15  
16  import java.sql.Connection;
17  
18  /**
19   * This class is a simple wrapper around OFBiz TransactionUtil class.
20   *
21   * You can set JIRA to use transactions or not with the useTransactions flag.
22   */
23  public class CoreTransactionUtil
24  {
25      static boolean useTransactions = true;
26      static int isolationLevel = Connection.TRANSACTION_READ_COMMITTED;;
27  
28      public static boolean begin() throws GenericTransactionException
29      {
30          if (useTransactions)
31              return TransactionUtil.beginLocalTransaction(CoreFactory.getGenericDelegator().getGroupHelperName("default"), isolationLevel);
32  
33          return true;
34      }
35  
36      public static void commit(boolean began) throws GenericTransactionException
37      {
38          if (useTransactions)
39              TransactionUtil.commitLocalTransaction(began);
40      }
41  
42      public static void rollback(boolean began) throws GenericTransactionException
43      {
44          if (useTransactions)
45              TransactionUtil.rollbackLocalTransaction(began);
46      }
47      
48      public static void setUseTransactions(boolean useTransactions)
49      {
50          CoreTransactionUtil.useTransactions = useTransactions;
51      }
52  
53      public static int getIsolationLevel()
54      {
55          return isolationLevel;
56      }
57  
58      public static void setIsolationLevel(int isolationLevel)
59      {
60          CoreTransactionUtil.isolationLevel = isolationLevel;
61      }
62  
63  }