本文整理汇总了Java中io.vertx.rxjava.ext.jdbc.JDBCClient类的典型用法代码示例。如果您正苦于以下问题:Java JDBCClient类的具体用法?Java JDBCClient怎么用?Java JDBCClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JDBCClient类属于io.vertx.rxjava.ext.jdbc包,在下文中一共展示了JDBCClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
/**
* Starts the verticle asynchronously. The the initialization is completed, it calls
* `complete()` on the given {@link Future} object. If something wrong happens,
* `fail` is called.
*
* @param future the future to indicate the completion
*/
@Override
public void start(Future<Void> future) {
super.start();
// creates the jdbc client.
jdbc = JDBCClient.createNonShared(vertx, config());
// TODO
// ----
Single<MessageConsumer<JsonObject>> readySingle = Single.error(new UnsupportedOperationException("not yet implemented"));
// ----
readySingle.doOnSuccess(consumer -> {
// on success we set the handler that will store message in the database
consumer.handler(message -> storeInDatabase(message.body()));
}).subscribe(consumer -> {
// complete the verticle start with a success
future.complete();
}, error -> {
// signal a verticle start failure
future.fail(error);
});
}
示例2: WikiDatabaseServiceImpl
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
WikiDatabaseServiceImpl(io.vertx.ext.jdbc.JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
this.dbClient = new JDBCClient(dbClient);
this.sqlQueries = sqlQueries;
getConnection()
.flatMap(conn -> conn.rxExecute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE)))
.map(v -> this)
.subscribe(RxHelper.toSubscriber(readyHandler));
}
示例3: initDatabase
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
public static Completable initDatabase(Vertx vertx, JDBCClient jdbc) {
return jdbc.rxGetConnection()
.flatMapCompletable(connection ->
vertx.fileSystem().rxReadFile("ddl.sql")
.flatMapObservable(buffer -> Observable.from(buffer.toString().split(";")))
.flatMapSingle(connection::rxExecute)
.doAfterTerminate(connection::close)
.toCompletable()
);
}
示例4: start
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Override
public void start() {
// Create a router object.
Router router = Router.router(vertx);
// enable parsing of request bodies
router.route().handler(BodyHandler.create());
// perform validation of the :id parameter
router.route("/api/fruits/:id")
.handler(this::validateId);
// implement a basic REST CRUD mapping
router.get("/api/fruits").handler(this::retrieveAll);
router.post("/api/fruits").handler(this::addOne);
router.get("/api/fruits/:id").handler(this::getOne);
router.put("/api/fruits/:id").handler(this::updateOne);
router.delete("/api/fruits/:id").handler(this::deleteOne);
// health check
router.get("/health").handler(rc -> rc.response().end("OK"));
// web interface
router.get().handler(StaticHandler.create());
// Create a JDBC client
JDBCClient jdbc = JDBCClient.createShared(vertx, new JsonObject()
.put("url", "jdbc:postgresql://" + getEnv("MY_DATABASE_SERVICE_HOST", "localhost") + ":5432/my_data")
.put("driver_class", "org.postgresql.Driver")
.put("user", getEnv("DB_USERNAME", "user"))
.put("password", getEnv("DB_PASSWORD", "password"))
);
DBInitHelper.initDatabase(vertx, jdbc)
.andThen(initHttpServer(router, jdbc))
.subscribe(
(http) -> System.out.println("Server ready on port " + http.actualPort()),
Throwable::printStackTrace
);
}
示例5: initHttpServer
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
private Single<HttpServer> initHttpServer(Router router, JDBCClient client) {
store = new JdbcProductStore(client);
// Create the HTTP server and pass the "accept" method to the request handler.
return vertx
.createHttpServer()
.requestHandler(router::accept)
.rxListen(8080);
}
示例6: CartEventDataSourceImpl
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
public CartEventDataSourceImpl(io.vertx.core.Vertx vertx, JsonObject json) {
this.client = JDBCClient.createNonShared(Vertx.newInstance(vertx), json);
// TODO: Should not init the table here.
client.rxGetConnection()
.flatMap(connection ->
connection.rxExecute(INIT_STATEMENT)
.doAfterTerminate(connection::close)
)
.subscribe();
}
示例7: start
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
/**
* Starts the verticle asynchronously. The the initialization is completed, it calls
* `complete()` on the given {@link Future} object. If something wrong happens,
* `fail` is called.
*
* @param future the future to indicate the completion
*/
@Override
public void start(Future<Void> future) {
super.start();
// creates the jdbc client.
jdbc = JDBCClient.createNonShared(vertx, config());
// ----
Single<Void> databaseReady = initializeDatabase(config().getBoolean("drop", false));
Single<Void> httpEndpointReady = configureTheHTTPServer()
.flatMap(server -> rxPublishHttpEndpoint("audit", "localhost", server.actualPort()));
Single<MessageConsumer<JsonObject>> messageConsumerReady = retrieveThePortfolioMessageSource();
Single<MessageConsumer<JsonObject>> readySingle = Single.zip(
databaseReady,
httpEndpointReady,
messageConsumerReady,
(db, http, consumer) -> consumer);
// ----
readySingle.doOnSuccess(consumer -> {
// on success we set the handler that will store message in the database
consumer.handler(message -> storeInDatabase(message.body()));
}).subscribe(consumer -> {
// complete the verticle start with a success
future.complete();
}, error -> {
// signal a verticle start failure
future.fail(error);
});
}
示例8: createDbClient
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
protected SQLClient createDbClient(JsonObject config) {
return JDBCClient.createNonShared(vertx, new JsonObject()
.put("url", config.getString("db_url", "jdbc:hsqldb:file:db/wiki"))
.put("driver_class", config.getString("db_driver", "org.hsqldb.jdbcDriver"))
.put("max_pool_size", config.getInteger("db_max_pool_size", 30)));
}
示例9: DatabaseServiceImpl
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
protected DatabaseServiceImpl(Vertx vertx, JsonObject config) {
if (config.containsKey("mysql")) {
this.client = JDBCClient.createShared(vertx, config.getJsonObject("mysql"));
}
}
示例10: LocalDatabase
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
private LocalDatabase(Vertx vertx, JsonObject config) {
database = createDatabase(config);
this.client = JDBCClient.createShared(vertx, config);
}
示例11: BaseDbRxWrapper
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
public BaseDbRxWrapper(Vertx vertx, JsonObject config) {
this.client = JDBCClient
.createNonShared(new io.vertx.rxjava.core.Vertx(vertx), config.getJsonObject("jdbc", config));
// TODO: 23.08.2017 get keys from (global?) .properties
}
示例12: JdbcProductStore
import io.vertx.rxjava.ext.jdbc.JDBCClient; //导入依赖的package包/类
public JdbcProductStore(JDBCClient db) {
this.db = db;
}