use of com.couchbase.client.java.query.SimpleN1qlQuery in project cas by apereo.
the class CouchbaseClientFactory method query.
/**
* Query and get a result by username.
*
* @param usernameAttribute the username attribute
* @param usernameValue the username value
* @return the n1ql query result
* @throws GeneralSecurityException the general security exception
*/
public N1qlQueryResult query(final String usernameAttribute, final String usernameValue) throws GeneralSecurityException {
final Statement statement = Select.select("*").from(Expression.i(getBucket().name())).where(Expression.x(usernameAttribute).eq('\'' + usernameValue + '\''));
LOGGER.debug("Running query [{}] on bucket [{}]", statement.toString(), getBucket().name());
final SimpleN1qlQuery query = N1qlQuery.simple(statement);
final N1qlQueryResult result = getBucket().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;
}
Aggregations