1 22 23 package org.jboss.resource.connectionmanager.xa; 24 25 import java.io.Serializable ; 26 27 import javax.transaction.xa.XAException ; 28 import javax.transaction.xa.XAResource ; 29 import javax.transaction.xa.Xid ; 30 31 import org.jboss.logging.Logger; 32 33 39 public class XAResourceWrapper implements XAResource , Serializable 40 { 41 42 43 private static final long serialVersionUID = 4551722165222496828L; 44 45 private static final Logger log = Logger.getLogger(XAResourceWrapper.class); 46 47 48 private XAResource xaResource; 49 50 private boolean pad; 51 52 private Boolean overrideRmValue; 53 54 public XAResourceWrapper(XAResource resource) 55 { 56 this(Boolean.FALSE, false, resource); 57 58 } 59 60 public XAResourceWrapper(boolean pad, XAResource resource) 61 { 62 this(Boolean.FALSE, pad, resource); 63 } 64 65 public XAResourceWrapper(Boolean override, boolean pad, XAResource resource) 66 { 67 this.overrideRmValue = override; 68 this.pad = pad; 69 this.xaResource = resource; 70 71 } 72 73 public void commit(Xid xid, boolean onePhase) throws XAException 74 { 75 xid = convertXid(xid); 76 xaResource.commit(xid, onePhase); 77 } 78 79 public void end(Xid xid, int flags) throws XAException 80 { 81 xid = convertXid(xid); 82 xaResource.end(xid, flags); 83 84 } 85 86 public void forget(Xid xid) throws XAException 87 { 88 xid = convertXid(xid); 89 xaResource.forget(xid); 90 } 91 92 public int getTransactionTimeout() throws XAException 93 { 94 return xaResource.getTransactionTimeout(); 95 } 96 97 public boolean isSameRM(XAResource resource) throws XAException 98 { 99 100 if (overrideRmValue != null) 101 { 102 if(log.isTraceEnabled()) 103 { 104 log.trace("Executing isSameRM with override value" + overrideRmValue + " for XAResourceWrapper" + this); 105 106 } 107 108 return overrideRmValue.booleanValue(); 109 110 } 111 else 112 { 113 if(resource instanceof XAResourceWrapper) 114 { 115 XAResourceWrapper other = (XAResourceWrapper)resource; 116 return xaResource.isSameRM(other.getResource()); 117 118 }else 119 { 120 return xaResource.isSameRM(resource); 121 122 } 123 124 } 125 126 } 127 128 public int prepare(Xid xid) throws XAException 129 { 130 xid = convertXid(xid); 131 return xaResource.prepare(xid); 132 } 133 134 public Xid [] recover(int flag) throws XAException 135 { 136 137 return xaResource.recover(flag); 138 } 139 140 public void rollback(Xid xid) throws XAException 141 { 142 xid = convertXid(xid); 143 xaResource.rollback(xid); 144 } 145 146 public boolean setTransactionTimeout(int flag) throws XAException 147 { 148 return xaResource.setTransactionTimeout(flag); 149 150 } 151 152 public void start(Xid xid, int flags) throws XAException 153 { 154 xid = convertXid(xid); 155 xaResource.start(xid, flags); 156 } 157 158 private Xid convertXid(Xid xid) 159 { 160 161 if (xid instanceof JcaXid) 162 return xid; 163 164 else 165 return new JcaXid(pad, xid); 166 167 } 168 169 private XAResource getResource() 170 { 171 return xaResource; 172 } 173 174 public String toString() 175 { 176 return super.toString(); 177 } 178 179 } 180 | Popular Tags |