1 2 3 package org.enhydra.shark.transaction; 4 5 6 7 11 12 import com.lutris.appserver.server.sql.DBTransaction; 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import org.enhydra.shark.api.RootException; 16 import org.enhydra.shark.api.TransactionException; 17 import org.enhydra.shark.api.internal.transaction.SharkInternalTransaction; 18 import org.enhydra.shark.api.internal.working.WfProcessInternal; 19 import org.enhydra.shark.api.internal.working.WfResourceInternal; 20 import org.enhydra.shark.utilities.dods.Buffer; 21 22 public class SharkDODSTransaction extends Buffer implements SharkInternalTransaction { 23 24 private Map processes=new HashMap (); 25 private Map resources=new HashMap (); 26 27 private static int noOfCreations=0; 28 private static int noOfCommits=0; 29 private static int noOfRollbacks=0; 30 private static int noOfReleases=0; 31 32 34 public SharkDODSTransaction (DBTransaction transaction) { 35 super(transaction); 36 if (DODSTransactionFactory._debug_) { 37 synchronized (SharkDODSTransaction.class) { 38 noOfCreations++; 39 System.out.println("CREATING T No"+noOfCreations); 40 } 41 } 43 } 45 46 public DBTransaction getDODSTransaction () { 47 return transaction; 48 } 49 50 public void commit () throws TransactionException { 51 if (DODSTransactionFactory._debug_) { 52 synchronized (SharkDODSTransaction.class) { 53 System.out.println("COMMITING T "); 54 } 55 } 57 try { 58 write(); 59 transaction.commit(); 60 if (DODSTransactionFactory._debug_) { 63 synchronized (SharkDODSTransaction.class) { 64 noOfCommits++; 65 System.out.println("COMMITED T No"+noOfCommits); 66 } 67 } 69 } catch (Exception ex) { 70 throw new TransactionException(ex); 71 } finally { 72 processes.clear(); 73 resources.clear(); 74 } 75 } 76 77 public void rollback () throws TransactionException { 78 try { 79 if (DODSTransactionFactory._debug_) { 82 synchronized (SharkDODSTransaction.class) { 83 noOfRollbacks++; 84 System.out.println("ROLLING BACK T "+noOfRollbacks); 85 } 86 } 88 } catch (Exception ex) { 89 if (DODSTransactionFactory._debug_) { 90 System.out.println("ROLLING BACK FAILED"); 91 } 92 throw new TransactionException(ex); 93 } finally { 94 processes.clear(); 95 resources.clear(); 96 } 97 } 98 99 public void release() throws TransactionException { 100 try { 101 clear(); 102 transaction.release(); 103 if (DODSTransactionFactory._debug_) { 104 synchronized (SharkDODSTransaction.class) { 105 noOfReleases++; 106 System.out.println("RELEASE T "+noOfReleases); 107 } 108 } 109 } catch (Exception ex) { 110 if (DODSTransactionFactory._debug_) { 111 System.out.println("RELEASE FAILED"); 112 } 113 throw new TransactionException(ex); 114 } finally { 115 processes.clear(); 116 resources.clear(); 117 } 118 } 119 120 public static synchronized void info () { 121 if (noOfCreations != noOfReleases) { 122 System.err.println("PANIC!!!\nI've lost transcaton counts."); 123 } 124 System.err.println("CRE="+noOfCreations+", COMM="+noOfCommits+", ROLL="+noOfRollbacks+", REL="+noOfReleases); 125 } 126 127 public void addToTransaction (String procId,WfProcessInternal proc) throws RootException { 128 processes.put(procId,proc); 129 } 130 131 public void addToTransaction (String resUname,WfResourceInternal res) throws RootException { 132 resources.put(resUname,res); 133 } 134 135 public void removeProcess (String procId) throws RootException { 136 processes.remove(procId); 137 } 138 139 public void removeResource (String resUname) throws RootException { 140 resources.remove(resUname); 141 } 142 143 public WfProcessInternal getProcess (String procId) throws RootException { 144 return (WfProcessInternal)processes.get(procId); 145 } 146 147 public WfResourceInternal getResource (String resUname) throws RootException { 148 return (WfResourceInternal)resources.get(resUname); 149 } 150 151 152 } 153 154 155 156 | Popular Tags |