Skip to content

Commit 875f327

Browse files
author
Zhen Li
committed
Fix after review
1 parent 07d4e95 commit 875f327

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

examples/src/main/java/org/neo4j/docs/driver/RxAutocommitTransactionExample.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.neo4j.docs.driver;
2020

2121
import io.reactivex.Flowable;
22-
import org.reactivestreams.Publisher;
2322
import reactor.core.publisher.Flux;
2423

2524
import java.util.Collections;
@@ -34,7 +33,7 @@ public RxAutocommitTransactionExample( String uri, String user, String password
3433
super( uri, user, password );
3534
}
3635

37-
public Publisher<String> readProductTitlesReactor()
36+
public Flux<String> readProductTitlesReactor()
3837
{
3938
// tag::reactor-autocommit-transaction[]
4039
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";
@@ -46,7 +45,7 @@ public Publisher<String> readProductTitlesReactor()
4645
// end::reactor-autocommit-transaction[]
4746
}
4847

49-
public Publisher<String> readProductTitlesRxJava()
48+
public Flowable<String> readProductTitlesRxJava()
5049
{
5150
// tag::RxJava-autocommit-transaction[]
5251
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";

examples/src/main/java/org/neo4j/docs/driver/RxExplicitTransactionExample.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
package org.neo4j.docs.driver;
2020

2121
import io.reactivex.Flowable;
22-
import org.reactivestreams.Publisher;
2322
import reactor.core.publisher.Flux;
24-
import reactor.core.publisher.Mono;
2523

2624
import java.util.Collections;
2725
import java.util.Map;
@@ -36,21 +34,23 @@ public RxExplicitTransactionExample( String uri, String user, String password )
3634
super( uri, user, password );
3735
}
3836

39-
public Publisher<String> readSingleProductReactor()
37+
public Flux<String> readSingleProductReactor()
4038
{
4139
// tag::reactor-explicit-transaction[]
4240
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";
4341
Map<String,Object> parameters = Collections.singletonMap( "id", 0 );
4442

4543
RxSession session = driver.rxSession();
46-
return Mono.usingWhen( session.beginTransaction(),
47-
tx -> Flux.from( tx.run( query, parameters ).records() ).single().map( record -> record.get( 0 ).asString() ),
44+
// It is recommended to use Flux.usingWhen for explicit transactions and Flux.using for autocommit transactions (session).
45+
// This is because an explicit transaction needs to be supplied via a another resource publisher session.beginTransaction.
46+
return Flux.usingWhen( session.beginTransaction(),
47+
tx -> Flux.from( tx.run( query, parameters ).records() ).map( record -> record.get( 0 ).asString() ),
4848
RxTransaction::commit,
4949
RxTransaction::rollback );
5050
// end::reactor-explicit-transaction[]
5151
}
5252

53-
public Publisher<String> readSingleProductRxJava()
53+
public Flowable<String> readSingleProductRxJava()
5454
{
5555
// tag::RxJava-explicit-transaction[]
5656
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";
@@ -59,7 +59,8 @@ public Publisher<String> readSingleProductRxJava()
5959
RxSession session = driver.rxSession();
6060
return Flowable.fromPublisher( session.beginTransaction() )
6161
.flatMap( tx -> Flowable.fromPublisher( tx.run( query, parameters ).records() ).map( record -> record.get( 0 ).asString() )
62-
.doOnComplete( tx::commit ).doOnError( error -> tx.rollback() ) );
62+
.doOnComplete( tx::commit )
63+
.doOnError( error -> tx.rollback() ) );
6364
// end::RxJava-explicit-transaction[]
6465
}
6566
}

examples/src/main/java/org/neo4j/docs/driver/RxTransactionFunctionExample.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.neo4j.docs.driver;
2020

2121
import io.reactivex.Flowable;
22-
import org.reactivestreams.Publisher;
2322
import reactor.core.publisher.Flux;
2423
import reactor.core.publisher.Mono;
2524

@@ -37,7 +36,7 @@ public RxTransactionFunctionExample( String uri, String user, String password )
3736
super( uri, user, password );
3837
}
3938

40-
public Publisher<ResultSummary> printAllProductsReactor()
39+
public Flux<ResultSummary> printAllProductsReactor()
4140
{
4241
// tag::reactor-transaction-function[]
4342
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";
@@ -53,7 +52,7 @@ public Publisher<ResultSummary> printAllProductsReactor()
5352
// end::reactor-transaction-function[]
5453
}
5554

56-
public Publisher<ResultSummary> printAllProductsRxJava()
55+
public Flowable<ResultSummary> printAllProductsRxJava()
5756
{
5857
// tag::RxJava-transaction-function[]
5958
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";

0 commit comments

Comments
 (0)