1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import org.omg.CORBA.*; 55 import org.omg.CosTransactions.*; 56 import com.sun.jts.trace.*; 57 import java.util.logging.Logger ; 58 import java.util.logging.Level ; 59 import com.sun.logging.LogDomains; 60 import com.sun.jts.utils.LogFormatter; 61 62 72 79 class CoordinatorTerm implements CompletionHandler { 80 private CoordinatorImpl coordinator = null; 81 private boolean subtransaction = false; 82 private boolean aborted = false; 83 private boolean heuristicDamage = false; 84 private boolean completed = false; 85 private boolean completing = false; 86 87 90 91 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 92 93 101 CoordinatorTerm() { 102 } 103 104 120 CoordinatorTerm( CoordinatorImpl coord, 121 boolean subtran ) { 122 123 125 coordinator = coord; 126 subtransaction = subtran; 127 128 131 if( coordinator != null ) 132 coordinator.setTerminator(this); 133 134 } 135 136 144 public void finalize() { 145 146 149 if( !completed ) { 150 completing = true; 151 try { 152 coordinator.rollback(true); 153 } catch( Throwable exc ) { 154 } 155 if( !subtransaction ) 156 ((TopCoordinator)coordinator).afterCompletion(Status.StatusRolledBack); 157 } 158 159 coordinator = null; 160 161 } 162 163 192 void commit( boolean promptReturn ) 193 throws HeuristicMixed, HeuristicHazard, TRANSACTION_ROLLEDBACK, 194 SystemException, LogicErrorException { 195 196 boolean commit_one_phase_worked_ok = false; 199 200 204 if( aborted ) { 205 throw new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 206 } 207 208 210 if( coordinator == null ) { 211 String msg = LogFormatter.getLocalizedMessage(_logger, 212 "jts.no_coordinator_available"); 213 LogicErrorException exc = 214 new LogicErrorException(msg); 215 throw exc; 216 } 217 218 221 completing = true; 222 223 226 ControlImpl current = CurrentTransaction.getCurrent(); 227 ControlImpl establishedControl = null; 228 Coordinator currentCoord = null; 229 boolean sameCoordinator = false; 230 231 if( current != null ) 232 try { 233 if (Configuration.isLocalFactory()) { 234 currentCoord = current.get_localCoordinator(); 235 } else { 236 currentCoord = current.get_coordinator(); 237 } 238 239 sameCoordinator = coordinator.is_same_transaction(currentCoord); 240 } catch( Unavailable exc ) {} 241 242 248 if( !subtransaction ) { 249 try { 250 if( current == null || 251 !sameCoordinator ) { 252 establishedControl = new ControlImpl(null,coordinator, 253 new GlobalTID(coordinator.getGlobalTID()), 254 new Long (coordinator.getLocalTID())); 255 CurrentTransaction.setCurrent(establishedControl,true); 256 } 257 } catch( Throwable exc ) { 258 } 259 260 262 try { 263 ((TopCoordinator)coordinator).beforeCompletion(); 264 } 265 266 268 catch( SystemException exc ) { 269 completing = false; 270 throw exc; 271 } 272 273 275 finally { 276 if( establishedControl != null ) { 277 CurrentTransaction.endCurrent(true); 278 establishedControl.finalize(); 279 } 280 } 281 } 282 283 288 Status status = Status.StatusCommitted; 289 if( sameCoordinator ) 290 CurrentTransaction.endCurrent(true); 291 292 293 295 Throwable heuristicExc = null; 296 297 301 try { 302 commit_one_phase_worked_ok = coordinator.commitOnePhase(); 303 } catch( Throwable exc ) { 304 305 if( exc instanceof HeuristicHazard || 306 exc instanceof HeuristicMixed ) { 307 heuristicExc = exc; 308 } else if( exc instanceof TRANSACTION_ROLLEDBACK ) { 309 status = Status.StatusRolledBack; 310 } else if( exc instanceof INVALID_TRANSACTION ) { 311 throw (INVALID_TRANSACTION)exc; 313 } if (exc instanceof INTERNAL) { 314 throw (INTERNAL) exc; 317 }else { 318 } 319 } 320 321 if( commit_one_phase_worked_ok ) { 322 status = Status.StatusCommitted; 329 } else if (status != Status.StatusRolledBack) { 332 Vote prepareResult = Vote.VoteRollback; 334 335 try { 336 prepareResult = coordinator.prepare(); 337 } catch( HeuristicHazard exc ) { 338 heuristicExc = exc; 339 } catch( HeuristicMixed exc ) { 340 heuristicExc = exc; 341 } catch( INVALID_TRANSACTION exc ) { 342 throw exc; 343 } catch( Throwable exc ) { 344 } 345 346 if( subtransaction ) { 347 349 if( prepareResult == Vote.VoteCommit ) 350 try { 351 352 if(_logger.isLoggable(Level.FINE)) 353 { 354 _logger.logp(Level.FINE,"CoordinatorTerm","commit()", 355 "Before invoking coordinator.commit() :"+"GTID is: "+ 356 ((TopCoordinator)coordinator).superInfo.globalTID.toString()); 357 358 } 359 coordinator.commit(); 360 } catch( NotPrepared exc ) { 361 prepareResult = Vote.VoteRollback; 362 } 363 364 if( prepareResult == Vote.VoteRollback ) { 365 if(_logger.isLoggable(Level.FINE)) 366 { 367 _logger.logp(Level.FINE,"CoordinatorTerm","commit()", 368 "Before invoking coordinator.rollback :"+ 369 "GTID is : "+ 370 ((TopCoordinator)coordinator).superInfo.globalTID.toString()); 371 } 372 coordinator.rollback(true); 373 status = Status.StatusRolledBack; 374 } 375 } 376 377 379 else { 380 381 383 385 try { 386 if( prepareResult == Vote.VoteCommit ) 387 try { 388 coordinator.commit(); 389 } catch( NotPrepared exc ) { 390 prepareResult = Vote.VoteRollback; 391 } 392 393 if( prepareResult == Vote.VoteRollback && heuristicExc == null ) { 394 status = Status.StatusRolledBack; coordinator.rollback(true); } 397 } catch( Throwable exc ) { 398 if (exc instanceof HeuristicHazard || 399 exc instanceof HeuristicMixed) { 400 heuristicExc = exc; 401 } 402 403 if (exc instanceof INTERNAL) { 406 throw (INTERNAL) exc; 407 } 408 } 409 410 411 } 413 } 415 if( !subtransaction ) { 418 ((TopCoordinator)coordinator).afterCompletion(status); 419 } 420 421 423 completed = true; 424 if( current != null && sameCoordinator ) 425 current.setTranState(status); 426 427 429 if( heuristicExc != null ) { 430 if( heuristicExc instanceof HeuristicMixed ) 431 throw (HeuristicMixed)heuristicExc; 432 else 433 throw (HeuristicHazard)heuristicExc; 434 } 435 436 438 if( status == Status.StatusRolledBack ) { 439 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_YES); 440 throw exc; 441 } 442 443 } 444 445 464 void rollback() 465 throws HeuristicMixed, HeuristicHazard, SystemException, 466 LogicErrorException { 467 468 472 if( aborted ) { 473 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO); 474 throw exc; 475 } 476 477 479 if( coordinator == null ) { 480 String msg = LogFormatter.getLocalizedMessage(_logger, 481 "jts.no_coordinator_available"); 482 483 LogicErrorException exc = 484 new LogicErrorException(msg); 485 throw exc; 486 } 487 488 491 Coordinator currentCoord = null; 492 ControlImpl current = null; 493 494 completing = true; 495 496 499 try { 500 current = CurrentTransaction.getCurrent(); 501 } catch( Throwable exc ) {} 502 503 if( current != null ) 504 try { 505 if (Configuration.isLocalFactory()) { 506 currentCoord = current.get_localCoordinator(); 507 } else { 508 currentCoord = current.get_coordinator(); 509 } 510 511 if( coordinator.is_same_transaction(currentCoord) ) 512 CurrentTransaction.endCurrent(true); 513 } 514 515 519 catch( Throwable exc ) { 520 CurrentTransaction.endCurrent(true); 521 } 522 523 525 Throwable heuristicExc = null; 526 try { 527 coordinator.rollback(true); 528 } 529 catch (Throwable exc) { 530 if (exc instanceof HeuristicHazard || 531 exc instanceof HeuristicMixed) { 532 heuristicExc = exc; 533 } 534 535 if (exc instanceof INTERNAL) { 537 throw (INTERNAL) exc; 538 } 539 } finally { 540 if( !subtransaction ) 541 ((TopCoordinator)coordinator).afterCompletion(Status.StatusRolledBack); 542 } 543 544 546 completed = true; 547 if( current != null ) 548 current.setTranState(Status.StatusRolledBack); 549 550 552 if( heuristicExc != null ) { 553 if( heuristicExc instanceof HeuristicMixed ) 554 throw (HeuristicMixed)heuristicExc; 555 else 556 throw (HeuristicHazard)heuristicExc; 557 } 558 559 561 } 562 563 582 583 public void setCompleted( boolean aborted, 584 boolean heuristicDamage ) { 585 586 589 if( !completing ) { 590 591 595 598 completed = true; 599 this.aborted = aborted; 600 this.heuristicDamage = heuristicDamage; 601 602 if( coordinator == null ) { 603 } else if( !subtransaction ) 604 ((TopCoordinator)coordinator).afterCompletion(Status.StatusRolledBack); 605 } 606 607 } 608 609 617 void dump() { 618 } 619 620 } 621 622 | Popular Tags |