public int prepare(TxXATerminator xat) throws XAException
    {
        if (tc.isEntryEnabled()) Tr.entry(tc, "prepare", _txn);

        // replay must have finished
        if (_tranManager.isReplayComplete())
        {
            // Suspend local transaction if present
            suspend();

            try
            {
                // Resume imported transaction
                _tranManager.resume(_txn);
            }
            catch (InvalidTransactionException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", new Object[] { "resume threw InvalidTransactionException", e });
                resume();
                throw new XAException(XAException.XAER_RMERR);
            }
            catch (IllegalStateException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", new Object[] { "resume threw IllegalStateException", e });
                resume();
                throw new XAException(XAException.XAER_PROTO);
            }

            // We're going to log the provider that prepares the transaction
            _txn.setJCARecoveryData(xat.getJCARecoveryData());
            
            try
            {
                int state = _txn.internalPrepare();
                switch (state)
                {
                case TransactionState.STATE_PREPARED :
                    // Transaction has prepared and is in doubt
                    _prepared = true;

                    if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "XAResource.XA_OK");
                    return XAResource.XA_OK;

                case TransactionState.STATE_COMMITTED :
                    // Transaction has committed
                    _txn.notifyCompletion();

                    if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "XAResource.XA_RDONLY");
                    return XAResource.XA_RDONLY;

                default :
                    _txn.internalRollback();
                    _txn.notifyCompletion();

                    if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "throwing XA_RBROLLBACK");
                    throw new XAException(XAException.XA_RBROLLBACK);
                }
            }
            catch (HeuristicMixedException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "internalPrepare threw HeuristicMixedException");
                // must rollback any resources now
                try {
                    _txn.internalRollback();
                }
                catch (Throwable t)
                {
                    // swallow any exceptions
                }

                throw new XAException(XAException.XA_HEURMIX);
            }
            catch (HeuristicHazardException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "internalPrepare threw HeuristicHazardException");
                // must rollback any resources now
                try {
                    _txn.internalRollback();
                }
                catch (Throwable t)
                {
                    // swallow any exceptions
                }

                throw new XAException(XAException.XA_HEURHAZ);
            }
            catch (HeuristicRollbackException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "internalPrepare threw HeuristicRollbackException");
                throw new XAException(XAException.XA_HEURRB);
            }
            catch (HeuristicCommitException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "internalPrepare threw HeuristicCommitException");
                throw new XAException(XAException.XA_HEURCOM);
            }
            catch (IllegalStateException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "internalPrepare threw IllegalStateException");
                throw new XAException(XAException.XAER_PROTO);
            }
            catch (SystemException e)
            {
                if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "internalPrepare threw SystemException");
                throw new XAException(XAException.XAER_RMERR);
            }
            finally
            {
                // suspend the imported tran
                _tranManager.suspend();

                // Resume local transaction if we suspended it earlier
                resume();
            }
        }

        if (tc.isEntryEnabled()) Tr.exit(tc, "prepare", "replay not finished");
        throw new XAException(XAException.XAER_RMFAIL);
    }
public int prepare ( TxXATerminator xat ) throws XAException { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "prepare" , _txn ) ; if ( _tranManager . isReplayComplete ( ) ) { suspend ( ) ; try { _tranManager . resume ( _txn ) ; } catch ( InvalidTransactionException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , new Object [ ] { "resume threw InvalidTransactionException" , e } ) ; resume ( ) ; throw new XAException ( XAException . XAER_RMERR ) ; } catch ( IllegalStateException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , new Object [ ] { "resume threw IllegalStateException" , e } ) ; resume ( ) ; throw new XAException ( XAException . XAER_PROTO ) ; } _txn . setJCARecoveryData ( xat . getJCARecoveryData ( ) ) ; try { int state = _txn . internalPrepare ( ) ; switch ( state ) { case TransactionState . STATE_PREPARED : _prepared = true ; if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "XAResource.XA_OK" ) ; return XAResource . XA_OK ; case TransactionState . STATE_COMMITTED : _txn . notifyCompletion ( ) ; if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "XAResource.XA_RDONLY" ) ; return XAResource . XA_RDONLY ; default : _txn . internalRollback ( ) ; _txn . notifyCompletion ( ) ; if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "throwing XA_RBROLLBACK" ) ; throw new XAException ( XAException . XA_RBROLLBACK ) ; } } catch ( HeuristicMixedException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "internalPrepare threw HeuristicMixedException" ) ; try { _txn . internalRollback ( ) ; } catch ( Throwable t ) { } throw new XAException ( XAException . XA_HEURMIX ) ; } catch ( HeuristicHazardException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "internalPrepare threw HeuristicHazardException" ) ; try { _txn . internalRollback ( ) ; } catch ( Throwable t ) { } throw new XAException ( XAException . XA_HEURHAZ ) ; } catch ( HeuristicRollbackException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "internalPrepare threw HeuristicRollbackException" ) ; throw new XAException ( XAException . XA_HEURRB ) ; } catch ( HeuristicCommitException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "internalPrepare threw HeuristicCommitException" ) ; throw new XAException ( XAException . XA_HEURCOM ) ; } catch ( IllegalStateException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "internalPrepare threw IllegalStateException" ) ; throw new XAException ( XAException . XAER_PROTO ) ; } catch ( SystemException e ) { if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "internalPrepare threw SystemException" ) ; throw new XAException ( XAException . XAER_RMERR ) ; } finally { _tranManager . suspend ( ) ; resume ( ) ; } } if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "prepare" , "replay not finished" ) ; throw new XAException ( XAException . XAER_RMFAIL ) ; }
Requests the prepare vote from the object

@return javax.transaction.xa.XAResource.XA_OK or
javax.transaction.xa.XAResource.XA_RDONLY
@exception XAException thrown with the following error codes:
<ul><li>XA_RBROLLBACK - transaction has rolled back</li>
<li>XAER_PROTO - routine was invoked in an inproper context</li>
<li>XA_RMERR - a resource manager error has occurred</li></ul>

@see javax.transaction.xa.XAException