if ( state_.equals ( TxState.HEUR_ABORTED ) )
throw new HeurRollbackException ( getHeuristicMessages () );
if ( xaresource_ == null ) {
Configuration.logWarning ( "XAResourceTransaction " + getXid ()
+ ": no XAResource to commit - the required resource is probably not yet intialized?" );
throw new HeurHazardException ( getHeuristicMessages () );
}
// xaresource is null if recovery failed
// ADDED: to tolerate non-delisting appservers
try {
if ( TxState.ACTIVE.equals ( state_ ) )
suspend ();
} catch ( ResourceException re ) {
// happens if already rolled back or something else;
// in any case the transaction can be trusted to act
// as if rollback already happened
throw new com.atomikos.icatch.RollbackException ( re.getMessage () );
}
if ( !(state_.equals ( TxState.LOCALLY_DONE ) || state_
.equals ( TxState.IN_DOUBT ) || state_.equals ( TxState.HEUR_HAZARD )) )
throw new SysException ( "Wrong state for commit: " + state_ );
try {
// refresh xaresource for MQSeries: seems to close XAResource after
// suspend???
testOrRefreshXAResourceFor2PC ();
printMsg ( "XAResource.commit ( " + xidToHexString (xid_) + " , " + onePhase
+ " ) on resource " + resourcename_
+ " represented by XAResource instance " + xaresource_,
Console.INFO );
xaresource_.commit ( xid_, onePhase );
} catch ( XAException xaerr ) {
String msg = interpretErrorCode ( resourcename_ , "commit" , xid_ , xaerr.errorCode );
Configuration.logWarning ( msg , xaerr );
if ( (XAException.XA_RBBASE <= xaerr.errorCode)
&& (xaerr.errorCode <= XAException.XA_RBEND) ) {
errors.push ( xaerr );
if ( !onePhase )
throw new SysException ( msg , errors );
else
throw new com.atomikos.icatch.RollbackException (
"Already rolled back in resource." );
} else {
switch ( xaerr.errorCode ) {
case XAException.XA_HEURHAZ:
switchToHeuristicState ( "commit" , TxState.HEUR_HAZARD , xaerr );
throw new HeurHazardException ( getHeuristicMessages () );
case XAException.XA_HEURMIX:
switchToHeuristicState ( "commit", TxState.HEUR_MIXED , xaerr );
throw new HeurMixedException ( getHeuristicMessages () );
case XAException.XA_HEURCOM:
forget ();