Skip to content

Instantly share code, notes, and snippets.

@juarezjuniorgithub
Created November 14, 2023 14:33
Show Gist options
  • Select an option

  • Save juarezjuniorgithub/8c7cffdc67939db692ff6c74e12cf00c to your computer and use it in GitHub Desktop.

Select an option

Save juarezjuniorgithub/8c7cffdc67939db692ff6c74e12cf00c to your computer and use it in GitHub Desktop.
OracleR2dbcProjectReactor.java
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