1 22 package org.jboss.tm.iiop.wrapper; 23 24 import java.rmi.RemoteException ; 25 26 import javax.transaction.HeuristicCommitException ; 27 import javax.transaction.HeuristicMixedException ; 28 import javax.transaction.HeuristicRollbackException ; 29 30 import org.jboss.iiop.CorbaORB; 31 import org.jboss.tm.remoting.interfaces.HeuristicHazardException; 32 import org.jboss.tm.remoting.interfaces.Resource; 33 import org.jboss.tm.remoting.interfaces.TransactionNotPreparedException; 34 import org.jboss.tm.remoting.interfaces.TransactionAlreadyPreparedException; 35 import org.jboss.tm.remoting.interfaces.Vote; 36 37 38 46 public class OTSResourceWrapper implements Resource 47 { 48 50 53 private org.omg.CosTransactions.Resource otsResource; 54 55 57 61 public OTSResourceWrapper(org.omg.CosTransactions.Resource otsResource) 62 { 63 this.otsResource = otsResource; 64 } 65 66 68 public org.omg.CosTransactions.Resource getWrappedResource() 69 { 70 return otsResource; 71 } 72 73 75 public String toString() 76 { 77 return CorbaORB.getInstance().object_to_string(otsResource); 78 } 79 80 82 public static OTSResourceWrapper fromString(String s) 83 { 84 org.omg.CORBA.Object obj = CorbaORB.getInstance().string_to_object(s); 85 org.omg.CosTransactions.Resource otsRes = 86 org.omg.CosTransactions.ResourceHelper.narrow(obj); 87 return new OTSResourceWrapper(otsRes); 88 } 89 90 92 96 public Vote prepare() 97 throws RemoteException , 98 TransactionAlreadyPreparedException, 99 HeuristicMixedException , 100 HeuristicHazardException 101 { 102 try 103 { 104 org.omg.CosTransactions.Vote otsVote = otsResource.prepare(); 105 if (otsVote == org.omg.CosTransactions.Vote.VoteCommit) 106 return Vote.COMMIT; 107 else if (otsVote == org.omg.CosTransactions.Vote.VoteReadOnly) 108 return Vote.READONLY; 109 else return Vote.ROLLBACK; 111 } 112 catch (org.omg.CosTransactions.HeuristicMixed hm) 113 { 114 throw new HeuristicMixedException (); 115 } 116 catch (org.omg.CosTransactions.HeuristicHazard hz) 117 { 118 throw new HeuristicHazardException(); 119 } 120 catch (org.omg.CORBA.BAD_INV_ORDER bio) 121 { 122 throw new TransactionAlreadyPreparedException(); 123 } 124 catch (org.omg.CORBA.SystemException se) 125 { 126 throw javax.rmi.CORBA.Util.mapSystemException(se); 127 } 128 } 129 130 134 public void rollback() 135 throws RemoteException , 136 HeuristicCommitException , 137 HeuristicMixedException , 138 HeuristicHazardException 139 { 140 try 141 { 142 otsResource.rollback(); 143 } 144 catch (org.omg.CosTransactions.HeuristicCommit hc) 145 { 146 throw new HeuristicCommitException (); 147 } 148 catch (org.omg.CosTransactions.HeuristicMixed hm) 149 { 150 throw new HeuristicMixedException (); 151 } 152 catch (org.omg.CosTransactions.HeuristicHazard hz) 153 { 154 throw new HeuristicHazardException(); 155 } 156 catch (org.omg.CORBA.SystemException se) 157 { 158 throw javax.rmi.CORBA.Util.mapSystemException(se); 159 } 160 } 161 162 166 public void commit() throws RemoteException , 167 TransactionNotPreparedException, HeuristicRollbackException , 168 HeuristicMixedException , HeuristicHazardException 169 { 170 try 171 { 172 otsResource.commit(); 173 } 174 catch (org.omg.CosTransactions.NotPrepared np) 175 { 176 throw new TransactionNotPreparedException(); 177 } 178 catch (org.omg.CosTransactions.HeuristicRollback hr) 179 { 180 throw new HeuristicRollbackException (); 181 } 182 catch (org.omg.CosTransactions.HeuristicMixed hm) 183 { 184 throw new HeuristicMixedException (); 185 } 186 catch (org.omg.CosTransactions.HeuristicHazard hz) 187 { 188 throw new HeuristicHazardException(); 189 } 190 catch (org.omg.CORBA.SystemException se) 191 { 192 throw javax.rmi.CORBA.Util.mapSystemException(se); 193 } 194 } 195 196 200 public void commitOnePhase() throws RemoteException , 201 HeuristicHazardException 202 { 203 try 204 { 205 otsResource.commit_one_phase(); 206 } 207 catch (org.omg.CosTransactions.HeuristicHazard hz) 208 { 209 throw new HeuristicHazardException(); 210 } 211 catch (org.omg.CORBA.SystemException se) 212 { 213 throw javax.rmi.CORBA.Util.mapSystemException(se); 214 } 215 } 216 217 221 public void forget() throws RemoteException 222 { 223 try 224 { 225 otsResource.forget(); 226 } 227 catch (org.omg.CORBA.SystemException se) 228 { 229 throw javax.rmi.CORBA.Util.mapSystemException(se); 230 } 231 } 232 233 } 234 | Popular Tags |