rhtyd commented on a change in pull request #4268:
URL: https://github.com/apache/cloudstack/pull/4268#discussion_r471031355
##########
File path: framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
##########
@@ -850,13 +853,23 @@ public int update(UpdateBuilder ub, final
SearchCriteria<?> sc, Integer rows) {
ub.clear();
return result;
} catch (final SQLException e) {
- if (e.getSQLState().equals("23000") && e.getErrorCode() == 1062) {
- throw new EntityExistsException("Entity already exists ", e);
- }
+ handleEntityExistsException(e);
throw new CloudRuntimeException("DB Exception on: " + pstmt, e);
}
}
+ /**
+ * If the SQLException.getSQLState is of 23000 (Integrity Constraint
Violation), and the Error Code is 1062 (Duplicate Entry), throws
EntityExistsException.
+ * @throws EntityExistsException
+ */
+ protected static void handleEntityExistsException(SQLException e) throws
EntityExistsException {
+ boolean isIntegrityConstantViolation =
INTEGRITY_CONSTRAINT_VIOLATION.equals(e.getSQLState());
Review comment:
+1 to this parrent to check contant.equals(potentially-nullable-obj)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]