use of org.folio.services.RecordSearchParameters in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method streamMarcRecordIds.
@Override
public Flowable<Row> streamMarcRecordIds(ParseLeaderResult parseLeaderResult, ParseFieldsResult parseFieldsResult, RecordSearchParameters searchParameters, String tenantId) {
/* Building a search query */
SelectJoinStep searchQuery = DSL.selectDistinct(RECORDS_LB.EXTERNAL_ID).from(RECORDS_LB);
appendJoin(searchQuery, parseLeaderResult, parseFieldsResult);
appendWhere(searchQuery, parseLeaderResult, parseFieldsResult, searchParameters);
if (searchParameters.getOffset() != null) {
searchQuery.offset(searchParameters.getOffset());
}
if (searchParameters.getLimit() != null) {
searchQuery.limit(searchParameters.getLimit());
}
/* Building a count query */
SelectJoinStep countQuery = DSL.select(countDistinct(RECORDS_LB.EXTERNAL_ID)).from(RECORDS_LB);
appendJoin(countQuery, parseLeaderResult, parseFieldsResult);
appendWhere(countQuery, parseLeaderResult, parseFieldsResult, searchParameters);
/* Join both in one query */
String sql = DSL.select().from(searchQuery).rightJoin(countQuery).on(DSL.trueCondition()).getSQL(ParamType.INLINED);
return getCachedPool(tenantId).rxGetConnection().flatMapPublisher(conn -> conn.rxBegin().flatMapPublisher(tx -> conn.rxPrepare(sql).flatMapPublisher(pq -> pq.createStream(10000).toFlowable().map(this::toRow)).doAfterTerminate(tx::commit)));
}
Aggregations