Skip to content

Commit

Permalink
Handle constrain violation in JDBC drivers which does not throw SQLIn…
Browse files Browse the repository at this point in the history
…tegrityConstraintViolationException
  • Loading branch information
ZiyamSanthosh committed Jun 10, 2024
1 parent 92db6fe commit 6930189
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,19 @@ public void storeUserSessionData(String userId, String sessionId) throws UserSes
}
} catch (SQLIntegrityConstraintViolationException e1) {
IdentityDatabaseUtil.rollbackTransaction(connection);
if (isExistingMapping(userId, sessionId)) {
throw new DuplicatedAuthUserException("Mapping between user Id: " + userId + " and session Id: "
+ sessionId + " already exists in the database.", e1);
} catch (SQLException e1) {
IdentityDatabaseUtil.rollbackTransaction(connection);
// Handle constrain violation issue in JDBC drivers which does not throw
// SQLIntegrityConstraintViolationException
if (StringUtils.containsIgnoreCase(e1.getMessage(), "USER_SESSION_STORE_CONSTRAINT")) {
throw new DuplicatedAuthUserException("Mapping between user Id: " + userId + " and session Id: "
+ sessionId + " already exists in the database.", e1);
} else {
throw new UserSessionException("Error while storing mapping between user Id: " + userId +
" and session Id: " + sessionId, e1);
}
} catch (SQLException e1) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new UserSessionException("Error while storing mapping between user Id: " + userId +
" and session Id: " + sessionId, e1);
}
} catch (SQLException e) {
throw new UserSessionException("Error while storing mapping between user Id: " + userId +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,8 @@ public void testExceptionAtStoreUserSessionDataForDuplicatedSession(String userI
Exception {

try (Connection connection = getConnection(DB_NAME);
Connection connection1 = getConnection(DB_NAME);
MockedStatic<IdentityDatabaseUtil> identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class)) {
mockIdentityDataBaseUtilConnection(connection, true, identityDatabaseUtil);
mockIdentityDataBaseUtilConnection(connection1, false, identityDatabaseUtil);
UserSessionStore.getInstance().storeUserSessionData(userId, sessionId);
}
}
Expand Down

0 comments on commit 6930189

Please sign in to comment.