KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > repositorypersistence > DODSRepositoryTransaction


1 package org.enhydra.shark.repositorypersistence;
2
3 import org.enhydra.shark.api.*;
4 import com.lutris.appserver.server.sql.DBTransaction;
5
6
7 /**
8  * Implementation of RepositoryTransaction interface
9  * @author Sasa Bojanic
10  */

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