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 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 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 } 33 this.transaction=transaction; 34 } 35 36 41 public DBTransaction getDODSTransaction () { 42 return transaction; 43 } 44 45 50 public void commit () throws TransactionException { 51 if (DODSUserTransactionFactory._debug_) { 52 synchronized (SharkDODSUserTransaction.class) { 53 System.out.println("COMMITING User T "); 54 } 55 } 57 try { 58 transaction.commit(); 59 if (DODSUserTransactionFactory._debug_) { 61 synchronized (SharkDODSUserTransaction.class) { 62 noOfCommits++; 63 System.out.println("COMMITED User T No"+noOfCommits); 64 } 65 } 67 } catch (Exception ex) { 68 throw new TransactionException(ex); 69 } 70 } 71 72 77 public void rollback () throws TransactionException { 78 try { 79 if (DODSUserTransactionFactory._debug_) { 82 synchronized (SharkDODSUserTransaction.class) { 83 noOfRollbacks++; 84 System.out.println("ROLLING BACK User T"+noOfRollbacks); 85 } 86 } 88 89 } catch (Exception ex) { 90 if (DODSUserTransactionFactory._debug_) { 91 System.out.println("ROLLING BACK FAILED"); 92 } 93 throw new TransactionException(ex); 94 } 95 } 96 97 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 ex) { 112 if (DODSUserTransactionFactory._debug_) { 113 System.out.println("RELEASE User T FAILED"); 114 } 115 throw new TransactionException(ex); 116 } 117 } 118 119 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 |