sureshanaparti commented on code in PR #6825:
URL: https://github.com/apache/cloudstack/pull/6825#discussion_r994024531


##########
usage/src/main/java/com/cloud/usage/UsageSanityChecker.java:
##########
@@ -69,48 +69,51 @@ protected boolean checkItemCountByPstmt(CheckCase 
checkCase) throws SQLException
         /*
          * Check for item usage records which are created after it is removed
          */
-        try (PreparedStatement pstmt = 
conn.prepareStatement(checkCase.sqlTemplate)) {
-            if(checkCase.checkId) {
-                pstmt.setInt(1, lastId);
-                pstmt.setInt(2, maxId);
-            }
-            try(ResultSet rs = pstmt.executeQuery();) {
-                if (rs.next() && (rs.getInt(1) > 0)) {
-                    errors.append(String.format("Error: Found %s %s\n", 
rs.getInt(1), checkCase.itemName));
-                    checkOk = false;
+        try (PreparedStatement pstmt = 
conn.prepareStatement(checkCase.getSqlTemplate())) {
+            if(checkCase.isCheckId()) {
+                if (lastId > 0) {
+                    pstmt.setInt(1, lastId);
+                }
+                if (maxId > lastId) {
+                    pstmt.setInt(2, maxId);
                 }
-            }catch (Exception e)
-            {
-                
s_logger.error("checkItemCountByPstmt:Exception:"+e.getMessage());
-                throw new 
CloudRuntimeException("checkItemCountByPstmt:Exception:"+e.getMessage(),e);
             }
+            checkOk = isCheckOkForPstmt(checkCase, checkOk, pstmt);
         }
         catch (Exception e)
         {
-            s_logger.error("checkItemCountByPstmt:Exception:"+e.getMessage());
-            throw new 
CloudRuntimeException("checkItemCountByPstmt:Exception:"+e.getMessage(),e);
+            throwPreparedStatementExcecutionException("preparing statement", 
checkCase.getSqlTemplate(), e);
+        }
+        return checkOk;
+    }
+
+    private boolean isCheckOkForPstmt(CheckCase checkCase, boolean checkOk, 
PreparedStatement pstmt) {
+        try(ResultSet rs = pstmt.executeQuery();) {
+            if (rs.next() && (rs.getInt(1) > 0)) {
+                errors.append(String.format("Error: Found %s %s%n", 
rs.getInt(1), checkCase.getItemName()));
+                checkOk = false;
+            }
+        }catch (Exception e)

Review Comment:
   ```suggestion
           } catch (Exception e)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to