-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rxjava-jdbc module fix #351 + add website doc for rxjava + some minor…
… doc updates
- Loading branch information
Showing
20 changed files
with
1,040 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
73 changes: 73 additions & 0 deletions
73
coverage-report/src/test/java/org/jooby/issues/Issue351.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.jooby.issues; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.jooby.rx.Rx; | ||
import org.jooby.rx.RxJdbc; | ||
import org.jooby.test.ServerFeature; | ||
import org.junit.Test; | ||
|
||
import com.github.davidmoten.rx.jdbc.Database; | ||
import com.typesafe.config.ConfigFactory; | ||
import com.typesafe.config.ConfigValueFactory; | ||
|
||
public class Issue351 extends ServerFeature { | ||
|
||
{ | ||
use(ConfigFactory.empty() | ||
.withValue("db", ConfigValueFactory.fromAnyRef("mem"))); | ||
|
||
use(new RxJdbc()); | ||
|
||
onStart(r -> { | ||
Database db = r.require(Database.class); | ||
db.update("create table something (id int primary key, name varchar(100))") | ||
.execute(); | ||
|
||
db.update("insert into something (id, name) values (?, ?)") | ||
.parameters(1, "jooby") | ||
.execute(); | ||
}); | ||
|
||
get("/351/reactive", req -> | ||
req.require(Database.class) | ||
.select("select name from something where id = :id") | ||
.parameter("id", 1) | ||
.getAs(String.class) | ||
).map(Rx.rx()); | ||
|
||
get("/351/blocking", req -> { | ||
return req.require(Database.class) | ||
.select("select name from something where id = :id") | ||
.parameter("id", 1) | ||
.getAs(String.class) | ||
.toBlocking() | ||
.single(); | ||
}); | ||
|
||
get("/db", req -> { | ||
assertEquals(req.require(Database.class), req.require(Database.class)); | ||
return "OK"; | ||
}); | ||
|
||
} | ||
|
||
@Test | ||
public void rxjdbc() throws Exception { | ||
request().get("/351/reactive") | ||
.expect("jooby"); | ||
} | ||
|
||
@Test | ||
public void rxjdbcBlocking() throws Exception { | ||
request().get("/351/blocking") | ||
.expect("jooby"); | ||
} | ||
|
||
@Test | ||
public void singletondb() throws Exception { | ||
request().get("/db") | ||
.expect("OK"); | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# banner | ||
|
||
Prints out an ASCII art banner on startup using <a href="https://github.com/lalyos/jfiglet">jfiglet</a>. | ||
|
||
## dependency | ||
|
||
```xml | ||
<dependency> | ||
<groupId>org.jooby</groupId> | ||
<artifactId>jooby-banner</artifactId> | ||
<version>1.0.0.CR2</version> | ||
</dependency> | ||
``` | ||
|
||
## usage | ||
|
||
```java | ||
package com.myapp; | ||
{ | ||
use(new Banner()); | ||
|
||
} | ||
``` | ||
|
||
Prints out the value of ```application.name``` which here is ```myapp```. Or you can specify the text to prints out: | ||
|
||
```java | ||
package com.myapp; | ||
{ | ||
use(new Banner("my awesome app")); | ||
|
||
} | ||
``` | ||
|
||
## font | ||
|
||
You can pick and use the font of your choice via {@link #font(String)} option: | ||
|
||
```java | ||
package com.myapp; | ||
{ | ||
use(new Banner("my awesome app").font("slant")); | ||
|
||
} | ||
``` | ||
|
||
Fonts are distributed within the library inside the ```/flf``` classpath folder. A full list of fonts is available <a href="http://patorjk.com/software/taag">here</a>. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# rxjdbc | ||
|
||
<a href="https://github.com/davidmoten/rxjava-jdbc">rxjava-jdbc</a> efficient execution, concise code, and functional composition of database calls using JDBC and RxJava Observable. | ||
|
||
This module depends on [jdbc module](/doc/jdbc), make sure you read the doc of the [jdbc module](/doc/jdbc) module. | ||
|
||
## dependency | ||
|
||
```xml | ||
<dependency> | ||
<groupId>org.jooby</groupId> | ||
<artifactId>jooby-rxjdbc</artifactId> | ||
<version>1.0.0.CR2</version> | ||
</dependency> | ||
``` | ||
|
||
## exports | ||
|
||
* A ```Database``` object | ||
* A [Hikari](https://github.com/brettwooldridge/HikariCP) ```DataSource``` object | ||
|
||
## usage | ||
|
||
```java | ||
import org.jooby.rx.RxJdbc; | ||
import org.jooby.rx.Rx; | ||
{ | ||
use(new RxJdbc()); | ||
|
||
get("/reactive", req -> | ||
req.require(Database.class) | ||
.select("select name from something where id = :id") | ||
.parameter("id", 1) | ||
.getAs(String.class) | ||
).map(Rx.rx()); | ||
|
||
} | ||
``` | ||
|
||
The [Rx.rx()](/apidocs/org/jooby/rx/Rx.html#rx--) mapper converts ```Observable``` to [deferred](/apidocs/org/jooby/Deferred.html) instances. More at [rx module](/doc/rxjava). | ||
|
||
## multiple db connections | ||
|
||
```java | ||
import org.jooby.rx.RxJdbc; | ||
import org.jooby.rx.Rx; | ||
{ | ||
use(new RxJdbc("db.main")); | ||
|
||
use(new RxJdbc("db.audit")); | ||
|
||
get("/", req -> | ||
|
||
Databse db = req.require("db.main", Database.class); | ||
Databse audit = req.require("db.audit", Database.class); | ||
// ... | ||
).map(Rx.rx()); | ||
|
||
} | ||
``` | ||
|
||
For more details on how to configure the Hikari datasource, please check the [jdbc module](/doc/jdbc). | ||
|
||
Happy coding!!! |
Oops, something went wrong.