1 17 18 package org.apache.geronimo.transaction.manager; 19 20 import java.util.HashMap ; 21 import java.util.HashSet ; 22 import java.util.Map ; 23 import java.util.Set ; 24 25 import javax.transaction.SystemException ; 26 import javax.transaction.xa.XAException ; 27 import javax.transaction.xa.XAResource ; 28 import javax.transaction.xa.Xid ; 29 30 35 public class MockResourceManager implements ResourceManager { 36 private boolean willCommit; 37 private Map xids = new HashMap (); 38 39 private NamedXAResource resources; 40 private NamedXAResource returnedResources; 41 42 public MockResourceManager(boolean willCommit) { 43 this.willCommit = willCommit; 44 } 45 46 public MockResource getResource(String xaResourceName) { 47 MockResource mockResource = new MockResource(this, xaResourceName); 48 resources = mockResource; 49 return mockResource; 50 } 51 52 public void join(Xid xid, XAResource xaRes) throws XAException { 53 Set resSet = (Set ) xids.get(xid); 54 if (resSet == null) { 55 throw new XAException (XAException.XAER_NOTA); 56 } 57 resSet.add(xaRes); 58 } 59 60 public void newTx(Xid xid, XAResource xaRes) throws XAException { 61 if (xids.containsKey(xid)) { 62 throw new XAException (XAException.XAER_DUPID); 63 } 64 Set resSet = new HashSet (); 65 resSet.add(xaRes); 66 xids.put(xid, resSet); 67 } 68 69 public void forget(Xid xid, XAResource xaRes) throws XAException { 70 if (xids.remove(xid) == null) { 71 throw new XAException (XAException.XAER_NOTA); 72 } 73 } 74 75 public NamedXAResource getRecoveryXAResources() throws SystemException { 76 return resources; 77 } 78 79 public void returnResource(NamedXAResource xaResource) { 80 returnedResources = xaResource; 81 } 82 83 public boolean areAllResourcesReturned() { 84 return returnedResources != null && returnedResources == resources; 85 } 86 } 87 | Popular Tags |