Java Code Examples for io.vertx.rxjava.ext.jdbc.JDBCClient

The following examples show how to use io.vertx.rxjava.ext.jdbc.JDBCClient. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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);
  });
}
 
Example 2
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();
}
 
Example 3
/**
 * 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);
  });
}
 
Example 4
Source Project: vertx-rx   Source File: SQLTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  client = new JDBCClient(io.vertx.ext.jdbc.JDBCClient.create(vertx, config));
  client.rxGetConnection().flatMapCompletable(conn -> {
    Completable setup = conn.rxExecute("drop table folks if exists").toCompletable()
      .andThen(conn.rxExecute("create table folks (firstname varchar(255) not null)").toCompletable());
    for (String name : NAMES) {
      setup = setup.andThen(conn.rxExecute(String.format(INSERT_FOLK_SQL, name)).toCompletable());
    }
    return setup.doAfterTerminate(conn::close);
  }).await();
}
 
Example 5
Source Project: vertx-rx   Source File: UsingConnectionSafetyTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  client = new JDBCClient(io.vertx.ext.jdbc.JDBCClient.create(vertx, config));
}