From b60daf7142c337d4a9a9401de6f0a59454be0662 Mon Sep 17 00:00:00 2001 From: ustcweizhou Date: Mon, 29 Apr 2019 08:51:08 +0200 Subject: [PATCH] server: Fix exception while update domain resource count (#3204) --- .../com/cloud/configuration/dao/ResourceCountDaoImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/engine/schema/src/com/cloud/configuration/dao/ResourceCountDaoImpl.java b/engine/schema/src/com/cloud/configuration/dao/ResourceCountDaoImpl.java index 1de2b65aed1..82903104f90 100644 --- a/engine/schema/src/com/cloud/configuration/dao/ResourceCountDaoImpl.java +++ b/engine/schema/src/com/cloud/configuration/dao/ResourceCountDaoImpl.java @@ -276,17 +276,18 @@ public class ResourceCountDaoImpl extends GenericDaoBase } 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); } } -} \ No newline at end of file +}