KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > scriptmappersistence > DODSScriptMappingTransaction


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

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

16 public class DODSScriptMappingTransaction implements ScriptMappingTransaction {
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 DODSScriptMappingTransaction (DBTransaction transaction) {
26       if (DODSScriptMappingMgr._debug_) {
27          synchronized (DODSScriptMappingTransaction.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 (DODSScriptMappingMgr._debug_) {
42          synchronized (DODSScriptMappingTransaction.class) {
43             System.out.println("COMMITING Mapping T ");
44          }
45          //Thread.dumpStack();
46
}
47       try {
48          transaction.commit();
49          //transaction.release();
50
if (DODSScriptMappingMgr._debug_) {
51             synchronized (DODSScriptMappingTransaction.class) {
52                noOfCommits++;
53                System.out.println("COMMITED Mapping T No"+noOfCommits);
54             }
55             //Thread.dumpStack();
56
}
57       } catch (Exception JavaDoc ex) {
58          ex.printStackTrace();
59          throw new TransactionException(ex);
60       }
61    }
62
63    public void rollback () throws TransactionException {
64       try {
65          //transaction.rollback();
66
//transaction.release();
67
if (DODSScriptMappingMgr._debug_) {
68             synchronized (DODSScriptMappingTransaction.class) {
69                noOfRollbacks++;
70                System.out.println("ROLLING BACK Mapping T"+noOfRollbacks);
71             }
72             //Thread.dumpStack();
73
}
74       } catch (Exception JavaDoc ex) {
75          if (DODSScriptMappingMgr._debug_) {
76             System.out.println("ROLLING BACK Mapping T FAILED");
77          }
78          throw new TransactionException(ex);
79       }
80    }
81
82    public void release() throws TransactionException {
83       try {
84          transaction.release();
85          if (DODSScriptMappingMgr._debug_) {
86             synchronized (DODSScriptMappingTransaction.class) {
87                noOfReleases++;
88                System.out.println("RELEASE Mapping T "+noOfReleases);
89             }
90          }
91       } catch (Exception JavaDoc ex) {
92          if (DODSScriptMappingMgr._debug_) {
93             System.out.println("RELEASE Mapping T FAILED");
94          }
95          throw new TransactionException(ex);
96       }
97    }
98
99
100    public static synchronized void info () {
101       if (noOfCommits + noOfRollbacks + noOfReleases != noOfCreations) {
102          System.err.println("PANIC!!!\nI've lost mapping transcaton counts.");
103       }
104       System.err.println("MTCRE="+noOfCreations+", MTCOMM="+noOfCommits+", MTROLL="+noOfRollbacks+", MTREL="+noOfReleases);
105    }
106
107 }
108
Popular Tags