Java Code Examples for javax.transaction.xa.XAResource#XA_RDONLY

The following examples show how to use javax.transaction.xa.XAResource#XA_RDONLY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalXAConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * This method does nothing since the LocalXAConnection does not support two-phase-commit. This method will
 * return XAResource.XA_RDONLY if the connection isReadOnly(). This assumes that the physical connection is
 * wrapped with a proxy that prevents an application from changing the read-only flag while enrolled in a
 * transaction.
 *
 * @param xid
 *            the id of the transaction branch for this connection
 * @return XAResource.XA_RDONLY if the connection.isReadOnly(); XAResource.XA_OK otherwise
 */
@Override
public synchronized int prepare(final Xid xid) {
    // if the connection is read-only, then the resource is read-only
    // NOTE: this assumes that the outer proxy throws an exception when application code
    // attempts to set this in a transaction
    try {
        if (connection.isReadOnly()) {
            // update the auto commit flag
            connection.setAutoCommit(originalAutoCommit);

            // tell the transaction manager we are read only
            return XAResource.XA_RDONLY;
        }
    } catch (final SQLException ignored) {
        // no big deal
    }

    // this is a local (one phase) only connection, so we can't prepare
    return XAResource.XA_OK;
}
 
Example 2
Source File: XATerminatorOptd.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized int prepare(Xid xid) throws XAException {
	if (this.archive == null) {
		return XAResource.XA_RDONLY;
	}
	TransactionLogger transactionLogger = this.beanFactory.getTransactionLogger();

	boolean prepared = archive.getVote() != XAResourceArchive.DEFAULT_VOTE;

	int globalVote = XAResource.XA_RDONLY;
	if (prepared) {
		globalVote = archive.getVote();
	} else {
		globalVote = archive.prepare(archive.getXid());
		archive.setVote(globalVote);

		if (globalVote == XAResource.XA_RDONLY) {
			archive.setReadonly(true);
			archive.setCompleted(true);
		} else {
			globalVote = XAResource.XA_OK;
		}

		transactionLogger.updateParticipant(archive);
	}

	logger.info("{}> prepare: xares= {}, branch= {}, vote= {}",
			ByteUtils.byteArrayToString(this.archive.getXid().getGlobalTransactionId()), archive,
			ByteUtils.byteArrayToString(this.archive.getXid().getBranchQualifier()), globalVote);

	return globalVote;
}
 
Example 3
Source File: LocalXAResource.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public int prepare(final Xid xid) {
    checkLock();

    try {
        if (connection.isReadOnly()) {
            connection.setAutoCommit(originalAutoCommit);
            return XAResource.XA_RDONLY;
        }
    } catch (final SQLException ignored) {
        // no-op
    }

    return XAResource.XA_OK;
}
 
Example 4
Source File: NetXAConnectionReply.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
protected int readXaPrepare(NetConnection conn) throws DisconnectException {
    startSameIdChainParse();
    int synctype = parseSYNCCTLreply(conn);
    endOfSameIdChainData();

    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    if (synctype == XAResource.XA_RDONLY) { // xaretval of read-only, make sure flag agrees
        callInfo.setReadOnlyTransactionFlag(true);
    } else { // xaretval NOT read-only, make sure flag agrees
        callInfo.setReadOnlyTransactionFlag(false);
    }
    return synctype;
}
 
Example 5
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized int prepare(Xid xid) throws XAException {
	TransactionLogger transactionLogger = this.beanFactory.getTransactionLogger();

	int globalVote = XAResource.XA_RDONLY;
	for (int i = 0; i < this.resources.size(); i++) {
		XAResourceArchive archive = this.resources.get(i);

		boolean prepared = archive.getVote() != XAResourceArchive.DEFAULT_VOTE;
		if (prepared) {
			globalVote = archive.getVote() == XAResource.XA_RDONLY ? globalVote : XAResource.XA_OK;
		} else {
			int branchVote = archive.prepare(archive.getXid());
			archive.setVote(branchVote);

			if (branchVote == XAResource.XA_RDONLY) {
				archive.setReadonly(true);
				archive.setCompleted(true);
			} else {
				globalVote = XAResource.XA_OK;
			}

			transactionLogger.updateParticipant(archive);
		}

		logger.info("{}> prepare: xares= {}, branch= {}, vote= {}",
				ByteUtils.byteArrayToString(archive.getXid().getGlobalTransactionId()), archive,
				ByteUtils.byteArrayToString(archive.getXid().getBranchQualifier()), archive.getVote());
	}

	return globalVote;
}
 
Example 6
Source File: XAResourceArchive.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int prepare(Xid ignore) throws XAException {
	if (this.vote == -1) {
		this.vote = this.descriptor.prepare(this.xid);
		this.readonly = this.vote == XAResource.XA_RDONLY;
	}
	return this.vote;

}
 
Example 7
Source File: NetXAConnectionReply.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int readXaPrepare(NetConnection conn) throws DisconnectException {
    startSameIdChainParse();
    int synctype = parseSYNCCTLreply(conn);
    endOfSameIdChainData();

    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    if (synctype == XAResource.XA_RDONLY) { // xaretval of read-only, make sure flag agrees
        callInfo.setReadOnlyTransactionFlag(true);
    } else { // xaretval NOT read-only, make sure flag agrees
        callInfo.setReadOnlyTransactionFlag(false);
    }
    return synctype;
}
 
Example 8
Source File: MultiThreadedTx.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(MultiThreadedTx tx) throws SystemException
{
    MutableList<Future<Integer>> futures = FastList.newList(tx.resourceManagers.size());
    int i = -1;
    try
    {
        for(i = 1; i < tx.resourceManagers.size();i++)
        {
            TxGroup branch = tx.resourceManagers.get(i);
            futures.add(branch.prepare());
        }
        int offset = 1;
        for(i = 0; i < futures.size();i++)
        {
            Future<Integer> result = futures.get(i);
            int prepareState = result.get();
            if (prepareState == XAResource.XA_RDONLY)
            {
                tx.resourceManagers.remove(i + offset);
                offset--;
            }
        }
        tx.status.set(COMMITTING);
    }
    catch (Throwable e)
    {
        logger.error("Error preparing. Rolling back instead", e);
        tx.resourceManagers.remove(i); // resource threw an exception and is presumed rolled back
        tx.rollbackCause = e;
        tx.status.set(ROLLING_BACK);
    }
}
 
Example 9
Source File: NetXAConnectionReply.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected int readXaPrepare(NetConnection conn) throws DisconnectException {
    startSameIdChainParse();
    int synctype = parseSYNCCTLreply(conn);
    endOfSameIdChainData();

    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    if (synctype == XAResource.XA_RDONLY) { // xaretval of read-only, make sure flag agrees
        callInfo.setReadOnlyTransactionFlag(true);
    } else { // xaretval NOT read-only, make sure flag agrees
        callInfo.setReadOnlyTransactionFlag(false);
    }
    return synctype;
}
 
Example 10
Source File: AbstractLuceneIndexerAndSearcherFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Prepare the transaction TODO: Store prepare results
 * 
 * @return - the tx code
 */
@SuppressWarnings("unchecked")
public int prepare() throws IndexerException
{
    boolean isPrepared = true;
    boolean isModified = false;
    Map<StoreRef, LuceneIndexer> indexers = (Map<StoreRef, LuceneIndexer>) AlfrescoTransactionSupport.getResource(indexersKey);
    if (indexers != null)
    {
        for (LuceneIndexer indexer : indexers.values())
        {
            try
            {
                isModified |= indexer.isModified();
                indexer.prepare();
            }
            catch (IndexerException e)
            {
                isPrepared = false;
                throw new IndexerException("Failed to prepare: requires rollback", e);
            }
        }
    }
    if (isPrepared)
    {
        if (isModified)
        {
            return XAResource.XA_OK;
        }
        else
        {
            return XAResource.XA_RDONLY;
        }
    }
    else
    {
        throw new IndexerException("Failed to prepare: requires rollback");
    }
}
 
Example 11
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param xid A global transaction identifier
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values
 *         are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by
 *         raising an appropriate XAException in the prepare method.
 *
 * @throws XAException An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 *                     XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
public int prepare(Xid xid) throws XAException { // public interface for prepare
    // just call prepareX with the recursion flag set to true
    exceptionsOnXA = null;

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "prepare", xid);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    /// update the XACallInfo
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        // sent the prepare PROTOCOL
        netAgent.netConnectionRequest_.writeXaPrepare(conn_);
        netAgent.flowOutsideUOW();

        // read the reply to the prepare
        rc = netAgent.netConnectionReply_.readXaPrepare(conn_);
        if ((callInfo.xaRetVal_ != XAResource.XA_OK) &&
                (callInfo.xaRetVal_ != XAException.XA_RDONLY)) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_PREPARE;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }

        netAgent.endReadChain();
    } catch (SqlException sqle) {
        rc = XAException.XAER_RMERR;
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if ((rc != XAResource.XA_OK ) && (rc != XAResource.XA_RDONLY)) {
        throwXAException(rc, false);
    }
    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceExit(this, "prepare", rc);
    }
    return rc;
}
 
Example 12
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param xid A global transaction identifier
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values
 *         are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by
 *         raising an appropriate XAException in the prepare method.
 *
 * @throws XAException An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 *                     XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
public int prepare(Xid xid) throws XAException { // public interface for prepare
    // just call prepareX with the recursion flag set to true
    exceptionsOnXA = null;

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "prepare", xid);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    /// update the XACallInfo
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        // sent the prepare PROTOCOL
        netAgent.netConnectionRequest_.writeXaPrepare(conn_);
        netAgent.flowOutsideUOW();

        // read the reply to the prepare
        rc = netAgent.netConnectionReply_.readXaPrepare(conn_);
        if ((callInfo.xaRetVal_ != XAResource.XA_OK) &&
                (callInfo.xaRetVal_ != XAException.XA_RDONLY)) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_PREPARE;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }

        netAgent.endReadChain();
    } catch (SqlException sqle) {
        rc = getSqlExceptionXAErrorCode(sqle);
        exceptionsOnXA = com.splicemachine.db.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if ((rc != XAResource.XA_OK ) && (rc != XAResource.XA_RDONLY)) {
        throwXAException(rc, false);
    }
    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceExit(this, "prepare", rc);
    }
    return rc;
}
 
Example 13
Source File: AbstractLuceneIndexerAndSearcherFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int prepare(Xid xid) throws XAException
{
    // TODO: Track state OK, ReadOnly, Exception (=> rolled back?)
    Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
    if (indexers == null)
    {
        if (suspendedIndexersInGlobalTx.containsKey(xid))
        {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        }
        else
        {
            // nothing to do
            return XAResource.XA_OK;
        }
    }
    boolean isPrepared = true;
    boolean isModified = false;
    for (LuceneIndexer indexer : indexers.values())
    {
        try
        {
            isModified |= indexer.isModified();
            indexer.prepare();
        }
        catch (IndexerException e)
        {
            isPrepared = false;
        }
    }
    if (isPrepared)
    {
        if (isModified)
        {
            return XAResource.XA_OK;
        }
        else
        {
            return XAResource.XA_RDONLY;
        }
    }
    else
    {
        throw new XAException("Failed to prepare: requires rollback");
    }
}
 
Example 14
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param xid A global transaction identifier
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values
 *         are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by
 *         raising an appropriate XAException in the prepare method.
 *
 * @throws XAException An error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 *                     XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
public int prepare(Xid xid) throws XAException { // public interface for prepare
    // just call prepareX with the recursion flag set to true
    exceptionsOnXA = null;

    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceEntry(this, "prepare", xid);
    }
    if (conn_.isPhysicalConnClosed()) {
        connectionClosedFailure();
    }

    /// update the XACallInfo
    NetAgent netAgent = conn_.netAgent_;
    int rc = XAResource.XA_OK;
    NetXACallInfo callInfo = callInfoArray_[conn_.currXACallInfoOffset_];
    callInfo.xid_ = xid;
    callInfo.xaResource_ = this;
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    try {
        netAgent.beginWriteChainOutsideUOW();
        // sent the prepare PROTOCOL
        netAgent.netConnectionRequest_.writeXaPrepare(conn_);
        netAgent.flowOutsideUOW();

        // read the reply to the prepare
        rc = netAgent.netConnectionReply_.readXaPrepare(conn_);
        if ((callInfo.xaRetVal_ != XAResource.XA_OK) &&
                (callInfo.xaRetVal_ != XAException.XA_RDONLY)) { // xaRetVal has possible error, format it
            callInfo.xaFunction_ = XAFUNC_PREPARE;
            rc = xaRetValErrorAccumSQL(callInfo, rc);
            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        }

        netAgent.endReadChain();
    } catch (SqlException sqle) {
        rc = XAException.XAER_RMERR;
        exceptionsOnXA = com.pivotal.gemfirexd.internal.client.am.Utils.accumulateSQLException
                (sqle, exceptionsOnXA);
    } finally {
        conn_.pendingEndXACallinfoOffset_ = -1; // indicate no pending callinfo
    }
    if ((rc != XAResource.XA_OK ) && (rc != XAResource.XA_RDONLY)) {
        throwXAException(rc, false);
    }
    if (conn_.agent_.loggingEnabled()) {
        conn_.agent_.logWriter_.traceExit(this, "prepare", rc);
    }
    return rc;
}
 
Example 15
Source File: XATerminatorImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void invokeRollback(XAResourceArchive archive) throws XAException {
	try {
		archive.rollback(archive.getXid());
	} catch (XAException xaex) {
		// * @exception XAException An error has occurred. Possible XAExceptions are
		// * XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL,
		// * XAER_NOTA, XAER_INVAL, or XAER_PROTO.
		// * <p>If the transaction branch is already marked rollback-only the
		// * resource manager may throw one of the XA_RB* exceptions. Upon return,
		// * the resource manager has rolled back the branch's work and has released
		// * all held resources.
		switch (xaex.errorCode) {
		case XAException.XA_HEURHAZ:
			// Due to some failure, the work done on behalf of the specified transaction branch
			// may have been heuristically completed. A resource manager may return this
			// value only if it has successfully prepared xid.
		case XAException.XA_HEURMIX:
			// Due to a heuristic decision, the work done on behalf of the specified transaction
			// branch was partially committed and partially rolled back. A resource manager
			// may return this value only if it has successfully prepared xid.
		case XAException.XA_HEURCOM:
			// Due to a heuristic decision, the work done on behalf of the specified transaction
			// branch was committed. A resource manager may return this value only if it has
			// successfully prepared xid.
		case XAException.XA_HEURRB:
			// Due to a heuristic decision, the work done on behalf of the specified transaction
			// branch was rolled back. A resource manager may return this value only if it has
			// successfully prepared xid.
			throw xaex;
		case XAException.XAER_RMFAIL:
			// An error occurred that makes the resource manager unavailable.
			XAException xrhaz = new XAException(XAException.XA_HEURHAZ);
			xrhaz.initCause(xaex);
			throw xrhaz;
		case XAException.XAER_NOTA:
			// The specified XID is not known by the resource manager.
			if (archive.isReadonly()) {
				throw new XAException(XAException.XA_RDONLY);
			} else if (archive.getVote() == XAResourceArchive.DEFAULT_VOTE) {
				break; // rolled back
			} else if (archive.getVote() == XAResource.XA_RDONLY) {
				throw new XAException(XAException.XA_RDONLY);
			} else if (archive.getVote() == XAResource.XA_OK) {
				throw new XAException(XAException.XAER_RMERR);
			} else {
				throw new XAException(XAException.XAER_RMERR);
			}
		case XAException.XAER_PROTO:
			// The routine was invoked in an improper context.
		case XAException.XAER_INVAL:
			// Invalid arguments were specified.
			throw new XAException(XAException.XAER_RMERR);
		case XAException.XAER_RMERR:
			// An error occurred in rolling back the transaction branch. The resource manager is
			// free to forget about the branch when returning this error so long as all accessing
			// threads of control have been notified of the branch’s state.
		default: // XA_RB*
			// The resource manager has rolled back the transaction branch’s work and has
			// released all held resources. These values are typically returned when the
			// branch was already marked rollback-only.
			XAException xarb = new XAException(XAException.XA_HEURRB);
			xarb.initCause(xaex);
			throw xarb;
		}
	}
}
 
Example 16
Source File: LocalXAResourceDescriptor.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int prepare(Xid arg0) throws XAException {
	if (this.delegate == null) {
		return XAResource.XA_RDONLY;
	}
	return delegate.prepare(arg0);
}
 
Example 17
Source File: UnidentifiedResourceDescriptor.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int prepare(Xid arg0) throws XAException {
	if (this.delegate == null) {
		return XAResource.XA_RDONLY;
	}
	return delegate.prepare(arg0);
}
 
Example 18
Source File: EmbedXAResource.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Ask the resource manager to prepare for a transaction commit of the
 * transaction specified in xid.
 *
 * @param xid A global transaction identifier
 *
 * @return A value indicating the resource manager's vote on the outcome
 * of the transaction. The possible values are: XA_RDONLY or XA_OK. If the
 * resource manager wants to roll back the transaction, it should do so by
 * raising an appropriate XAException in the prepare method.
 *
 * @exception XAException An error has occurred. Possible exception values
 * are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or
 * XAER_PROTO.
 *
 */
public final synchronized int prepare(Xid xid) throws XAException {
    checkXAActive();
    
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    
    XATransactionState tranState = getTransactionState(xid_im);
    
    if (tranState == null) {
        XAResourceManager rm = ra.getXAResourceManager();
        
        ContextManager inDoubtCM = rm.find(xid);
        
        // RM also does not know about this xid.
        if (inDoubtCM == null)
            throw new XAException(XAException.XAER_NOTA);
        
        // cannot prepare in doubt transactions
        throw new XAException(XAException.XAER_PROTO);
        
    }
    
    synchronized (tranState) {
        
        checkUserCredentials(tranState.creatingResource);
        
        // Check the transaction is no associated with
        // any XAResource.
        switch (tranState.associationState) {
            case XATransactionState.T0_NOT_ASSOCIATED:
                break;
                
            case XATransactionState.TRO_FAIL:
                throw new XAException(tranState.rollbackOnlyCode);
                
            default:
                throw new XAException(XAException.XAER_PROTO);
        }
        
        if (tranState.suspendedList != null 
                && !tranState.suspendedList.isEmpty())
            throw new XAException(XAException.XAER_PROTO);
        
        if (tranState.isPrepared)
            throw new XAException(XAException.XAER_PROTO);
        
        try {
            
            int ret = tranState.xa_prepare();
            
            if (ret == XATransactionController.XA_OK) {
                tranState.isPrepared = true;
                
                return XAResource.XA_OK;
            } else {
                
                returnConnectionToResource(tranState, xid_im);

	if (SanityManager.DEBUG) {
		if (con.realConnection != null) {
			SanityManager.ASSERT(
                            con.realConnection.transactionIsIdle(),
                            "real connection should have been idle." +
                            "tranState = " + tranState +
                            "ret = " + ret +
                            "con.realConnection = " + con.realConnection);
                    }
	}
                return XAResource.XA_RDONLY;
            }
        } catch (SQLException sqle) {
            throw wrapInXAException(sqle);
        }
    }
    
}
 
Example 19
Source File: VacantTransactionStrategy.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int prepare(Xid xid) throws RollbackRequiredException, CommitRequiredException {
	return XAResource.XA_RDONLY;
}
 
Example 20
Source File: AbstractLuceneIndexerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Prepare to commit At the moment this makes sure we have all the locks TODO: This is not doing proper
 * serialisation against the index as would a data base transaction.
 * 
 * @return the tx state
 * @throws LuceneIndexException
 */
public int prepare() throws LuceneIndexException
{
    if (s_logger.isDebugEnabled())
    {
        s_logger.debug(Thread.currentThread().getName() + " Starting Prepare");
    }
    switch (getStatus().getStatus())
    {
    case Status.STATUS_COMMITTING:
        throw new IndexerException("Unable to prepare: Transaction is committing");
    case Status.STATUS_COMMITTED:
        throw new IndexerException("Unable to prepare: Transaction is commited ");
    case Status.STATUS_ROLLING_BACK:
        throw new IndexerException("Unable to prepare: Transaction is rolling back");
    case Status.STATUS_ROLLEDBACK:
        throw new IndexerException("Unable to prepare: Transaction is aleady rolled back");
    case Status.STATUS_MARKED_ROLLBACK:
        throw new IndexerException("Unable to prepare: Transaction is marked for roll back");
    case Status.STATUS_PREPARING:
        throw new IndexerException("Unable to prepare: Transaction is already preparing");
    case Status.STATUS_PREPARED:
        throw new IndexerException("Unable to prepare: Transaction is already prepared");
    default:
        try
        {
            setStatus(TransactionStatus.PREPARING);
            if (isModified())
            {
                doPrepare();
                if (s_logger.isDebugEnabled())
                {
                    s_logger.debug(Thread.currentThread().getName() + " Waiting to Finish Preparing");
                }                    
            }
            setStatus(TransactionStatus.PREPARED);
            return isModified() ? XAResource.XA_OK : XAResource.XA_RDONLY;
        }
        catch (LuceneIndexException e)
        {
            setRollbackOnly();
            if (s_logger.isDebugEnabled())
            {
                s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", e);
            }
            throw new LuceneIndexException("Index failed to prepare", e);
        }
        catch (Throwable t)
        {
            // If anything goes wrong we try and do a roll back
            rollback();
            if (s_logger.isDebugEnabled())
            {
                s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", t);
            }
            throw new LuceneIndexException("Prepared failed", t);                
        }
        finally
        {
            if (s_logger.isDebugEnabled())
            {
                s_logger.debug(Thread.currentThread().getName() + " Ending Prepare");
            }                
        }
    }
}