public void increasePriority ( int overrideId , int ordinal , int pathId , String clientUUID ) { logger . info ( "Increase priority" ) ; int origPriority = - 1 ; int newPriority = - 1 ; int origId = 0 ; int newId = 0 ; PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { results = null ; statement = sqlConnection . prepareStatement ( "SELECT * FROM " + Constants . DB_TABLE_ENABLED_OVERRIDE + " WHERE " + Constants . ENABLED_OVERRIDES_PATH_ID + " = ?" + " AND " + Constants . GENERIC_CLIENT_UUID + " = ?" + " ORDER BY " + Constants . ENABLED_OVERRIDES_PRIORITY ) ; statement . setInt ( 1 , pathId ) ; statement . setString ( 2 , clientUUID ) ; results = statement . executeQuery ( ) ; int ordinalCount = 0 ; while ( results . next ( ) ) { if ( results . getInt ( Constants . ENABLED_OVERRIDES_OVERRIDE_ID ) == overrideId ) { ordinalCount ++ ; if ( ordinalCount == ordinal ) { origPriority = results . getInt ( Constants . ENABLED_OVERRIDES_PRIORITY ) ; origId = results . getInt ( Constants . GENERIC_ID ) ; break ; } } newPriority = results . getInt ( Constants . ENABLED_OVERRIDES_PRIORITY ) ; newId = results . getInt ( Constants . GENERIC_ID ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } try ( Connection sqlConnection = sqlService . getConnection ( ) ) { // update priorities if ( origPriority != - 1 && newPriority != - 1 ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_ENABLED_OVERRIDE + " SET " + Constants . ENABLED_OVERRIDES_PRIORITY + "=?" + " WHERE " + Constants . GENERIC_ID + "=?" ) ; statement . setInt ( 1 , origPriority ) ; statement . setInt ( 2 , newId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_ENABLED_OVERRIDE + " SET " + Constants . ENABLED_OVERRIDES_PRIORITY + "=?" + " WHERE " + Constants . GENERIC_ID + "=?" ) ; statement . setInt ( 1 , newPriority ) ; statement . setInt ( 2 , origId ) ; statement . executeUpdate ( ) ; } } catch ( Exception e ) { } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } }
Increase the priority of an overrideId