use of io.vertx.rxjava.ext.jdbc.JDBCClient in project vertx-examples by vert-x3.
the class Streaming method start.
@Override
public void start() throws Exception {
JsonObject config = new JsonObject().put("url", "jdbc:hsqldb:mem:test?shutdown=true").put("driver_class", "org.hsqldb.jdbcDriver");
JDBCClient jdbc = JDBCClient.createShared(vertx, config);
jdbc.rxGetConnection().flatMapObservable(conn -> {
// With the connection...
return // ...create test table
conn.rxUpdate("CREATE TABLE test(col VARCHAR(20))").flatMap(// ...insert a row
result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val1')")).flatMap(// ...another one
result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val2')")).flatMap(// ...get values stream
result -> conn.rxQueryStream("SELECT * FROM test")).flatMapObservable(sqlRowStream -> {
return // Transform the stream into an Observable...
sqlRowStream.toObservable().doOnTerminate(// ...and close the connection when the stream is fully read or an error occurs
conn::close);
});
}).subscribe(row -> System.out.println("Row : " + row.encode()));
}
use of io.vertx.rxjava.ext.jdbc.JDBCClient in project vertx-openshift-it by cescoffier.
the class OracleVerticle method start.
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.route("/api/vegetables/:id").handler(this::validateId);
router.get("/api/vegetables").handler(this::getAll);
router.post("/api/vegetables").handler(this::addOne);
router.get("/api/vegetables/:id").handler(this::getOne);
router.put("/api/vegetables/:id").handler(this::updateOne);
router.delete("/api/vegetables/:id").handler(this::deleteOne);
router.get("/healthcheck").handler(rc -> rc.response().end("OK"));
JsonObject config = TestUtils.allocateDatabase("oracle", true);
JDBCClient jdbcClient = JDBCClient.createShared(vertx, config);
vegetableTableExists(jdbcClient).subscribe(VegetableTableExists -> {
Completable firstAction = initDatabase(vertx, jdbcClient);
if (VegetableTableExists) {
firstAction = dropVegetableTable(jdbcClient).andThen(initDatabase(vertx, jdbcClient));
}
firstAction.andThen(initHttpServer(router, jdbcClient)).subscribe((http) -> System.out.println("Server ready on port " + http.actualPort()), Throwable::printStackTrace);
});
}
Aggregations