public Client setFriendlyName ( int profileId , String clientUUID , String friendlyName ) throws Exception { // first see if this friendlyName is already in use Client client = this . findClientFromFriendlyName ( profileId , friendlyName ) ; if ( client != null && ! client . getUUID ( ) . equals ( clientUUID ) ) { throw new Exception ( "Friendly name already in use" ) ; } PreparedStatement statement = null ; int rowsAffected = 0 ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_CLIENT + " SET " + Constants . CLIENT_FRIENDLY_NAME + " = ?" + " WHERE " + Constants . CLIENT_CLIENT_UUID + " = ?" + " AND " + Constants . GENERIC_PROFILE_ID + " = ?" ) ; statement . setString ( 1 , friendlyName ) ; statement . setString ( 2 , clientUUID ) ; statement . setInt ( 3 , profileId ) ; rowsAffected = statement . executeUpdate ( ) ; } catch ( Exception e ) { } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } if ( rowsAffected == 0 ) { return null ; } return this . findClient ( clientUUID , profileId ) ; }
Set a friendly name for a client