There is one thing I have trouble understanding with quarkus. I use JPA with Oracle. So I have the error IllegalStateException: You have attempted to perform a blocking operation on an IO thread. This is not allowed, as blocking the IO thread I looked in the Quarkus doc how to go about making JPA calls without having this difficulty. But all the examples and the doc use PostgreSQL or MariaDB with responsive clients. But I have not found any for classic JDBC clients.
I found a solution that works partially.
Uni.cretaFrom().Items(() -> MyBlokingIOCall());
Indeed I no longer have the exception. But the MyBlokingIOCall method can raise exceptions. I think I can use Uni's onFailure but we cannot pass methods raising an exception to
Uni.cretaFrom().Items
Indeed this method has as argument a Supplier, therefore the exceptions must be captured. it's impossible to use Uni's onFailure with this solution. If I use the current code in imperative mode
try {
Response.ok (myService ());
} catch (throwable e) {
Response.status (555, e.getMessage ());
}
I tried in vain to do this in reactive form but I did not find a solution. I did not find any help. I imagined something like.
Uni.createFrom().Items(() -> myService())
.onItem().apply(data -> Response.ok(data))
.onFailure().apply(err -> Response.status(555, err.getMessage()))
But this causes a compilation error. indeed the method myService cannot be used in a Supplier because it throws an exception. it must therefore be captured. But then we no longer go into Uni's onFailure and we cannot trace the error we caught.
I think I think too much about wearing my imperative code instead of thinking differently.
But I can't find a doc or example that looks like this by any means. I imagine that there is a way of doing things (if not Quarkus would not exist). I think that when you think about it with the right approach, you have to find the doc, but when you don't know where to go, it's more complicated. I haven't found it because I don't know what I'm looking for.
I suppose I have to encapsulate the JPA call which produces a Uni or a Multi which is consumed by a processor which transforms the Entity into DTO which is then transmitted to the resource Rest layer which transforms the DTO into Response. the JPA call must be able to produce errors the processor too and the Resource layer too
It is, therefore, necessary at each step to capture these errors to propagate them through Uni or Multi
But how to do it?