use of org.folio.rest.persist.SQLConnection in project mod-source-record-manager by folio-org.
the class SourceRecordStateDaoImpl method save.
@Override
public Future<String> save(SourceRecordState state, String tenantId) {
state.withId(UUID.randomUUID().toString());
PostgresClient client = pgClientFactory.createInstance(tenantId);
return DbUtil.executeInTransaction(client, sqlConnection -> get(state.getSourceRecordId(), sqlConnection, tenantId).compose(sourceRecordStateOptional -> {
if (sourceRecordStateOptional.isPresent()) {
return update(state, sqlConnection, tenantId).map(state.getId());
} else {
return save(state, sqlConnection, tenantId);
}
}));
}
use of org.folio.rest.persist.SQLConnection in project mod-inventory-storage by folio-org.
the class ItemService method updateEffectiveCallNumbersAndLocation.
private Future<RowSet<Row>> updateEffectiveCallNumbersAndLocation(AsyncResult<SQLConnection> connectionResult, Collection<Item> items, HoldingsRecord holdingsRecord) {
final Promise<RowSet<Row>> allItemsUpdated = promise();
final var batchFactories = items.stream().map(item -> effectiveValuesService.populateEffectiveValues(item, holdingsRecord)).map(this::updateSingleItemBatchFactory).collect(toList());
final SQLConnection connection = connectionResult.result();
Future<RowSet<Row>> lastUpdate = succeededFuture();
for (var factory : batchFactories) {
lastUpdate = lastUpdate.compose(prev -> factory.apply(connection));
}
lastUpdate.onComplete(allItemsUpdated);
return allItemsUpdated.future();
}
use of org.folio.rest.persist.SQLConnection in project mod-source-record-manager by folio-org.
the class JobExecutionProgressDaoImpl method updateByJobExecutionId.
@Override
public Future<JobExecutionProgress> updateByJobExecutionId(String jobExecutionId, UnaryOperator<JobExecutionProgress> progressMutator, String tenantId) {
String rollbackMessage = String.format(ROLLBACK_MESSAGE, jobExecutionId);
Promise<JobExecutionProgress> promise = Promise.promise();
Promise<SQLConnection> tx = Promise.promise();
PostgresClient pgClient = pgClientFactory.createInstance(tenantId);
getSelectResult(tx, pgClient, jobExecutionId, tenantId).map(progressResults -> {
Optional<JobExecutionProgress> optionalJobExecutionProgress = mapResultSetToOptionalJobExecutionProgress(progressResults);
if (optionalJobExecutionProgress.isEmpty()) {
throw new NotFoundException(rollbackMessage);
}
return progressMutator.apply(optionalJobExecutionProgress.get());
}).compose(mutatedProgress -> updateProgressByJobExecutionId(tx.future(), mutatedProgress, tenantId)).onComplete(updateAr -> {
if (updateAr.succeeded()) {
pgClient.endTx(tx.future(), endTx -> promise.complete(updateAr.result()));
} else {
LOGGER.error(rollbackMessage, updateAr.cause());
pgClient.rollbackTx(tx.future(), r -> promise.fail(updateAr.cause()));
}
});
return promise.future();
}
use of org.folio.rest.persist.SQLConnection in project mod-source-record-manager by folio-org.
the class JobExecutionProgressDaoImpl method getSelectResult.
private Future<RowSet<Row>> getSelectResult(Promise<SQLConnection> tx, PostgresClient pgClient, String jobExecutionId, String tenantId) {
Tuple queryParams = Tuple.of(jobExecutionId);
return Future.succeededFuture().compose(v -> {
pgClient.startTx(tx);
return tx.future();
}).compose(sqlConnection -> {
String selectProgressQuery = buildSelectProgressQuery(tenantId);
Promise<RowSet<Row>> selectResult = Promise.promise();
pgClient.execute(tx.future(), selectProgressQuery, queryParams, selectResult);
return selectResult.future();
}).compose(selectResult -> {
Promise<RowSet<Row>> getProgressPromise = Promise.promise();
String query = buildSelectByJobExecutionIdQuery(tenantId);
pgClient.execute(tx.future(), query, queryParams, getProgressPromise);
return getProgressPromise.future();
});
}
use of org.folio.rest.persist.SQLConnection in project mod-circulation-storage by folio-org.
the class ExpirationTool method getExpiredRequests.
private static Future<List<Request>> getExpiredRequests(AsyncResult<SQLConnection> conn, Vertx vertx, String tenant) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
df.setTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC));
PostgresClient pgClient = PostgresClient.getInstance(vertx, tenant);
Promise<RowSet<Row>> promise = Promise.promise();
String where = format("WHERE " + "(jsonb->>'status' = '%1$s' AND jsonb->>'requestExpirationDate' < '%5$s') OR " + "(jsonb->>'status' = '%2$s' AND jsonb->>'requestExpirationDate' < '%5$s') OR " + "(jsonb->>'status' = '%3$s' AND jsonb->>'requestExpirationDate' < '%5$s') OR " + "(jsonb->>'status' = '%4$s' AND jsonb->>'holdShelfExpirationDate' < '%5$s') " + "LIMIT 150", OPEN_NOT_YET_FILLED.value(), OPEN_AWAITING_DELIVERY.value(), OPEN_IN_TRANSIT.value(), OPEN_AWAITING_PICKUP.value(), df.format(new Date()));
String fullTableName = format("%s.%s", PostgresClient.convertToPsqlStandard(tenant), REQUEST_TABLE);
String query = format("SELECT jsonb FROM %s %s", fullTableName, where);
pgClient.select(conn, query, promise);
return promise.future().map(rs -> rowSetToStream(rs).map(row -> row.get(JsonObject.class, row.getColumnIndex(JSONB_COLUMN))).map(json -> json.mapTo(Request.class)).collect(toList()));
}
Aggregations