@@ -113,14 +113,29 @@ public static void addPermissionToRoleOrDoNothingIfExists_Transaction(Start star
113113 });
114114 }
115115
116- public static boolean deleteRole (Start start , AppIdentifier appIdentifier , String role )
117- throws SQLException , StorageQueryException {
118- String QUERY = "DELETE FROM " + getConfig (start ).getRolesTable ()
119- + " WHERE app_id = ? AND role = ? ;" ;
120- return update (start , QUERY , pst -> {
121- pst .setString (1 , appIdentifier .getAppId ());
122- pst .setString (2 , role );
123- }) == 1 ;
116+ public static boolean deleteRole (Start start , AppIdentifier appIdentifier , String role ) throws SQLException , StorageQueryException {
117+
118+ try {
119+ return start .startTransaction (con -> {
120+ // Row lock must be taken to delete the role, otherwise the table may be locked for delete
121+ Connection sqlCon = (Connection ) con .getConnection ();
122+ ((ConnectionWithLocks ) sqlCon ).lock (appIdentifier .getAppId () + "~" + role + Config .getConfig (start ).getRolesTable ());
123+
124+ String QUERY = "DELETE FROM " + getConfig (start ).getRolesTable ()
125+ + " WHERE app_id = ? AND role = ? ;" ;
126+
127+ try {
128+ return update (sqlCon , QUERY , pst -> {
129+ pst .setString (1 , appIdentifier .getAppId ());
130+ pst .setString (2 , role );
131+ }) == 1 ;
132+ } catch (SQLException e ) {
133+ throw new StorageTransactionLogicException (e );
134+ }
135+ });
136+ } catch (StorageTransactionLogicException e ) {
137+ throw new StorageQueryException (e .actualException );
138+ }
124139 }
125140
126141 public static boolean doesRoleExist (Start start , AppIdentifier appIdentifier , String role )
0 commit comments