KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > transaction > SharkDODSTransaction


1 /* SharkDODSTransaction.java */
2
3 package org.enhydra.shark.transaction;
4
5
6
7 /**
8  * Implementation of TransactionFactory interface that creates DODS transaction.
9  *
10  */

11
12 import com.lutris.appserver.server.sql.DBTransaction;
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15 import org.enhydra.shark.api.RootException;
16 import org.enhydra.shark.api.TransactionException;
17 import org.enhydra.shark.api.internal.transaction.SharkInternalTransaction;
18 import org.enhydra.shark.api.internal.working.WfProcessInternal;
19 import org.enhydra.shark.api.internal.working.WfResourceInternal;
20 import org.enhydra.shark.utilities.dods.Buffer;
21
22 public class SharkDODSTransaction extends Buffer implements SharkInternalTransaction {
23
24    private Map JavaDoc processes=new HashMap JavaDoc();
25    private Map JavaDoc resources=new HashMap JavaDoc();
26
27    private static int noOfCreations=0;
28    private static int noOfCommits=0;
29    private static int noOfRollbacks=0;
30    private static int noOfReleases=0;
31
32    //private DBTransaction transaction;
33

34    public SharkDODSTransaction (DBTransaction transaction) {
35       super(transaction);
36       if (DODSTransactionFactory._debug_) {
37          synchronized (SharkDODSTransaction.class) {
38             noOfCreations++;
39             System.out.println("CREATING T No"+noOfCreations);
40          }
41          //Thread.dumpStack();
42
}
43       //this.transaction=transaction;
44
}
45
46    public DBTransaction getDODSTransaction () {
47       return transaction;
48    }
49
50    public void commit () throws TransactionException {
51       if (DODSTransactionFactory._debug_) {
52          synchronized (SharkDODSTransaction.class) {
53             System.out.println("COMMITING T ");
54          }
55          //Thread.dumpStack();
56
}
57       try {
58          write();
59          transaction.commit();
60          //System.err.println("success: "+baos.toString());
61
//transaction.release();
62
if (DODSTransactionFactory._debug_) {
63             synchronized (SharkDODSTransaction.class) {
64                noOfCommits++;
65                System.out.println("COMMITED T No"+noOfCommits);
66             }
67             //Thread.dumpStack();
68
}
69       } catch (Exception JavaDoc ex) {
70          throw new TransactionException(ex);
71       } finally {
72          processes.clear();
73          resources.clear();
74       }
75    }
76
77    public void rollback () throws TransactionException {
78       try {
79          //transaction.rollback();
80
//transaction.release();
81
if (DODSTransactionFactory._debug_) {
82             synchronized (SharkDODSTransaction.class) {
83                noOfRollbacks++;
84                System.out.println("ROLLING BACK T "+noOfRollbacks);
85             }
86             //Thread.dumpStack();
87
}
88       } catch (Exception JavaDoc ex) {
89          if (DODSTransactionFactory._debug_) {
90             System.out.println("ROLLING BACK FAILED");
91          }
92          throw new TransactionException(ex);
93       } finally {
94          processes.clear();
95          resources.clear();
96       }
97    }
98
99    public void release() throws TransactionException {
100       try {
101          clear();
102          transaction.release();
103          if (DODSTransactionFactory._debug_) {
104             synchronized (SharkDODSTransaction.class) {
105                noOfReleases++;
106                System.out.println("RELEASE T "+noOfReleases);
107             }
108          }
109       } catch (Exception JavaDoc ex) {
110          if (DODSTransactionFactory._debug_) {
111             System.out.println("RELEASE FAILED");
112          }
113          throw new TransactionException(ex);
114       } finally {
115          processes.clear();
116          resources.clear();
117       }
118    }
119
120    public static synchronized void info () {
121       if (noOfCreations != noOfReleases) {
122          System.err.println("PANIC!!!\nI've lost transcaton counts.");
123       }
124       System.err.println("CRE="+noOfCreations+", COMM="+noOfCommits+", ROLL="+noOfRollbacks+", REL="+noOfReleases);
125    }
126
127    public void addToTransaction (String JavaDoc procId,WfProcessInternal proc) throws RootException {
128       processes.put(procId,proc);
129    }
130
131    public void addToTransaction (String JavaDoc resUname,WfResourceInternal res) throws RootException {
132       resources.put(resUname,res);
133    }
134
135    public void removeProcess (String JavaDoc procId) throws RootException {
136       processes.remove(procId);
137    }
138
139    public void removeResource (String JavaDoc resUname) throws RootException {
140       resources.remove(resUname);
141    }
142
143    public WfProcessInternal getProcess (String JavaDoc procId) throws RootException {
144       return (WfProcessInternal)processes.get(procId);
145    }
146
147    public WfResourceInternal getResource (String JavaDoc resUname) throws RootException {
148       return (WfResourceInternal)resources.get(resUname);
149    }
150
151
152 }
153 /* End of SharkDODSTransaction.java */
154
155
156
Popular Tags