KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on May 12, 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 org.enhydra.dods.DODS;
12 import org.enhydra.dods.xa.XAUserTransaction;
13 import org.enhydra.pim.business.TransactionContextI;
14
15 import com.lutris.appserver.server.sql.DBTransaction;
16 import com.lutris.appserver.server.sql.DatabaseManagerException;
17
18 /**
19  * @author P.Djojic May 12, 2005 8:41:03 PM
20  *
21  * TODO TransactionContextManager
22  */

23 public class TransactionContext implements TransactionContextI {
24     
25     private DBTransaction context= null;
26     
27     public void beginContext(String JavaDoc database) throws DatabaseManagerException, SQLException JavaDoc {
28         if(context==null) {
29             context = DODS.getDatabaseManager().findLogicalDatabase(database).createTransaction();
30         }
31     }
32     
33     public void releaseContext() {
34         if(context!=null) {
35             try {
36                 context.commit();
37             } catch (Exception JavaDoc e) {
38                 System.out.println("Transaction context are not released");
39             }
40             context.release();
41             context=null;
42         }
43     }
44     
45     public void commitContext() throws SQLException JavaDoc {
46         if(context!=null) {
47             try {
48                 context.commit();
49             } catch (Exception JavaDoc e) {
50                 System.out.println("Transaction context are not commited");
51             }
52             if(context instanceof XAUserTransaction ) {
53                 context=null;
54             }
55         }
56     }
57     
58     public void rollbackContext() throws SQLException JavaDoc {
59         if(context!=null) {
60             try {
61                 context.rollback();
62             } catch (Exception JavaDoc e) {
63                 System.out.println("Transaction context are not rollback-ed");
64             }
65             if(context instanceof XAUserTransaction ) {
66                 context=null;
67             }
68         }
69     }
70     
71 }
72
73
Popular Tags