KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > partmappersistence > DODSParticipantMappingTransaction


1 /*
2  * DODSParticipantMappingTransaction.java. Created on Apr 29, 2004.
3  */

4 package org.enhydra.shark.partmappersistence;
5
6 import org.enhydra.shark.api.ParticipantMappingTransaction;
7 import org.enhydra.shark.api.TransactionException;
8
9 import com.lutris.appserver.server.sql.DBTransaction;
10
11 /**
12  * Implementation of ParticipantMappingTransaction.
13  *
14  * @author Zoran Milakovic
15  */

16 public class DODSParticipantMappingTransaction implements ParticipantMappingTransaction {
17
18    private static int noOfCreations=0;
19    private static int noOfCommits=0;
20    private static int noOfRollbacks=0;
21    private static int noOfReleases=0;
22
23    private DBTransaction transaction;
24
25    public DODSParticipantMappingTransaction (DBTransaction transaction) {
26       if (DODSParticipantMappingMgr._debug_) {
27          synchronized (DODSParticipantMappingTransaction.class) {
28             noOfCreations++;
29             System.out.println("CREATING Mapping T No"+noOfCreations);
30          }
31          //Thread.dumpStack();
32
}
33       this.transaction=transaction;
34    }
35
36    public DBTransaction getDODSTransaction () {
37       return transaction;
38    }
39
40    public void commit () throws TransactionException {
41       if (DODSParticipantMappingMgr._debug_) {
42          synchronized (DODSParticipantMappingTransaction.class) {
43             System.out.println("COMMITING Mapping T ");
44          }
45          //Thread.dumpStack();
46
}
47       try {
48          transaction.commit();
49          //transaction.release();
50
if (DODSParticipantMappingMgr._debug_) {
51             synchronized (DODSParticipantMappingTransaction.class) {
52                noOfCommits++;
53                System.out.println("COMMITED Mapping T No"+noOfCommits);
54             }
55             //Thread.dumpStack();
56
}
57       } catch (Exception JavaDoc ex) {
58          throw new TransactionException(ex);
59       }
60    }
61
62    public void rollback () throws TransactionException {
63       try {
64          //transaction.rollback();
65
//transaction.release();
66
if (DODSParticipantMappingMgr._debug_) {
67             synchronized (DODSParticipantMappingTransaction.class) {
68                noOfRollbacks++;
69                System.out.println("ROLLING BACK Mapping T"+noOfRollbacks);
70             }
71             //Thread.dumpStack();
72
}
73       } catch (Exception JavaDoc ex) {
74          if (DODSParticipantMappingMgr._debug_) {
75             System.out.println("ROLLING BACK Mapping T FAILED");
76          }
77          throw new TransactionException(ex);
78       }
79    }
80
81    public void release() throws TransactionException {
82       try {
83          transaction.release();
84          if (DODSParticipantMappingMgr._debug_) {
85             synchronized (DODSParticipantMappingTransaction.class) {
86                noOfReleases++;
87                System.out.println("RELEASE Mapping T "+noOfReleases);
88             }
89          }
90       } catch (Exception JavaDoc ex) {
91          if (DODSParticipantMappingMgr._debug_) {
92             System.out.println("RELEASE Mapping T FAILED");
93          }
94          throw new TransactionException(ex);
95       }
96    }
97
98
99    public static synchronized void info () {
100       if (noOfCreations != noOfReleases) {
101          System.err.println("PANIC!!!\nI've lost mapping transcaton counts.");
102       }
103       System.err.println("MTCRE="+noOfCreations+", MTCOMM="+noOfCommits+", MTROLL="+noOfRollbacks+", MTREL="+noOfReleases);
104    }
105
106 }
107
Popular Tags