public Client findClient ( String clientUUID , Integer profileId ) throws Exception { Client client = null ; /* ERROR CODE: 500 WHEN TRYING TO DELETE A SERVER GROUP. THIS APPEARS TO BE BECAUSE CLIENT UUID IS NULL. */ /* CODE ADDED TO PREVENT NULL POINTERS. */ if ( clientUUID == null ) { clientUUID = "" ; } // first see if the clientUUID is actually a uuid.. it might be a friendlyName and need conversion /* A UUID IS A UNIVERSALLY UNIQUE IDENTIFIER. */ if ( clientUUID . compareTo ( Constants . PROFILE_CLIENT_DEFAULT_ID ) != 0 && ! clientUUID . matches ( "[\\w]{8}-[\\w]{4}-[\\w]{4}-[\\w]{4}-[\\w]{12}" ) ) { Client tmpClient = this . findClientFromFriendlyName ( profileId , clientUUID ) ; // if we can't find a client then fall back to the default ID if ( tmpClient == null ) { clientUUID = Constants . PROFILE_CLIENT_DEFAULT_ID ; } else { return tmpClient ; } } PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { String queryString = "SELECT * FROM " + Constants . DB_TABLE_CLIENT + " WHERE " + Constants . CLIENT_CLIENT_UUID + " = ?" ; if ( profileId != null ) { queryString += " AND " + Constants . GENERIC_PROFILE_ID + "=?" ; } statement = sqlConnection . prepareStatement ( queryString ) ; statement . setString ( 1 , clientUUID ) ; if ( profileId != null ) { statement . setInt ( 2 , profileId ) ; } results = statement . executeQuery ( ) ; if ( results . next ( ) ) { client = this . getClientFromResultSet ( results ) ; } } catch ( Exception e ) { throw e ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } return client ; }
Returns a Client object for a clientUUID and profileId