Examples of XAResource


Examples of javax.transaction.xa.XAResource

        if (branchXid == null)
        {
            Iterator enlistedIterator = enlistedResources.iterator();
            while ((!alreadyEnlisted) && (enlistedIterator.hasNext()))
            {
                XAResource resourceManager = (XAResource) enlistedIterator.next();
                try
                {
                    if (resourceManager.isSameRM(xaRes))
                    {
                        flag = XAResource.TMJOIN;
                        alreadyEnlisted = true;
                    }
                }
View Full Code Here

Examples of javax.transaction.xa.XAResource

   
            status = Status.STATUS_ROLLING_BACK;
            while (branchKeys.hasNext())
            {
                Xid xid = (Xid) branchKeys.next();
                XAResource resourceManager = (XAResource) branches.get(xid);
                try
                {
                    resourceManager.rollback(xid);
                }
                catch (Throwable e)
                {
                    if( failures == null )
                    {
View Full Code Here

Examples of javax.transaction.xa.XAResource

     * @return the XAResource registered for the connection; never null
     * @throws SQLException if the connection does not have a registered XAResource
     */
    public synchronized XAResource getXAResource(Connection connection) throws SQLException {
        if (connection == null) throw new NullPointerException("connection is null");
        XAResource xaResource = (XAResource) xaResources.get(connection);
        if (xaResource == null) {
            throw new SQLException("Connection does not have a registered XAResource " + connection);
        }
        return xaResource;
    }
View Full Code Here

Examples of javax.transaction.xa.XAResource

    public Connection createConnection() throws SQLException {
        // create a new connection
        Connection connection = connectionFactory.createConnection();

        // create a XAResource to manage the connection during XA transactions
        XAResource xaResource = new LocalXAResource(connection);

        // register the xa resource for the connection
        transactionRegistry.registerConnection(connection, xaResource);

        return connection;
View Full Code Here

Examples of javax.transaction.xa.XAResource

        // This is the first use of the connection in this transaction, so we must
        // enlist it in the transaction
        Transaction transaction = getTransaction();
        try {
            XAResource xaResource = transactionRegistry.getXAResource(sharedConnection);
            transaction.enlistResource(xaResource);
        } catch (RollbackException e) {
            // transaction was rolled back... proceed as if there never was a transaction
        } catch (SystemException e) {
            throw (SQLException) new SQLException("Unable to enlist connection the transaction").initCause(e);
View Full Code Here

Examples of javax.transaction.xa.XAResource

            xaConnection = xaDataSource.getXAConnection(username, password);
        }

        // get the real connection and XAResource from the connection
        Connection connection = xaConnection.getConnection();
        XAResource xaResource = xaConnection.getXAResource();

        // register the xa resource for the connection
        transactionRegistry.registerConnection(connection, xaResource);

        return connection;
View Full Code Here

Examples of javax.transaction.xa.XAResource

                // If we have only one resource, we don't ask to prepare, and we go with one-phase commit
                status = Status.STATUS_COMMITTING;
                while (branchKeys.hasNext())
                {
                    Xid key = branchKeys.next();
                    XAResource resourceManager = branches.get(key);
                    try
                    {
                        if (!failed)
                        {
                            resourceManager.commit(key, true);
                        }
                        else
                        {
                            resourceManager.rollback(key);
                        }
                    }
                    catch (Throwable e)
                    {
                        if (failures == null)
                        {
                            //lazy instantiate this, because we only need on failures
                            failures = new ArrayList();
                        }
                        failures.add(e);
                        failed = true;
                        status = Status.STATUS_MARKED_ROLLBACK;
                        NucleusLogger.TRANSACTION.error(LOCALISER.msg("015038", "commit", resourceManager,
                            getXAErrorCode(e), toString()));                   
                    }
                }
                if (!failed)
                {
                    status = Status.STATUS_COMMITTED;
                }
                else
                {
                    status = Status.STATUS_ROLLEDBACK;
                }
            }
            else if (enlistedResources.size() > 0)
            {
                // Prepare each enlisted resource
                status = Status.STATUS_PREPARING;
                while ((!failed) && (branchKeys.hasNext()))
                {
                    Xid key = branchKeys.next();
                    XAResource resourceManager = branches.get(key);
                    try
                    {
                        // Preparing the resource manager using its branch xid
                        resourceManager.prepare(key);
                    }
                    catch (Throwable e)
                    {
                        if (failures == null)
                        {
                            //lazy instantiate this, because we only need on failures
                            failures = new ArrayList();
                        }
                        failures.add(e);
                        failed = true;
                        status = Status.STATUS_MARKED_ROLLBACK;
                        NucleusLogger.TRANSACTION.error(LOCALISER.msg("015038", "prepare", resourceManager,
                            getXAErrorCode(e), toString()));
                    }
                }

                if (!failed)
                {
                    status = Status.STATUS_PREPARED;
                }
   
                // Starts 2nd commit phase
                // If fail, rollback
                if (failed)
                {
                    status = Status.STATUS_ROLLING_BACK;
                    failed = false;
                    // Rolling back all the prepared (and unprepared) branches
                    branchKeys = branches.keySet().iterator();
                    while (branchKeys.hasNext())
                    {
                        Xid key = branchKeys.next();
                        XAResource resourceManager = branches.get(key);
                        try
                        {
                            resourceManager.rollback(key);
                        }
                        catch (Throwable e)
                        {
                            NucleusLogger.TRANSACTION.error(LOCALISER.msg("015038", "rollback", resourceManager,
                                getXAErrorCode(e), toString()));                       
                            if (failures == null)
                            {
                                //lazy instantiate this, because we only need on failures
                                failures = new ArrayList();
                            }
                            failures.add(e);
                            failed = true;
                        }
                    }
                    status = Status.STATUS_ROLLEDBACK;
                }
                else
                {
                    status = Status.STATUS_COMMITTING;
                    // Commit each enlisted resource
                    branchKeys = branches.keySet().iterator();
                    while (branchKeys.hasNext())
                    {
                        Xid key = branchKeys.next();
                        XAResource resourceManager = branches.get(key);
                        try
                        {
                            resourceManager.commit(key, false);
                        }
                        catch (Throwable e)
                        {
                            NucleusLogger.TRANSACTION.error(LOCALISER.msg("015038", "commit", resourceManager,
                                getXAErrorCode(e), toString()));                    
View Full Code Here

Examples of javax.transaction.xa.XAResource

        if (branchXid == null)
        {
            Iterator<XAResource> enlistedIterator = enlistedResources.iterator();
            while ((!alreadyEnlisted) && (enlistedIterator.hasNext()))
            {
                XAResource resourceManager = enlistedIterator.next();
                try
                {
                    if (resourceManager.isSameRM(xaRes))
                    {
                        flag = XAResource.TMJOIN;
                        alreadyEnlisted = true;
                    }
                }
View Full Code Here

Examples of javax.transaction.xa.XAResource

            Iterator branchKeys = branches.keySet().iterator();
            status = Status.STATUS_ROLLING_BACK;
            while (branchKeys.hasNext())
            {
                Xid xid = (Xid) branchKeys.next();
                XAResource resourceManager = branches.get(xid);
                try
                {
                    resourceManager.rollback(xid);
                }
                catch (Throwable e)
                {
                    if (failures == null)
                    {
View Full Code Here

Examples of javax.transaction.xa.XAResource

     * @param tx Transaction
     * @param options Any options
     */
    private void enlistResource(ManagedConnection mconn, Transaction tx, Map<String, Object> options)
    {
        XAResource res = mconn.getXAResource();
        if (res != null)
        {
            // Enlist the connection resource if has enlistable resource
            boolean enlistInLocalTM = true;
            if (options != null && options.get(ConnectionFactory.RESOURCE_TYPE_OPTION) != null &&
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.