KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > usertransaction > SharkDODSUserTransaction


1 package org.enhydra.shark.usertransaction;
2
3 import org.enhydra.shark.api.UserTransaction;
4 import org.enhydra.shark.api.TransactionException;
5 import com.lutris.appserver.server.sql.DBTransaction;
6
7 /**
8  * Implementation of UserTransaction interface that creates DODS transaction.
9  * @author Tanja Jovanovic
10  */

11 public class SharkDODSUserTransaction implements UserTransaction {
12
13    private static int noOfCreations=0;
14    private static int noOfCommits=0;
15    private static int noOfRollbacks=0;
16    private static int noOfReleases=0;
17
18    private DBTransaction transaction;
19
20    /**
21     * Creates user transaction.
22     *
23     * @param transaction transaction.
24     */

25    public SharkDODSUserTransaction (DBTransaction transaction) {
26       if (DODSUserTransactionFactory._debug_) {
27          synchronized (SharkDODSUserTransaction.class) {
28             noOfCreations++;
29             System.out.println("CREATING User T No"+noOfCreations);
30          }
31          //Thread.dumpStack();
32
}
33       this.transaction=transaction;
34    }
35
36    /**
37     * Returns DODS user transaction.
38     *
39     * @return DODS user transaction.
40     */

41    public DBTransaction getDODSTransaction () {
42       return transaction;
43    }
44
45    /**
46     * Commits DODS user transaction.
47     *
48     * @exception TransactionException If something unexpected happens.
49     */

50    public void commit () throws TransactionException {
51       if (DODSUserTransactionFactory._debug_) {
52          synchronized (SharkDODSUserTransaction.class) {
53             System.out.println("COMMITING User T ");
54          }
55          //Thread.dumpStack();
56
}
57       try {
58          transaction.commit();
59          //transaction.release();
60
if (DODSUserTransactionFactory._debug_) {
61             synchronized (SharkDODSUserTransaction.class) {
62                noOfCommits++;
63                System.out.println("COMMITED User T No"+noOfCommits);
64             }
65             //Thread.dumpStack();
66
}
67       } catch (Exception JavaDoc ex) {
68          throw new TransactionException(ex);
69       }
70    }
71
72    /**
73     * Rollbacks DODS user transaction.
74     *
75     * @exception TransactionException If something unexpected happens.
76     */

77    public void rollback () throws TransactionException {
78       try {
79          //transaction.rollback();
80
//transaction.release();
81
if (DODSUserTransactionFactory._debug_) {
82             synchronized (SharkDODSUserTransaction.class) {
83                noOfRollbacks++;
84                System.out.println("ROLLING BACK User T"+noOfRollbacks);
85             }
86             //Thread.dumpStack();
87
}
88
89       } catch (Exception JavaDoc ex) {
90          if (DODSUserTransactionFactory._debug_) {
91             System.out.println("ROLLING BACK FAILED");
92          }
93          throw new TransactionException(ex);
94       }
95    }
96
97    /**
98     * Releases DODS user transaction.
99     *
100     * @exception TransactionException If something unexpected happens.
101     */

102    public void release() throws TransactionException {
103       try {
104          transaction.release();
105          if (DODSUserTransactionFactory._debug_) {
106             synchronized (SharkDODSUserTransaction.class) {
107                noOfReleases++;
108                System.out.println("RELEASE User T "+noOfReleases);
109             }
110          }
111       } catch (Exception JavaDoc ex) {
112          if (DODSUserTransactionFactory._debug_) {
113             System.out.println("RELEASE User T FAILED");
114          }
115          throw new TransactionException(ex);
116       }
117    }
118
119    /**
120     * Writes info about DODS user transaction.
121     */

122    public static synchronized void info () {
123       if (noOfCreations != noOfReleases) {
124          System.err.println("PANIC!!!\nI've lost user transaction counts.");
125       }
126       System.err.println("UTCRE="+noOfCreations+", UTCOMM="+noOfCommits+", UTROLL="+noOfRollbacks+", UTREL="+noOfReleases);
127    }
128 }
129
Popular Tags