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);
}
}
Aggregations