boolean dobatch = dbMgr.supportsBatchUpdates() && !dbMgr.isHADB();
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rs = null;
TransactionUID tid = null;
Exception myex = null;
try {
pstmt = conn.prepareStatement(insertTxnSQL);
stmt = conn.createStatement();
rs = stmt.executeQuery(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 );