oracle / oracle-r2dbc

R2DBC Driver for Oracle Database
https://oracle.com
Other
197 stars 40 forks source link

R2DBC integration with Mutiny example #65

Closed LazaroR94 closed 2 years ago

LazaroR94 commented 2 years ago

I am new to both reactive-programming and R2DBC. I have recently come to know about a reactive oracle API (R2DBC) and wanted to see how I can integrate this inside my Quarkus/Kotlin project using Mutiny. I've seen the Mutiny example on https://r2dbc.io but wanted to know how I can convert this to, let's say, an entity that maps to a table? Essentially, I want to only perform database inserts based on the given entities but I see that R2DBC's example is just a simple native query. How can I accomplish this? I am currently using Hibernate ORM with Panache.

I will post here a sample snippet of my current code using only Mutiny:

fun save(entity: SomeDatabaseEntity): Uni<Void> =
    Uni.createFrom().voidItem().invoke { -> someDatabaseRepository.persistEntity(entity) }

Is there a similar way that I can achieve the above with R2DBC? Any suggestions/tips are greatly appreciated, thanks!

Michael-A-McMahon commented 2 years ago

I think that Hibernate Reactive might be what you're looking for: http://hibernate.org/reactive/ Hibernate Reactive lets you continue to use Hibernate as an ORM, but it will offer non-blocking reactive APIs. And, just skimming through their documentation, it seems to offer tight integration with Mutiny.

Please note that I have no experience working with Hibernate, and so I'm not offering expert advice here. Just trying to point you in the right direction.

I don't think that Hibernate Reactive uses Oracle R2DBC. Instead, it seems to depend on the Vert.x Database Client. The good news is that the Vert.x team has done some great work to create a database client for Oracle Database: https://vertx.io/docs/4.2.0/vertx-oracle-client/java/

I believe that the Vert.x Oracle Client is built on top of Oracle JDBC's Reactive Extensions, just like Oracle R2DBC is. So it should offer functionality and performance that is comparable to Oracle R2DBC.

Michael-A-McMahon commented 2 years ago

Just thought that I should also mention Spring Data R2DBC. The Spring project has also done great work to provide a reactive ORM: https://spring.io/projects/spring-data-r2dbc

Spring Data R2DBC exposes the Flux and Mono types of Project Reactor. However, these types implement the org.reactivestreams.Publisher interface, so it should be possible to adapt them into Mutiny types. https://smallrye.io/smallrye-mutiny/guides/converters

Michael-A-McMahon commented 2 years ago

@LazaroR94 I hope I was able to help. I'm going to close this issue now, but please let me know if there's more to discuss.

Swe77 commented 9 months ago

I think the response is using this dependency:

<dependency>
    <groupId>io.smallrye.reactive</groupId>
    <artifactId>mutiny-reactor</artifactId>
    <version>1.6.0</version>
</dependency>

More details can be found in this link: https://smallrye.io/smallrye-mutiny/1.6.0/guides/converters/