Search in sources :

Example 16 with JMQXid

use of com.sun.messaging.jmq.util.JMQXid in project openmq by eclipse-ee4j.

the class JMSServiceImpl method prepareTransaction.

/**
 * Pepare a transaction.
 *
 * @param connectionId The Id of the connection
 * @param transactionId If non-zero, the transaction being prepared is identified by this broker-generated id
 * @param xid If transactionId is zero, then xid contains the Xid of the XA transaction being prepared
 *
 * @return The JMSServiceReply of the request to prepare a transaction
 *
 * @throws JMSServiceException if the Status returned for the prepareTransaction method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSServiceReply.Status#getJMQTransactionID
 *
 * @see JMSServiceReply.Status#BAD_REQUEST
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#PRECONDITION_FAILED
 * @see JMSServiceReply.Status#TIMEOUT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply prepareTransaction(long connectionId, long transactionId, Xid xid) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    TransactionUID txnUID = null;
    JMQXid jmqXid = null;
    cxn = checkConnectionId(connectionId, "prepareTransaction");
    /*
         * If transactionId is 0, extract it from XID
         */
    if (transactionId == 0) {
        jmqXid = new JMQXid(xid);
        Object[] oo = TransactionList.mapXidToTid(jmqXid, cxn);
        if (oo == null) {
            String errStr = "prepareTransaction(" + connectionId + "): Unknown XID " + jmqXid;
            BrokerException be = new BrokerException(errStr, Status.NOT_FOUND);
            props.put("JMQStatus", getErrorReplyStatus(be));
            throw new JMSServiceException(errStr, be, props);
        }
        txnUID = (TransactionUID) oo[1];
    } else {
        txnUID = new TransactionUID(transactionId);
    }
    try {
        protocol.prepareTransaction(txnUID, cxn);
    } catch (BrokerException be) {
        String errStr = "prepareTransaction: prepare transaction failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId + ", XID: " + xid;
        logger.logStack(Logger.ERROR, errStr, be);
        props.put("JMQStatus", getErrorReplyStatus(be));
        throw new JMSServiceException(errStr, be, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQTransactionID", txnUID.longValue());
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 17 with JMQXid

use of com.sun.messaging.jmq.util.JMQXid in project openmq by eclipse-ee4j.

the class JMSServiceImpl method rollbackTransaction.

@Override
public JMSServiceReply rollbackTransaction(long connectionId, long transactionId, Xid xid, boolean redeliver, boolean setRedelivered, int maxRollbacks, boolean dmqOnMaxRollbacks) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    TransactionUID txnUID = null;
    JMQXid jmqXid = null;
    cxn = checkConnectionId(connectionId, "rollbackTransaction");
    txnUID = new TransactionUID(transactionId);
    if (xid != null) {
        jmqXid = new JMQXid(xid);
    }
    try {
        protocol.rollbackTransaction(txnUID, jmqXid, cxn, redeliver, setRedelivered, maxRollbacks, dmqOnMaxRollbacks);
    } catch (BrokerException be) {
        String errStr = "rollbackTransaction: rollback transaction failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId + ", XID: " + xid;
        logger.logStack(Logger.ERROR, errStr, be);
        props.put("JMQStatus", getErrorReplyStatus(be));
        throw new JMSServiceException(errStr, be, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQTransactionID", txnUID.longValue());
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 18 with JMQXid

use of com.sun.messaging.jmq.util.JMQXid in project openmq by eclipse-ee4j.

the class JMSServiceImpl method endTransaction.

/**
 * End a transaction.
 *
 * @param connectionId The Id of the connection
 * @param transactionId If non-zero, the transaction being ended is identified by this broker-generated id
 * @param xid If transactionId is zero, then xid contains the Xid of the XA transaction being ended
 * @param flags If this is an XA transaction, then flags is one of:
 * <UL>
 * <LI>XAResource.TMSUSPEND: If suspending a transaction</LI>
 * <LI>XAResource.TMFAIL: If failing a transaction</LI>
 * <LI>XAResource.TMSUCCESS: If ending a transaction</LI>
 * </UL>
 *
 * @return The JMSServiceReply of the request to end a transaction
 *
 * @throws JMSServiceException if the Status returned for the endTransaction method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSServiceReply.Status#getJMQTransactionID
 *
 * @see JMSServiceReply.Status#BAD_REQUEST
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#PRECONDITION_FAILED
 * @see JMSServiceReply.Status#TIMEOUT
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply endTransaction(long connectionId, long transactionId, Xid xid, int flags) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    TransactionUID txnUID = null;
    JMQXid jmqXid = null;
    Integer xaFlags = null;
    cxn = checkConnectionId(connectionId, "endTransaction");
    txnUID = new TransactionUID(transactionId);
    if (xid != null) {
        jmqXid = new JMQXid(xid);
        xaFlags = Integer.valueOf(flags);
    }
    try {
        protocol.endTransaction(txnUID, jmqXid, xaFlags, cxn);
    } catch (BrokerException be) {
        String errStr = "endTransaction: end transaction failed. Connection ID: " + connectionId + ", Transaction ID: " + transactionId + ", XID: " + xid;
        logger.logStack(Logger.ERROR, errStr, be);
        props.put("JMQStatus", getErrorReplyStatus(be));
        throw new JMSServiceException(errStr, be, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    props.put("JMQTransactionID", txnUID.longValue());
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) JMQXid(com.sun.messaging.jmq.util.JMQXid)

Example 19 with JMQXid

use of com.sun.messaging.jmq.util.JMQXid in project openmq by eclipse-ee4j.

the class ProtocolImpl method recoverTransaction.

/**
 * Recover a transaction.
 *
 * @param id id to recover or null if all
 */
@Override
public JMQXid[] recoverTransaction(TransactionUID id) {
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.RECOVER TRANSACTION:TID=" + id);
    }
    // TransactionHandler handler = (TransactionHandler)
    // pr.getHandler(PacketType.START_TRANSACTION);
    TransactionList[] tls = DL.getTransactionList(null);
    TransactionList tl = null;
    TransactionState ts = null;
    Map<TransactionList, Vector> map = new LinkedHashMap<>();
    Vector v = null;
    for (int i = 0; i < tls.length; i++) {
        tl = tls[i];
        if (id == null) {
            v = tl.getTransactions(TransactionState.PREPARED);
            map.put(tl, v);
        } else {
            ts = tl.retrieveState(id);
            if (ts == null) {
                continue;
            }
            if (ts.getState() == TransactionState.PREPARED) {
                v = new Vector();
                v.add(id);
                map.put(tl, v);
                break;
            }
        }
    }
    ArrayList xids = new ArrayList();
    for (Map.Entry<TransactionList, Vector> pair : map.entrySet()) {
        tl = pair.getKey();
        v = pair.getValue();
        Iterator itr = v.iterator();
        while (itr.hasNext()) {
            TransactionUID tuid = (TransactionUID) itr.next();
            TransactionState _ts = tl.retrieveState(tuid);
            if (_ts == null) {
                // Should never happen
                continue;
            }
            JMQXid _xid = _ts.getXid();
            xids.add(_xid);
        }
    }
    return (JMQXid[]) xids.toArray(new JMQXid[xids.size()]);
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) JMQXid(com.sun.messaging.jmq.util.JMQXid) LinkedHashMap(java.util.LinkedHashMap) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Iterator(java.util.Iterator) Vector(java.util.Vector) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with JMQXid

use of com.sun.messaging.jmq.util.JMQXid in project openmq by eclipse-ee4j.

the class UpgradeHAStore method upgradeTxns.

/**
 * Upgrade transactions
 */
private void upgradeTxns(Connection conn) throws BrokerException {
    TransactionDAO txnDAO = dbMgr.getDAOFactory().getTransactionDAO();
    // Non-HA table
    String oldtxntbl = TransactionDAO.TABLE_NAME_PREFIX + "S" + brokerID;
    // SQL to select all transactions from version Non_HA table
    String getAllTxnsFromOldSQL = new StringBuilder(128).append("SELECT ").append(TransactionDAO.ID_COLUMN).append(", ").append(TransactionDAO.TYPE_COLUMN).append(", ").append(TransactionDAO.STATE_COLUMN).append(", ").append(TransactionDAO.TXN_STATE_COLUMN).append(", ").append(TransactionDAO.TXN_HOME_BROKER_COLUMN).append(", ").append(TransactionDAO.TXN_BROKERS_COLUMN).append(", ").append(TransactionDAO.STORE_SESSION_ID_COLUMN).append(" FROM ").append(oldtxntbl).append(" WHERE ").append(TransactionDAO.ID_COLUMN).append(" NOT IN (SELECT ").append(TransactionDAO.ID_COLUMN).append(" FROM ").append(txnDAO.getTableName()).append(')').toString();
    // SQL to insert transactions to new table
    String insertTxnSQL = new StringBuilder(128).append("INSERT INTO ").append(txnDAO.getTableName()).append(" ( ").append(TransactionDAO.ID_COLUMN).append(", ").append(TransactionDAO.TYPE_COLUMN).append(", ").append(TransactionDAO.STATE_COLUMN).append(", ").append(TransactionDAO.AUTO_ROLLBACK_COLUMN).append(", ").append(TransactionDAO.XID_COLUMN).append(", ").append(TransactionDAO.TXN_STATE_COLUMN).append(", ").append(TransactionDAO.TXN_HOME_BROKER_COLUMN).append(", ").append(TransactionDAO.TXN_BROKERS_COLUMN).append(", ").append(TransactionDAO.STORE_SESSION_ID_COLUMN).append(", ").append(TransactionDAO.EXPIRED_TS_COLUMN).append(", ").append(TransactionDAO.ACCESSED_TS_COLUMN).append(") VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )").toString();
    boolean dobatch = dbMgr.supportsBatchUpdates();
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rs = null;
    TransactionUID tid = null;
    Exception myex = null;
    try {
        pstmt = dbMgr.createPreparedStatement(conn, insertTxnSQL);
        stmt = conn.createStatement();
        rs = dbMgr.executeQueryStatement(stmt, getAllTxnsFromOldSQL);
        while (rs.next()) {
            long id = rs.getLong(1);
            tid = new TransactionUID(id);
            int type = rs.getInt(2);
            int state = rs.getInt(3);
            TransactionState txnState = (TransactionState) Util.readObject(rs, 4);
            txnState.setState(state);
            BrokerAddress txnHomeBroker = (BrokerAddress) Util.readObject(rs, 5);
            TransactionBroker[] txnBrokers = (TransactionBroker[]) Util.readObject(rs, 6);
            long sessionID = rs.getLong(7);
            // insert in new table
            try {
                pstmt.setLong(1, id);
                pstmt.setInt(2, type);
                pstmt.setInt(3, state);
                pstmt.setInt(4, txnState.getType().intValue());
                JMQXid jmqXid = txnState.getXid();
                if (jmqXid != null) {
                    pstmt.setString(5, jmqXid.toString());
                } else {
                    pstmt.setNull(5, Types.VARCHAR);
                }
                Util.setObject(pstmt, 6, txnState);
                Util.setObject(pstmt, 7, txnHomeBroker);
                Util.setObject(pstmt, 8, txnBrokers);
                pstmt.setLong(9, sessionID);
                pstmt.setLong(10, txnState.getExpirationTime());
                pstmt.setLong(11, txnState.getLastAccessTime());
                if (dobatch) {
                    pstmt.addBatch();
                } else {
                    pstmt.executeUpdate();
                }
            } catch (IOException e) {
                IOException ex = DBManager.wrapIOException("[" + insertTxnSQL + "]", e);
                throw ex;
            } catch (SQLException e) {
                SQLException ex = DBManager.wrapSQLException("[" + insertTxnSQL + "]", e);
                throw ex;
            }
        }
        if (dobatch) {
            pstmt.executeBatch();
        }
        conn.commit();
    } catch (Exception e) {
        myex = e;
        String errorMsg = br.getKString(BrokerResources.X_JDBC_UPGRADE_TRANSACTIONS_FAILED, (tid == null ? "loading" : tid.toString()));
        logger.logStack(Logger.ERROR, errorMsg, e);
        throw new BrokerException(errorMsg, e);
    } finally {
        Util.close(rs, stmt, null, myex);
        Util.close(null, pstmt, null, myex);
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) JMQXid(com.sun.messaging.jmq.util.JMQXid) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker)

Aggregations

JMQXid (com.sun.messaging.jmq.util.JMQXid)39 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)13 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)9 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)6 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)6 XidImpl (com.sun.messaging.jmq.util.XidImpl)4 JMSException (jakarta.jms.JMSException)4 Hashtable (java.util.Hashtable)4 XAException (javax.transaction.xa.XAException)4 JMSRASessionAdapter (com.sun.messaging.jms.ra.api.JMSRASessionAdapter)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)2 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)2 TransactionHandler (com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler)2 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)2 UnknownTransactionException (com.sun.messaging.jmq.jmsserver.util.UnknownTransactionException)2 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)2