use of org.folio.rest.persist.PostgresClient.TotaledResults in project raml-module-builder by folio-org.
the class PostgresClientIT method processQueryWithCountBelowOffset.
// offset >= estimated total https://issues.folio.org/browse/RMB-684
@Test
public void processQueryWithCountBelowOffset(TestContext context) {
postgresClient = createNumbers(context, 1, 2, 3, 4, 5);
postgresClient.startTx(context.asyncAssertSuccess(conn -> {
QueryHelper queryHelper = new QueryHelper("numbers");
queryHelper.selectQuery = "SELECT i FROM numbers ORDER BY i OFFSET 2";
queryHelper.offset = 2;
// estimation=1 is below offset=2
queryHelper.countQuery = "SELECT 1";
Function<TotaledResults, Results<Integer>> resultSetMapper = totaledResults -> {
context.verify(verify -> {
assertThat(totaledResults.estimatedTotal, is(1));
assertThat(totaledResults.set.size(), is(3));
});
return null;
};
postgresClient.processQueryWithCount(conn.conn, queryHelper, "statMethod", resultSetMapper).onComplete(context.asyncAssertSuccess());
}));
}
use of org.folio.rest.persist.PostgresClient.TotaledResults in project raml-module-builder by folio-org.
the class Conn method get.
/**
* Return records selected by {@link CQLWrapper} filter.
*
* @param table - table to query
* @param clazz - class of objects to be returned
* @param fieldName - database column to return, for example @link {@link PostgresClient#DEFAULT_JSONB_FIELD_NAME}
* @param wrapper - filter to select records
* @param returnCount - whether to return totalRecords, the number of matching records when disabling OFFSET and LIMIT
* @param returnIdField - if the id field should also be returned, must be true for facets
* @param facets - fields to calculate counts for
* @param distinctOn - database column to calculate the number of distinct values for, null or empty string for none
*/
public <T> Future<Results<T>> get(String table, Class<T> clazz, String fieldName, CQLWrapper wrapper, boolean returnCount, boolean returnIdField, List<FacetField> facets, String distinctOn) {
try {
QueryHelper queryHelper = postgresClient.buildQueryHelper(table, fieldName, wrapper, returnIdField, facets, distinctOn);
Function<TotaledResults, Results<T>> resultSetMapper = totaledResults -> postgresClient.processResults(totaledResults.set, totaledResults.estimatedTotal, queryHelper.offset, queryHelper.limit, clazz);
if (returnCount) {
return postgresClient.processQueryWithCount(pgConnection, queryHelper, "get", resultSetMapper);
} else {
return Future.future(promise -> postgresClient.processQuery(pgConnection, queryHelper, null, "get", resultSetMapper, promise));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return Future.failedFuture(e);
}
}
Aggregations