use of org.folio.rest.jooq.Tables.RECORDS_LB in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method streamSourceRecords.
@Override
public Flowable<SourceRecord> streamSourceRecords(Condition condition, RecordType recordType, Collection<OrderField<?>> orderFields, int offset, int limit, String tenantId) {
Name prt = name(recordType.getTableName());
String sql = DSL.select(getRecordFields(prt)).from(RECORDS_LB).innerJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).where(condition.and(recordType.getSourceRecordImplicitCondition())).orderBy(orderFields).offset(offset).limit(limit).getSQL(ParamType.INLINED);
return getCachedPool(tenantId).rxGetConnection().flatMapPublisher(conn -> conn.rxBegin().flatMapPublisher(tx -> conn.rxPrepare(sql).flatMapPublisher(pq -> pq.createStream(1).toFlowable().map(this::toRow).map(this::toSourceRecord)).doAfterTerminate(tx::commit)));
}
use of org.folio.rest.jooq.Tables.RECORDS_LB 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)));
}
use of org.folio.rest.jooq.Tables.RECORDS_LB in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method streamRecords.
@Override
public Flowable<Record> streamRecords(Condition condition, RecordType recordType, Collection<OrderField<?>> orderFields, int offset, int limit, String tenantId) {
Name prt = name(recordType.getTableName());
String sql = DSL.select(getAllRecordFields(prt)).from(RECORDS_LB).leftJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).leftJoin(RAW_RECORDS_LB).on(RECORDS_LB.ID.eq(RAW_RECORDS_LB.ID)).leftJoin(ERROR_RECORDS_LB).on(RECORDS_LB.ID.eq(ERROR_RECORDS_LB.ID)).where(condition.and(recordType.getRecordImplicitCondition())).orderBy(orderFields).offset(offset).limit(limit).getSQL(ParamType.INLINED);
return getCachedPool(tenantId).rxGetConnection().flatMapPublisher(conn -> conn.rxBegin().flatMapPublisher(tx -> conn.rxPrepare(sql).flatMapPublisher(pq -> pq.createStream(1).toFlowable().map(this::toRow).map(this::toRecord)).doAfterTerminate(tx::commit)));
}
use of org.folio.rest.jooq.Tables.RECORDS_LB in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method getMatchedRecords.
public Future<List<Record>> getMatchedRecords(MatchField matchedField, TypeConnection typeConnection, int offset, int limit, String tenantId) {
Name prt = name(typeConnection.getDbType().getTableName());
Table marcIndexersPartitionTable = table(name("marc_indexers_" + matchedField.getTag()));
return getQueryExecutor(tenantId).transaction(txQE -> txQE.query(dsl -> dsl.select(getAllRecordFields(prt)).from(RECORDS_LB).leftJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).leftJoin(RAW_RECORDS_LB).on(RECORDS_LB.ID.eq(RAW_RECORDS_LB.ID)).leftJoin(ERROR_RECORDS_LB).on(RECORDS_LB.ID.eq(ERROR_RECORDS_LB.ID)).innerJoin(marcIndexersPartitionTable).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, marcIndexersPartitionTable, name(MARC_ID)))).where(filterRecordByType(typeConnection.getRecordType().value()).and(filterRecordByState(Record.State.ACTUAL.value())).and(getMatchedFieldCondition(matchedField, marcIndexersPartitionTable.getName()))).offset(offset).limit(limit > 0 ? limit : DEFAULT_LIMIT_FOR_GET_RECORDS))).map(queryResult -> queryResult.stream().map(res -> asRow(res.unwrap())).map(this::toRecord).collect(Collectors.toList()));
}
Aggregations