Package javax.transaction.xa

Examples of javax.transaction.xa.XAException


        while (associationState == XATransactionState.T1_ASSOCIATED) {
         
          try {
            wait();
          } catch (InterruptedException ie) {
            throw new XAException(XAException.XA_RETRY);
          }
        }
      }

      switch (associationState) {
      case XATransactionState.TC_COMPLETED:
        throw new XAException(XAException.XAER_NOTA);
      case XATransactionState.TRO_FAIL:
        if (endingCurrentXid)
          flags = XAResource.TMFAIL;
        else
          throw new XAException(rollbackOnlyCode);
      }

      boolean notify = false;
      switch (flags) {
      case XAResource.TMSUCCESS:
        if (isSuspendedByResource) {
          suspendedList.remove(resource);
        }
        else {
          if (resource != associatedResource)
            throw new XAException(XAException.XAER_PROTO);

          associationState = XATransactionState.T0_NOT_ASSOCIATED;
          associatedResource = null;
          notify = true;
        }

        conn.setApplicationConnection(null);
        break;

      case XAResource.TMFAIL:

        if (isSuspendedByResource) {
          suspendedList.remove(resource);
        } else {
          if (resource != associatedResource)
            throw new XAException(XAException.XAER_PROTO);
          associatedResource = null;
        }
       
        if (associationState != XATransactionState.TRO_FAIL) {
          associationState = XATransactionState.TRO_FAIL;
          rollbackOnlyCode = XAException.XA_RBROLLBACK;
        }
        conn.setApplicationConnection(null);
        notify = true;
        rollbackOnly = true;
        break;

      case XAResource.TMSUSPEND:
        if (isSuspendedByResource)
          throw new XAException(XAException.XAER_PROTO);
       
        if (resource != associatedResource)
          throw new XAException(XAException.XAER_PROTO);

        if (suspendedList == null)
          suspendedList = new HashMap();
        suspendedList.put(resource, this);

        associationState = XATransactionState.T0_NOT_ASSOCIATED;
        associatedResource = null;
        conn.setApplicationConnection(null);
        notify = true;

        break;

      default:
        throw new XAException(XAException.XAER_INVAL);
      }

      if (notify)
        notifyAll();
View Full Code Here


            // Rollback the global transaction
            try {
                conn.xa_rollback();
            } catch (SQLException sqle) {
                XAException ex = new XAException(XAException.XAER_RMERR);
                ex.initCause(sqle);
                throw ex;
            }

            // Do the cleanup on the resource
            creatingResource.returnConnectionToResource(this, xid);
View Full Code Here

        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);
            ContextService csf = ContextService.getFactory();
            csf.setCurrentContextManager(inDoubtCM);
            try {
                rm.commit(inDoubtCM, xid_im, onePhase);
               
                // close the connection/transaction since it can never
                // be used again. DERBY-4856 No extended diagnostic information needed.
                inDoubtCM.cleanupOnError(StandardException.closeException(),
                        false);
                return;
            } catch (StandardException se) {
                // The rm threw an exception, clean it up in the approprate
                // context.  There is no transactionResource to handle the
                // exception for us.
                inDoubtCM.cleanupOnError(se, con.isActive());
                throw wrapInXAException(se);
            } finally {
                csf.resetCurrentContextManager(inDoubtCM);
            }
           
        }
       
        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.size() != 0)
                throw new XAException(XAException.XAER_PROTO);
           
            if (tranState.isPrepared == onePhase)
                throw new XAException(XAException.XAER_PROTO);
           
            try {
                tranState.xa_commit(onePhase);
            } catch (SQLException sqle) {
                throw wrapInXAException(sqle);
View Full Code Here

        boolean endingCurrentXid = false;
       
        // must match the Xid from start()
        if (currentXid != null) {
            if (!currentXid.equals(xid_im))
                throw new XAException(XAException.XAER_PROTO);
            endingCurrentXid = true;
        }
       
        XATransactionState tranState = getTransactionState(xid_im);
        if (tranState == null)
            throw new XAException(XAException.XAER_NOTA);
       
        boolean rollbackOnly = tranState.end(this, flags, endingCurrentXid);
       
        // RESOLVE - what happens to the connection on a fail
        // where we are not ending the current XID.
        if (endingCurrentXid) {
            currentXid = null;           
            con.realConnection = null;
        }
       
        if (rollbackOnly)
            throw new XAException(tranState.rollbackOnlyCode);       
    }
View Full Code Here

           
            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.size() != 0)
                throw new XAException(XAException.XAER_PROTO);
           
            if (tranState.isPrepared)
                throw new XAException(XAException.XAER_PROTO);
           
            try {
               
                int ret = tranState.xa_prepare();
               
View Full Code Here

           
            ContextManager inDoubtCM = rm.find(xid);
           
            // RM also does not know about this xid.
            if (inDoubtCM == null)
                throw new XAException(XAException.XAER_NOTA);
           
            ContextService csf = ContextService.getFactory();
           
            csf.setCurrentContextManager(inDoubtCM);
            try {
                rm.forget(inDoubtCM, xid_im);
               
                // close the connection/transaction since it can never be used again.
                inDoubtCM.cleanupOnError(StandardException.closeException(),
                        false);
                return;
            } catch (StandardException se) {
                // The rm threw an exception, clean it up in the approprate
                // context.  There is no transactionResource to handle the
                // exception for us.
                inDoubtCM.cleanupOnError(se, con.isActive());
                throw wrapInXAException(se);
            } finally {
                csf.resetCurrentContextManager(inDoubtCM);
            }
           
        }
       
        throw new XAException(tranState.isPrepared
            ? XAException.XAER_NOTA
            : XAException.XAER_PROTO);
    }   
View Full Code Here

           
            ContextManager inDoubtCM = rm.find(xid);
           
            // RM also does not know about this xid.
            if (inDoubtCM == null)
                throw new XAException(XAException.XAER_NOTA);
           
            ContextService csf = ContextService.getFactory();
           
            csf.setCurrentContextManager(inDoubtCM);
            try {
                rm.rollback(inDoubtCM, xid_im);
               
                // close the connection/transaction since it can never be used again.
                inDoubtCM.cleanupOnError(StandardException.closeException(),
                        false);
                return;
            } catch (StandardException se) {
                // The rm threw an exception, clean it up in the approprate
                // context.  There is no transactionResource to handle the
                // exception for us.
                inDoubtCM.cleanupOnError(se, con.isActive());
                throw wrapInXAException(se);
            } finally {
                csf.resetCurrentContextManager(inDoubtCM);
            }
           
        }
       
        synchronized (tranState) {
           
            // Check the transaction is no associated with
            // any XAResource.
            switch (tranState.associationState) {
                case XATransactionState.T0_NOT_ASSOCIATED:
                case XATransactionState.TRO_FAIL:
                    break;
                   
                default:
                    throw new XAException(XAException.XAER_PROTO);
            }
           
            if (tranState.suspendedList != null
                    && tranState.suspendedList.size() != 0)
                throw new XAException(XAException.XAER_PROTO);
           
            checkUserCredentials(tranState.creatingResource);
           
            try {
               
View Full Code Here

     */
    public synchronized boolean setTransactionTimeout(int seconds)
    throws XAException {
        if (seconds < 0) {
            // throw an exception if invalid value was specified
            throw new XAException(XAException.XAER_INVAL);
        }
        timeoutSeconds = seconds;
        return true;
    }
View Full Code Here

                                        int flags) throws XAException {
        checkXAActive();
       
        // JDBC 3.0 section 12.3 - One transaction associated with a XAConnection
        if (currentXid != null)
            throw new XAException(XAException.XAER_PROTO);
       
        // ensure immtable and correct equals method.
        XAXactId xid_im = new XAXactId(xid);
       
        XATransactionState tranState = getTransactionState(xid_im);
       
        switch (flags) {
            case XAResource.TMNOFLAGS:
                if (tranState != null)
                    throw new XAException(XAException.XAER_DUPID);
               
                try {
                   
                    if (con.realConnection == null) {
                        con.openRealConnection();
                       
                        if (con.currentConnectionHandle != null) {
                           
                            // since this is a new connection, set its complete
                            // state according to the application's Connection
                            // handle view of the world.
                            con.currentConnectionHandle.setState(true);
                            con.realConnection.setApplicationConnection
                                    (con.currentConnectionHandle);
                        }
                       
                    } else {
                       
                        // XAResource.start() auto commits in DB2 when in
                        // auto commit mode.
                        if (con.currentConnectionHandle != null) {
                            if (con.currentConnectionHandle.getAutoCommit())
                                con.currentConnectionHandle.rollback();
                        }
                        if (!con.realConnection.transactionIsIdle())
                            throw new XAException(XAException.XAER_OUTSIDE);
                       
                        if (con.currentConnectionHandle != null) {
                            // It is possible that the isolation level state
                            // in connection handle has gotten out of sync
                            // with the real isolation level. This can happen
                            // if SLQ instead of JDBC api has been used to set
                            // the isolation level. The code below will check
                            // if isolation was set using JDBC or SQL and if
                            // yes, then it will update the isolation state
                            // in BrokeredConnection with EmbedConnection's
                            // isolation level.
                            con.currentConnectionHandle.getIsolationUptoDate();
                            // we have a current handle so we need to keep
                            // the connection state of the current connection.
                            con.currentConnectionHandle.setState(true);
                           
                            // At the local to global transition we need
                            // to discard and close any open held result
                            // sets, a rollback will do this.
                            con.realConnection.rollback();
                        } else {
                            con.resetRealConnection();
                        }
                       
                    }
                   
                    // Global connections are always in auto commit false mode.
                    con.realConnection.setAutoCommit(false);
                   
                    // and holdability false (cannot hold cursors across
                    // XA transactions.
                    con.realConnection.setHoldability(
                            ResultSet.CLOSE_CURSORS_AT_COMMIT);
                   
                    con.realConnection.getLanguageConnection().
                            getTransactionExecute().
                            createXATransactionFromLocalTransaction(
                                                xid_im.getFormatId(),
                                                xid_im.getGlobalTransactionId(),
                                                xid_im.getBranchQualifier());
                   
                   
                } catch (StandardException se) {
                    throw wrapInXAException(se);
                } catch (SQLException sqle) {
                    throw wrapInXAException(sqle);
                }
               
                tranState = new XATransactionState(
                    con.realConnection.getContextManager(),
                    con.realConnection, this, xid_im);
                if (!ra.addConnection(xid_im, tranState))
                    throw new XAException(XAException.XAER_DUPID);
               
                currentXid = xid_im;

                // If the the timeout specified is equal to Integer.MAX_VALUE
                // it means that transaction timeout is disabled.
                if (timeoutSeconds != Integer.MAX_VALUE) {
                    // Find out the value of the transaction timeout
                    long timeoutMillis;
                    if (timeoutSeconds > 0) {
                        timeoutMillis = 1000*timeoutSeconds;
                    } else {
                        timeoutMillis = getDefaultXATransactionTimeout();
                    }
                    // If we have non-zero transaction timeout schedule a timeout task.
                    // The only way how timeoutMillis might be equeal to 0 is that
                    // it was specified as a default transaction timeout
                    if (timeoutMillis > 0) {
                        tranState.scheduleTimeoutTask(timeoutMillis);
                    }
                }

                break;
               
            case XAResource.TMRESUME:
            case XAResource.TMJOIN:
                if (tranState == null)
                    throw new XAException(XAException.XAER_NOTA);
               
                tranState.start(this, flags);
               
                if (tranState.conn != con.realConnection) {
                   
                    if (con.realConnection != null) {
                       
                        if (!con.realConnection.transactionIsIdle())
                            throw new XAException(XAException.XAER_OUTSIDE);
                       
                        // We need to get the isolation level up to date same
                        // way as it is done at start of a transaction. Before
                        // joining the transaction, it is possible that the
                        // isolation level was updated using SQL. We need to
                        // get this state and store in the connection handle so
                        // that we can restore the isolation when we are in the
                        // local mode.
                        try {
                        if (con.currentConnectionHandle != null) {
                          con.currentConnectionHandle.getIsolationUptoDate();
                        }
                      } catch (SQLException sqle) {
                            throw wrapInXAException(sqle);
                        }
                       
                        closeUnusedConnection(con.realConnection);
                    }
                    con.realConnection = tranState.conn;
                   
                    if (con.currentConnectionHandle != null) {
                       
                        try {
                            // only reset the non-transaction specific
                            // Connection state.
                            con.currentConnectionHandle.setState(false);
                            con.realConnection.setApplicationConnection(
                                    con.currentConnectionHandle);
                        } catch (SQLException sqle) {
                            throw wrapInXAException(sqle);
                        }
                    }
                   
                }
               
               
                break;
               
            default:
                throw new XAException(XAException.XAER_INVAL);
        }
       
        currentXid = xid_im;
    }
View Full Code Here

        if (original == this)
            return;       
        if (original.con.getPassword().equals(con.getPassword()) &&
                (original.con.getUsername().equals(con.getUsername())))
            return;               
        throw new XAException(XAException.XA_RBINTEGRITY);
    }
View Full Code Here

TOP

Related Classes of javax.transaction.xa.XAException

Copyright © 2018 www.massapicom. 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.