Skip to content
Advertisement

Updating webclient response from database

I have situation where I can’t update column at database. The problem is that only method setIsPurchased is executed and the flag is_purchase at SQL table changed to true, but the next line with setPurchasedDate which has to set current time is not executed. The response from database is Mono<Void> type.

fun purchase(uuid: UUID, request: PurchaseInternalRequest) =
        extraProductTransactionService.findTransactionByUuid(uuid)
            .doOnNext { it.validateNotPurchased() }
            .flatMap { purchaseViaSupplier(it, request) }
            .flatMap { extraProductTransactionService.setIsPurchased(uuid) }
            .flatMap { extraProductTransactionService.setPurchasedDate(uuid) }
            .onErrorMap(Exception::class.java) { Exception(it.status) }
            .then()

Queries for those two method are simple and looks like:

For setIsPurchased:

update extra_product_transactions SET is_purchased = 1 where uuid = :uuid

For setPurchasedDate:

update extra_product_transactions SET purchased_date = CURRENT_TIMESTAMP where uuid = :uuid

Advertisement

Answer

A Mono<Void> by essence never emits an element onNext(). Having said that, .flatMap { extraProductTransactionService.setPurchasedDate(uuid) } is never invoked.

I assume you are not interested in the return values of the set methods so you can do something like:

fun purchase(uuid: UUID, request: PurchaseInternalRequest) =
    extraProductTransactionService.findTransactionByUuid(uuid)
        .doOnNext { it.validateNotPurchased() }
        .flatMap { purchaseViaSupplier(it, request) }
        .flatMap { 
          extraProductTransactionService.setIsPurchased(uuid).subscribe()
          extraProductTransactionService.setPurchasedDate(uuid)
        }
        .onErrorMap(Exception::class.java) { Exception(it.status) }
        .then()
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement