1 23 24 package com.sun.enterprise.resource; 25 26 import javax.transaction.xa.*; 27 import java.util.logging.*; 28 import com.sun.logging.*; 29 30 38 public class XAResourceWrapper implements XAResource { 39 40 private XAResource res; 42 43 public XAResourceWrapper(XAResource res) { 44 this.res = res; 45 } 46 47 50 static Logger _logger = null; 51 static{ 52 _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 53 } 54 55 public void commit(Xid xid, boolean onePhase) throws XAException { 56 print("XAResource.commit: " + xidToString(xid) + "," + onePhase); 57 res.commit(xid, onePhase); 58 } 59 60 public void end(Xid xid, int flags) throws XAException { 61 print("XAResource.end: " + xidToString(xid) + "," + 62 flagToString(flags)); 63 res.end(xid, flags); 64 } 65 66 67 public void forget(Xid xid) throws XAException { 68 print("XAResource.forget: " + xidToString(xid)); 69 res.forget(xid); 70 } 71 72 public int getTransactionTimeout() throws XAException { 73 return res.getTransactionTimeout(); 74 } 75 76 public boolean isSameRM(XAResource xares) throws XAException { 77 if (xares instanceof XAResourceWrapper) { 78 XAResourceWrapper other = (XAResourceWrapper) xares; 79 boolean result = res.isSameRM(other.res); 80 print("XAResource.isSameRM: " + res + "," + other.res + "," + 81 result); 82 return result; 83 } else { 84 boolean result = res.isSameRM(xares); 85 print("XAResource.isSameRM: " + res + "," + xares + "," + 86 result); 87 return result; 88 } 90 } 91 92 public int prepare(Xid xid) throws XAException { 93 print("XAResource.prepare: " + xidToString(xid)); 94 int result = res.prepare(xid); 95 print("prepare result = " + flagToString(result)); 96 return result; 97 } 98 99 public Xid[] recover(int flag) throws XAException { 100 print("XAResource.recover: " + flagToString(flag)); 101 return res.recover(flag); 102 } 103 104 public void rollback(Xid xid) throws XAException { 105 print("XAResource.rollback: " + xidToString(xid)); 106 res.rollback(xid); 107 } 108 109 public boolean setTransactionTimeout(int seconds) throws XAException { 110 return res.setTransactionTimeout(seconds); 111 } 112 113 public void start(Xid xid, int flags) throws XAException { 114 print("XAResource.start: " + xidToString(xid) + "," + 115 flagToString(flags)); 116 res.start(xid, flags); 117 } 118 119 private void print(String s) { 120 _logger.log(Level.FINE,s); 121 } 122 123 static public String xidToString(Xid xid) { 124 return String.valueOf((new String (xid.getGlobalTransactionId()) + 125 new String (xid.getBranchQualifier())).hashCode()); 126 } 127 128 static public String flagToString(int flag) { 129 switch (flag) { 130 case TMFAIL: 131 return "TMFAIL"; 132 case TMJOIN: 133 return "TMJOIN"; 134 case TMNOFLAGS: 135 return "TMNOFLAGS"; 136 case TMONEPHASE: 137 return "TMONEPHASE"; 138 case TMRESUME: 139 return "TMRESUME"; 140 case TMSTARTRSCAN: 141 return "TMSTARTRSCAN"; 142 case TMENDRSCAN: 143 return "TMENDRSCAN"; 144 case TMSUCCESS: 145 return "TMSUCCESS"; 146 case TMSUSPEND: 147 return "TMSUSPEND"; 148 case XA_RDONLY: 149 return "XA_RDONLY"; 150 default: 151 return "" + Integer.toHexString(flag); 152 } 153 } 154 155 public boolean equals(Object obj) { 156 if (this == obj) return true; 157 if (obj == null) return false; 158 if (obj instanceof XAResourceWrapper) { 159 XAResource other = ((XAResourceWrapper) obj).res; 160 return res.equals(other); 161 } 162 if (obj instanceof XAResource) { 163 XAResource other = (XAResource) obj; 164 return res.equals(other); 165 } 166 return false; 167 } 168 169 public int hashCode() { 170 return res.hashCode(); 171 } 172 } 173 | Popular Tags |