-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
111 additions
and
84 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
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package io.vertx.example.rxjava3.database.mongo; | ||
|
||
import io.reactivex.rxjava3.core.Completable; | ||
import io.reactivex.rxjava3.core.Flowable; | ||
import io.reactivex.rxjava3.core.Maybe; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.launcher.application.VertxApplication; | ||
import io.vertx.rxjava3.core.AbstractVerticle; | ||
import io.vertx.rxjava3.ext.mongo.MongoClient; | ||
|
||
import java.util.List; | ||
|
||
/* | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
*/ | ||
|
@@ -18,7 +22,7 @@ public static void main(String[] args) { | |
} | ||
|
||
@Override | ||
public void start() throws Exception { | ||
public Completable rxStart() { | ||
|
||
JsonObject config = new JsonObject() | ||
.put("connection_string", "mongodb://localhost:27018") | ||
|
@@ -27,17 +31,17 @@ public void start() throws Exception { | |
// Create the client | ||
mongo = MongoClient.createShared(vertx, config); | ||
|
||
insertAndFind(); | ||
return insertAndFind(); | ||
} | ||
|
||
private void insertAndFind() { | ||
private Completable insertAndFind() { | ||
// Documents to insert | ||
Flowable<JsonObject> documents = Flowable.just( | ||
new JsonObject().put("username", "temporalfox").put("firstname", "Julien").put("password", "bilto"), | ||
new JsonObject().put("username", "purplefox").put("firstname", "Tim").put("password", "wibble") | ||
); | ||
|
||
mongo | ||
Maybe<List<JsonObject>> maybe = mongo | ||
.rxCreateCollection("users") | ||
.andThen( | ||
// After collection is created we insert each document | ||
|
@@ -52,11 +56,9 @@ private void insertAndFind() { | |
System.out.println("Insertions done"); | ||
return mongo.rxFind("users", new JsonObject()); | ||
}) | ||
.subscribe(results -> { | ||
.doOnSuccess(results -> { | ||
System.out.println("Results " + results); | ||
}, error -> { | ||
System.out.println("Err"); | ||
error.printStackTrace(); | ||
}); | ||
return maybe.ignoreElement(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package io.vertx.example.rxjava3.database.sqlclient; | ||
|
||
import io.reactivex.rxjava3.core.Maybe; | ||
import io.reactivex.rxjava3.core.Completable; | ||
import io.vertx.jdbcclient.JDBCConnectOptions; | ||
import io.vertx.launcher.application.VertxApplication; | ||
import io.vertx.rxjava3.core.AbstractVerticle; | ||
|
@@ -9,7 +9,6 @@ | |
import io.vertx.sqlclient.PoolOptions; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Function; | ||
|
||
/* | ||
* @author <a href="mailto:[email protected]">Emad Alblueshi</a> | ||
|
@@ -21,7 +20,7 @@ public static void main(String[] args) { | |
} | ||
|
||
@Override | ||
public void start() throws Exception { | ||
public Completable rxStart() { | ||
|
||
String sql = "CREATE TABLE colors (" + | ||
"id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY, " + | ||
|
@@ -31,7 +30,8 @@ public void start() throws Exception { | |
Pool pool = JDBCPool.pool(vertx, new JDBCConnectOptions().setJdbcUrl("jdbc:hsqldb:mem:test?shutdown=true"), new PoolOptions()); | ||
|
||
// Connect to the database | ||
pool.rxWithTransaction((Function<SqlConnection, Maybe<RowSet<Row>>>) client -> client | ||
return pool | ||
.rxWithTransaction(client -> client | ||
// Create table | ||
.query(sql).rxExecute() | ||
// Insert colors | ||
|
@@ -41,11 +41,12 @@ public void start() throws Exception { | |
// Get colors if all succeeded | ||
.flatMap(r -> client.query("SELECT * FROM colors").rxExecute()) | ||
.toMaybe())// Subscribe to get the final result | ||
.subscribe(rowSet -> { | ||
.doOnSuccess(rowSet -> { | ||
System.out.println("Results:"); | ||
rowSet.forEach(row -> { | ||
System.out.println(row.toJson()); | ||
}); | ||
}, Throwable::printStackTrace); | ||
}) | ||
.ignoreElement(); | ||
} | ||
} |
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
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
Oops, something went wrong.