Search in sources :

Example 26 with TransactionBroker

use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker 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

TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)26 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)10 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)9 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)8 IOException (java.io.IOException)8 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)7 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)6 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)6 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)6 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)5 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)4 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)4 HandshakeInProgressException (com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException)4 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)4 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)4 UID (com.sun.messaging.jmq.util.UID)4 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)4 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)3 BrokerDownException (com.sun.messaging.jmq.jmsserver.util.BrokerDownException)3 MaxConsecutiveRollbackException (com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException)3