Skip to content

Commit

Permalink
fix: inmemory test fix (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc authored Sep 21, 2023
1 parent 07e2ca6 commit a6a3d48
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,29 @@ public static void addPermissionToRoleOrDoNothingIfExists_Transaction(Start star
});
}

public static boolean deleteRole(Start start, AppIdentifier appIdentifier, String role)
throws SQLException, StorageQueryException {
String QUERY = "DELETE FROM " + getConfig(start).getRolesTable()
+ " WHERE app_id = ? AND role = ? ;";
return update(start, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, role);
}) == 1;
public static boolean deleteRole(Start start, AppIdentifier appIdentifier, String role) throws SQLException, StorageQueryException {

try {
return start.startTransaction(con -> {
// Row lock must be taken to delete the role, otherwise the table may be locked for delete
Connection sqlCon = (Connection) con.getConnection();
((ConnectionWithLocks) sqlCon).lock(appIdentifier.getAppId() + "~" + role + Config.getConfig(start).getRolesTable());

String QUERY = "DELETE FROM " + getConfig(start).getRolesTable()
+ " WHERE app_id = ? AND role = ? ;";

try {
return update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, role);
}) == 1;
} catch (SQLException e) {
throw new StorageTransactionLogicException(e);
}
});
} catch (StorageTransactionLogicException e) {
throw new StorageQueryException(e.actualException);
}
}

public static boolean doesRoleExist(Start start, AppIdentifier appIdentifier, String role)
Expand Down

0 comments on commit a6a3d48

Please sign in to comment.