Skip to content

Commit 8108ec2

Browse files
committed
rx module: add rx() mapper by default fix #386
1 parent 4eebaba commit 8108ec2

9 files changed

Lines changed: 180 additions & 221 deletions

File tree

jooby-mongodb-rx/src/main/java/org/jooby/mongodb/MongoRx.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
* execution, concise code, and functional composition of results.
7373
* </p>
7474
*
75+
* <p>
76+
* This module depends on {@link Rx} module, please read the {@link Rx} documentation before using
77+
* this module.
78+
* </p>
79+
*
7580
* <h2>exports</h2>
7681
* <ul>
7782
* <li>{@link MongoClient}</li>
@@ -80,12 +85,20 @@
8085
* <li>{@link Route.Mapper} for mongo observables</li>
8186
* </ul>
8287
*
88+
* <h2>depends on</h2>
89+
* <ul>
90+
* <li>{@link Rx rx module}</li>
91+
* </ul>
92+
*
8393
* <h2>usage</h2>
8494
* <pre>{@code
8595
*
8696
* import org.jooby.mongodb.MongoRx;
8797
*
8898
* {
99+
* // required by MongoRx
100+
* use(new Rx());
101+
*
89102
* use(new MongoRx());
90103
*
91104
* get("/", req -> {
@@ -110,6 +123,9 @@
110123
* </p>
111124
* <pre>{@code
112125
* {
126+
* // required by MongoRx
127+
* use(new Rx());
128+
*
113129
* use(new MongoRx("mongodb://localhost/mydb"));
114130
* }
115131
* }</pre>
@@ -120,6 +136,9 @@
120136
*
121137
* <pre>{@code
122138
* {
139+
* // required by MongoRx
140+
* use(new Rx());
141+
*
123142
* use(new MongoRx("mongodb://localhost/mydb"));
124143
*
125144
* get("/", req -> {
@@ -135,6 +154,9 @@
135154
*
136155
* <pre>{@code
137156
* {
157+
* // required by MongoRx
158+
* use(new Rx());
159+
*
138160
* use(new MongoRx("mongodb://localhost/mydb.mycol"));
139161
*
140162
* get("/", req -> {
@@ -151,6 +173,9 @@
151173
*
152174
* <pre>{@code
153175
* {
176+
* // required by MongoRx
177+
* use(new Rx());
178+
*
154179
* use(new MongoRx()
155180
* .observableAdapter(observable -> observable.observeOn(Scheduler.io())));
156181
*
@@ -175,6 +200,9 @@
175200
* <p>
176201
* <pre>{@code
177202
* {
203+
* // required by MongoRx
204+
* use(new Rx());
205+
*
178206
* use(new MongoRx("db1"));
179207
*
180208
* use(new MongoRx("db2"));
@@ -207,6 +235,9 @@
207235
*
208236
* <pre>{@code
209237
* {
238+
* // required by MongoRx
239+
* use(new Rx());
240+
*
210241
* use(new MongoRx().observableAdapter(o -> o.observeOn(Schedulers.io())));
211242
* }
212243
* }</pre>
@@ -389,7 +420,6 @@ public void configure(final Env env, final Config conf, final Binder binder) {
389420

390421
/** mapper */
391422
env.routes()
392-
.map(Rx.rx())
393423
.map(mapper());
394424

395425
log.info("Started {}", cstr);

jooby-mongodb-rx/src/test/java/org/jooby/mongodb/MongodbRxTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,8 @@ public class MongodbRxTest {
100100
.andReturn(unit.get(MongoClient.class));
101101
};
102102

103-
@SuppressWarnings({"rawtypes", "unchecked" })
104103
private Block env = unit -> {
105-
Route.Mapper rx = unit.mock(Route.Mapper.class);
106-
107-
unit.mockStatic(Rx.class);
108-
expect(Rx.rx()).andReturn(rx);
109-
110104
Routes routes = unit.mock(Routes.class);
111-
expect(routes.map(rx)).andReturn(routes);
112105
expect(routes.map(unit.capture(Route.Mapper.class))).andReturn(routes);
113106

114107
Env env = unit.get(Env.class);

jooby-rxjava-jdbc/src/main/java/org/jooby/rx/RxJdbc.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
import javax.inject.Provider;
2222
import javax.sql.DataSource;
2323

24-
import org.jooby.Deferred;
2524
import org.jooby.Env;
2625
import org.jooby.jdbc.Jdbc;
2726

2827
import com.github.davidmoten.rx.jdbc.Database;
2928
import com.google.inject.Binder;
3029
import com.typesafe.config.Config;
3130

32-
import rx.Observable;
33-
3431
/**
3532
* <h1>rxjdbc</h1>
3633
* <p>
@@ -39,8 +36,8 @@
3936
* </p>
4037
*
4138
* <p>
42-
* This module depends on {@link Jdbc} module, make sure you read the doc of the {@link Jdbc}
43-
* module.
39+
* This module depends on {@link Jdbc} and {@link Rx} modules, make sure you read the doc of the {@link Jdbc}
40+
* and {@link Rx} modules before using {@link RxJdbc}.
4441
* </p>
4542
*
4643
* <h2>exports</h2>
@@ -49,6 +46,11 @@
4946
* <li>A Hikari {@link DataSource} object</li>
5047
* </ul>
5148
*
49+
* <h2>depends on</h2>
50+
* <ul>
51+
* <li>{@link Rx rx module}</li>
52+
* </ul>
53+
*
5254
* <h2>usage</h2>
5355
*
5456
* <pre>{@code
@@ -57,22 +59,20 @@
5759
* import org.jooby.rx.Rx;
5860
*
5961
* {
62+
* // required by RxJdbc
63+
* use(new Rx());
64+
*
6065
* use(new RxJdbc());
6166
*
6267
* get("/reactive", req ->
6368
* req.require(Database.class)
6469
* .select("select name from something where id = :id")
6570
* .parameter("id", 1)
6671
* .getAs(String.class)
67-
* ).map(Rx.rx());
72+
* );
6873
* }
6974
* }</pre>
7075
*
71-
* <p>
72-
* The {@link Rx#rx()} mapper converts {@link Observable rx observables} to {@link Deferred}
73-
* instances. More at {@link Rx}.
74-
* </p>
75-
*
7676
* <h2>multiple db connections</h2>
7777
*
7878
* <pre>{@code
@@ -81,6 +81,9 @@
8181
* import org.jooby.rx.Rx;
8282
*
8383
* {
84+
* // required by RxJdbc
85+
* use(new Rx());
86+
*
8487
* use(new RxJdbc("db.main"));
8588
* use(new RxJdbc("db.audit"));
8689
*

0 commit comments

Comments
 (0)