diff --git a/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java b/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java index 9136a640b42..3d0c3f56309 100644 --- a/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java +++ b/framework/cluster/src/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java @@ -53,14 +53,15 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase listOrphanMsids() { List orphanList = new ArrayList(); + TransactionLegacy txn = TransactionLegacy.currentTxn(); - try (PreparedStatement pstmt = - txn.prepareStatement("select t.mgmt_server_id from (select mgmt_server_id, count(*) as count from host group by mgmt_server_id) as t WHERE t.count > 0 AND t.mgmt_server_id NOT IN (select msid from mshost)");) - { - try(ResultSet rs = pstmt.executeQuery();) { - while (rs.next()) { - orphanList.add(rs.getLong(1)); - } - }catch (SQLException e) { - throw new CloudRuntimeException("listOrphanMsids:Exception:" + e.getMessage(), e); + PreparedStatement pstmt = null; + try { + pstmt = + txn.prepareAutoCloseStatement("select t.mgmt_server_id from (select mgmt_server_id, count(*) as count from host group by mgmt_server_id) as t WHERE t.count > 0 AND t.mgmt_server_id NOT IN (select msid from mshost)"); + + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + orphanList.add(rs.getLong(1)); } - return orphanList; } catch (SQLException e) { - throw new CloudRuntimeException("listOrphanMsids:Exception:" + e.getMessage(), e); + throw new CloudRuntimeException("DB exception on " + pstmt.toString(), e); } + + return orphanList; } @Override