Java源码示例:org.neo4j.driver.reactive.RxResult
示例1
Mono<ResultSummary> run() {
return doInQueryRunnerForMono(
targetDatabase,
runner -> prepareStatement().flatMap(t -> {
RxResult rxResult = runner.run(t.getT1(), t.getT2());
return Flux.from(rxResult.records()).then(Mono.from(rxResult.consume()));
})
).onErrorMap(RuntimeException.class, DefaultReactiveNeo4jClient.this::potentiallyConvertRuntimeException);
}
示例2
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public Publisher<String> get() {
return Multi.createFrom().resource(
driver::rxSession,
session -> session.readTransaction(tx -> {
RxResult result = tx.run("MATCH (f:Fruit) RETURN f.name as name ORDER BY f.name");
return Multi.createFrom().publisher(result.records())
.map(record -> record.get("name").asString());
})
).withFinalizer(session -> {
return Uni.createFrom().publisher(session.close());
});
}
示例3
@GET
@Path("/reactive")
@Produces(SERVER_SENT_EVENTS)
public Publisher<Integer> doStuffWithNeo4jReactive() {
return Flux.using(driver::rxSession, session -> session.readTransaction(tx -> {
RxResult result = tx.run("UNWIND range(1, 3) AS x RETURN x", Collections.emptyMap());
return Flux.from(result.records()).map(record -> record.get("x").asInt());
}), RxSession::close).doOnNext(System.out::println);
}
示例4
public Mono<ResultSummary> createPerson() {
return neo4jClient.delegateTo(rxQueryRunner -> {
RxResult rxResult = rxQueryRunner.run("CREATE (:SimplePerson {name: 'Tom'})");
return Flux.from(rxResult.records()).then(Mono.from(rxResult.consume()));
}).run();
}