1 23 24 28 29 package com.sun.jts.jtsxa; 30 31 import org.omg.CosTransactions.*; 32 import org.omg.CORBA.*; 33 import org.omg.PortableServer.*; 34 35 import com.sun.jts.CosTransactions.*; 36 37 import com.sun.jts.jta.*; 38 import javax.transaction.xa.*; 39 import com.sun.jts.jta.TransactionState; 41 42 import java.util.logging.Logger ; 43 import java.util.logging.Level ; 44 import com.sun.logging.LogDomains; 45 import com.sun.jts.utils.LogFormatter; 46 47 50 51 public class OTSResourceImpl extends OTSResourcePOA implements OTSResource { 52 53 private static POA poa = null; 54 private OTSResource thisRef = null; 55 private XAResource xaRes = null; 56 private Xid xid = null; 57 private TransactionState tranState = null; 58 59 60 63 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 64 70 71 public OTSResourceImpl(Xid xid, XAResource xaRes, 72 TransactionState tranState) { 73 this.xaRes= xaRes; this.xid= xid; this.tranState = tranState; 76 } 77 78 94 95 public void commit() throws NotPrepared, HeuristicRollback, 96 HeuristicHazard, HeuristicMixed, SystemException { 97 98 100 try { 101 xaRes.commit(xid, false); 102 } catch (Exception ex) { 103 destroy(); 104 if (!(ex instanceof XAException)) { 105 INTERNAL internal = new INTERNAL(0,CompletionStatus.COMPLETED_MAYBE); 106 internal.initCause(ex); 107 _logger.log(Level.WARNING, "jts.unexpected_error_occurred_twopc_commit", ex); 108 throw internal; 109 } 110 111 XAException e = (XAException) ex; 112 if (_logger.isLoggable(Level.FINE)) 113 _logger.log(Level.FINE, "An XAException occurred in twopc commit", e); 114 if (e.errorCode == XAException.XA_HEURRB) 115 throw new HeuristicRollback(ex.getMessage()); 116 if (e.errorCode == XAException.XA_HEURHAZ) 117 throw new HeuristicHazard(ex.getMessage()); 118 if (e.errorCode == XAException.XA_HEURMIX) 119 throw new HeuristicMixed(ex.getMessage()); 120 if (e.errorCode == XAException.XA_RBPROTO) 121 throw new NotPrepared(ex.getMessage()); 122 if (e.errorCode == XAException.XA_HEURCOM) 123 return; 124 if ((e.errorCode == XAException.XA_RETRY) || 125 (e.errorCode == XAException.XA_RBTRANSIENT) || 126 (e.errorCode == XAException.XA_RBCOMMFAIL)) 127 throw new TRANSIENT(); 128 if (e.errorCode >= XAException.XA_RBBASE && 129 e.errorCode <= XAException.XA_RBEND) { 130 throw new HeuristicRollback(ex.getMessage()); 131 } 132 throw new INTERNAL(0,CompletionStatus.COMPLETED_MAYBE); 133 } 134 135 destroy(); 136 return; 137 } 138 139 148 public void commit_one_phase() throws HeuristicHazard, SystemException { 149 150 152 try { 153 xaRes.commit(xid, true); 154 } catch (Exception ex) { 155 destroy(); 156 if (!(ex instanceof XAException)) { 157 INTERNAL internal = new INTERNAL(0,CompletionStatus.COMPLETED_MAYBE); 158 internal.initCause(ex); 159 _logger.log(Level.WARNING, "jts.unexpected_error_occurred_twopc_commit", ex); 160 throw internal; 161 } 162 XAException e = (XAException) ex; 163 if (_logger.isLoggable(Level.FINE)) 164 _logger.log(Level.FINE, "An XAException occurred in c_o_p", e); 165 if (e.errorCode == XAException.XA_HEURRB) 166 throw new HeuristicHazard(ex.getMessage()); 167 if (e.errorCode == XAException.XA_HEURHAZ) 168 throw new HeuristicHazard(ex.getMessage()); 169 if (e.errorCode == XAException.XA_HEURMIX) 170 throw new HeuristicHazard(ex.getMessage()); 171 177 if (e.errorCode == XAException.XA_HEURCOM) 178 return; 179 if ((e.errorCode == XAException.XA_RETRY) || 180 (e.errorCode == XAException.XA_RBTRANSIENT) || 181 (e.errorCode == XAException.XA_RBCOMMFAIL)) 182 throw new TRANSIENT(); 183 if (e.errorCode >= XAException.XA_RBBASE && 184 e.errorCode <= XAException.XA_RBEND) { 185 HeuristicHazard hazex = new HeuristicHazard(); 186 ((Throwable )hazex).initCause((Throwable )ex); 187 throw hazex; 188 } 189 INTERNAL internal = new INTERNAL(0,CompletionStatus.COMPLETED_MAYBE); 191 internal.initCause(ex); 192 throw internal; 193 } 194 195 destroy(); 196 return; 197 } 198 199 203 public void forget() { 204 205 207 try { 209 xaRes.forget(xid); 210 } catch (XAException e) { 211 if (_logger.isLoggable(Level.FINE)) 212 _logger.log(Level.FINE,"An XAException occurred in forget", e); 213 } 215 216 destroy(); 217 return; 218 } 219 220 232 public Vote prepare() throws HeuristicHazard, HeuristicMixed { 233 234 236 int rc = XAException.XAER_PROTO; 237 238 240 try { 241 rc = xaRes.prepare(xid); } catch (XAException e) { 243 if (_logger.isLoggable(Level.FINE)) 244 _logger.log(Level.FINE,"An XAException occurred in prepare", e); 245 } 247 248 if (rc == XAResource.XA_OK) { 250 return Vote.VoteCommit; 251 } 252 253 if (rc == XAResource.XA_RDONLY) { 254 destroy(); 255 return Vote.VoteReadOnly; 256 } 257 258 if (rc == Configuration.LAO_PREPARE_OK) { 259 destroy(); 260 return null; 261 } 262 263 264 destroy(); 265 return Vote.VoteRollback; } 267 268 282 public void rollback() throws HeuristicCommit, HeuristicMixed, 283 HeuristicHazard, SystemException { 284 285 287 try { 288 if (tranState == null) { 289 xaRes.rollback(xid); 292 } else { 293 tranState.rollback(xaRes); 295 } 296 } catch (Exception ex) { 297 destroy(); 298 if (!(ex instanceof XAException)) { 299 INTERNAL internal = new INTERNAL(0,CompletionStatus.COMPLETED_MAYBE); 300 internal.initCause(ex); 301 _logger.log(Level.WARNING, "jts.unexpected_error_occurred_twopc_rollback", ex); 302 throw internal; 303 } 304 305 XAException e = (XAException) ex; 306 if (_logger.isLoggable(Level.FINE)) 307 _logger.log(Level.FINE, "An XAException occurred in rollback", e); 308 if (e.errorCode == XAException.XA_HEURCOM) 309 throw new HeuristicCommit(ex.getMessage()); 310 if (e.errorCode == XAException.XA_HEURHAZ) 311 throw new HeuristicHazard(ex.getMessage()); 312 if (e.errorCode == XAException.XA_HEURMIX) 313 throw new HeuristicMixed(ex.getMessage()); 314 if (e.errorCode == XAException.XA_HEURCOM) 315 return; 316 if ((e.errorCode == XAException.XA_RETRY) || 317 (e.errorCode == XAException.XA_RBTRANSIENT) || 318 (e.errorCode == XAException.XA_RBCOMMFAIL)) 319 throw new TRANSIENT(); 320 INTERNAL internal = new INTERNAL(0,CompletionStatus.COMPLETED_MAYBE); 321 internal.initCause(ex); 322 throw internal; 323 } 324 325 destroy(); 326 return; 327 } 328 329 336 public otid_t getGlobalTID() { 337 338 byte[] gtrid = xid.getGlobalTransactionId(); 339 byte[] otidData = new byte[gtrid.length]; 340 System.arraycopy(gtrid,0,otidData,0,gtrid.length); 341 otid_t otid = new otid_t(xid.getFormatId(),0,otidData); 342 343 return otid; 344 } 345 346 352 public OTSResource getCORBAObjReference() { 353 354 if (thisRef == null) { 355 if (poa == null) { 356 poa = Configuration.getPOA("transient"); 357 } 358 359 try { 360 poa.activate_object(this); 361 thisRef = OTSResourceHelper. 362 narrow(poa.servant_to_reference(this)); 363 } catch (Exception exc) { 365 _logger.log(Level.SEVERE,"jts.create_xaresource_object_error"); 366 String msg = LogFormatter.getLocalizedMessage(_logger, 367 "jts.create_xaresource_object_error"); 368 throw new org.omg.CORBA.INTERNAL (msg); 369 } 370 } 371 372 return thisRef; 373 } 374 375 381 private void destroy() { 382 383 if (poa != null && thisRef != null) { 384 try { 385 poa.deactivate_object(poa.reference_to_id(thisRef)); 386 thisRef = null; 387 } catch (Exception exc) { 388 _logger.log(Level.WARNING,"jts.object_destroy_error","OTSResource"); 389 } 390 } 391 } 393 394 410 private void ensureInitialized() { 411 425 } 426 427 432 433 private static org.omg.CORBA.NO_IMPLEMENT no_implement = 434 new org.omg.CORBA.NO_IMPLEMENT ("This is a locally constrained object."); 435 436 437 public org.omg.CORBA.Object _duplicate() { 438 throw no_implement; 439 } 440 441 public void _release() { 442 throw no_implement; 443 } 444 445 public boolean _is_a(String repository_id) { 446 throw no_implement; 447 } 448 449 public boolean _is_equivalent(org.omg.CORBA.Object that) { 450 throw no_implement; 451 } 452 453 public boolean _non_existent() { 454 throw no_implement; 455 } 456 457 public int _hash(int maximum) { 458 throw no_implement; 459 } 460 461 public Request _request(String operation) { 462 throw no_implement; 463 } 464 465 public Request _create_request(Context ctx, 466 String operation, 467 NVList arg_list, 468 NamedValue result) { 469 throw no_implement; 470 } 471 472 public Request _create_request(Context ctx, 473 String operation, 474 NVList arg_list, 475 NamedValue result, 476 ExceptionList exceptions, 477 ContextList contexts) { 478 throw no_implement; 479 } 480 481 public org.omg.CORBA.Object _get_interface_def() { 482 throw no_implement; 483 } 484 485 public org.omg.CORBA.Policy _get_policy(int policy_type) { 486 throw no_implement; 487 } 488 489 public org.omg.CORBA.DomainManager [] _get_domain_managers() { 490 throw no_implement; 491 } 492 493 public org.omg.CORBA.Object _set_policy_override( 494 org.omg.CORBA.Policy [] policies, 495 org.omg.CORBA.SetOverrideType set_add) { 496 throw no_implement; 497 } 498 } 499 | Popular Tags |