server: Fix exception while update domain resource count (#3204)

This commit is contained in:
ustcweizhou 2019-04-29 08:51:08 +02:00 committed by dahn
parent 96611fc640
commit b60daf7142
1 changed files with 4 additions and 3 deletions

View File

@ -276,17 +276,18 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
}
private long executeSqlCountComputingResourcesForAccount(long accountId, String sqlCountComputingResourcesAllocatedToAccount) {
try (TransactionLegacy tx = TransactionLegacy.currentTxn()) {
TransactionLegacy tx = TransactionLegacy.currentTxn();
try {
PreparedStatement pstmt = tx.prepareAutoCloseStatement(sqlCountComputingResourcesAllocatedToAccount);
pstmt.setLong(1, accountId);
ResultSet rs = pstmt.executeQuery();
if (!rs.next()) {
throw new CloudRuntimeException(String.format("An unexpected case happened while counting allocated computing resources for account: " + accountId));
return 0L;
}
return rs.getLong("total");
} catch (SQLException e) {
throw new CloudRuntimeException(e);
}
}
}
}