public N1qlQueryResult query ( final String usernameAttribute , final String usernameValue ) throws GeneralSecurityException { val theBucket = getBucket ( ) ; val statement = Select . select ( "*" ) . from ( Expression . i ( theBucket . name ( ) ) ) . where ( Expression . x ( usernameAttribute ) . eq ( ' ' + usernameValue + ' ' ) ) ; LOGGER . debug ( "Running query [{}] on bucket [{}]" , statement . toString ( ) , theBucket . name ( ) ) ; val query = N1qlQuery . simple ( statement ) ; val result = theBucket . query ( query , timeout , TimeUnit . MILLISECONDS ) ; if ( ! result . finalSuccess ( ) ) { LOGGER . error ( "Couchbase query failed with [{}]" , result . errors ( ) . stream ( ) . map ( JsonObject :: toString ) . collect ( Collectors . joining ( "," ) ) ) ; throw new GeneralSecurityException ( "Could not locate account for user " + usernameValue ) ; } return result ; }
Query and get a result by username .