Created
November 14, 2023 14:33
-
-
Save juarezjuniorgithub/8c7cffdc67939db692ff6c74e12cf00c to your computer and use it in GitHub Desktop.
OracleR2dbcProjectReactor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.oracle.dev.jdbc.r2dbc; | |
| import io.r2dbc.spi.Connection; | |
| import io.r2dbc.spi.ConnectionFactory; | |
| import reactor.core.publisher.Flux; | |
| import reactor.core.publisher.Mono; | |
| public class OracleR2dbcProjectReactor { | |
| private static final String QUERY = "SELECT * FROM CUSTOMERS"; | |
| public static void main(String[] args) { | |
| ConnectionFactory factory = DatabaseConfig.getConnectionFactory(); | |
| // Reactor Core - Example with Mono - | |
| // https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html | |
| Mono.from(factory.create()).flatMapMany(connection -> connection.createStatement(QUERY).execute()) | |
| .flatMap(result -> result.map((row, meta) -> row.get(0, String.class))).doOnNext(System.out::println) | |
| .blockLast(); | |
| System.out.println("-------------------------------------------------------"); | |
| // Reactor Core - Example with Flux - | |
| // https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Flux.html | |
| Flux.usingWhen(factory.create(), | |
| connection -> Mono.from(connection.createStatement(QUERY).execute()) | |
| .flatMapMany(result -> result.map((row, meta) -> row.get(0, String.class))), | |
| Connection::close).doOnNext(System.out::println).blockLast(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment