KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > pim > data > JtaTransactionContext


1 /*
2  * Created on May 27, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.pim.data;
8
9 import java.sql.SQLException JavaDoc;
10
11 import javax.naming.InitialContext JavaDoc;
12 import javax.naming.NamingException JavaDoc;
13 import javax.transaction.UserTransaction JavaDoc;
14
15 import org.enhydra.pim.business.TransactionContextI;
16
17 import com.lutris.appserver.server.sql.DatabaseManagerException;
18
19 /**
20  * @author P.Djojic May 27, 2005 1:39:37 AM
21  *
22  * TODO JtaTransactionContext
23  */

24 public class JtaTransactionContext implements TransactionContextI {
25
26     UserTransaction JavaDoc utContext = null;
27     
28     public void beginContext(String JavaDoc database) throws DatabaseManagerException, SQLException JavaDoc {
29         if(utContext==null) {
30             try {
31                 InitialContext JavaDoc ic = new InitialContext JavaDoc();
32                 utContext = (UserTransaction JavaDoc) ic.lookup("java:comp/UserTransaction");
33             } catch (NamingException JavaDoc e) {
34                 System.out.println("Error during transaction context begin");
35             }
36         }
37         try {
38             utContext.begin();
39         } catch (Exception JavaDoc e) {
40             System.out.println("Error during transaction context begin");
41         }
42     }
43     
44     public void releaseContext() {
45         if(utContext!=null) {
46             try {
47                 utContext.commit();
48             } catch (Exception JavaDoc e) {
49                 System.out.println("Error during transaction context release");
50             }
51             utContext=null;
52         }
53     }
54     
55     public void commitContext() throws SQLException JavaDoc {
56         if(utContext!=null) {
57             try {
58                 utContext.commit();
59             } catch (Exception JavaDoc e) {
60                 System.out.println("Error during transaction context commit");
61             }
62             utContext=null;
63         }
64     }
65     
66     public void rollbackContext() throws SQLException JavaDoc {
67         if(utContext!=null) {
68             try {
69                 utContext.rollback();
70             } catch (Exception JavaDoc e) {
71                 System.out.println("Error during transaction context rollback");
72             }
73             utContext=null;
74         }
75     }
76
77 }
78
Popular Tags