Java Code Examples for io.vertx.ext.jdbc.JDBCClient#createNonShared()

The following examples show how to use io.vertx.ext.jdbc.JDBCClient#createNonShared() . 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
Source File: AuditVerticleTest.java    From microtrader with MIT License 6 votes vote down vote up
@Test
public void testStockTradesPersisted(TestContext context) throws ClassNotFoundException {
    Async async = context.async();
    JsonObject jdbcConfig = new JsonObject(config.getObject("jdbc").render(ConfigRenderOptions.concise()));
    JDBCClient jdbc = JDBCClient.createNonShared(vertx, jdbcConfig);
    Class.forName(jdbcConfig.getString("driverclass"));

    jdbc.getConnection(ar -> {
        SQLConnection connection = ar.result();
        if (ar.failed()) {
            context.fail(ar.cause());
        } else {
            connection.query(SELECT_STATEMENT, result -> {
                ResultSet set = result.result();
                List<JsonObject> operations = set.getRows().stream()
                        .map(json -> new JsonObject(json.getString("OPERATION")))
                        .collect(Collectors.toList());
                context.assertTrue(operations.size() >= 3);
                connection.close();
                async.complete();
            });
        }
    });
}
 
Example 2
Source File: MysqlSideFunction.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private SQLClient createClient(MysqlSideProperties mysqlProperties, Vertx vertx) {
    JsonObject mysqlClientConfig = new JsonObject();
    mysqlClientConfig.put("url", mysqlProperties.getUrl()).put("driver_class", MYSQL_DRIVER)
        .put("max_pool_size",
            mysqlProperties.getMaxPoolSize() == null ? DEFAULT_MAX_DB_CONN_POOL_SIZE
                : mysqlProperties.getMaxPoolSize())
        .put("user", mysqlProperties.getUsername()).put("password", mysqlProperties.getPassword());

    return JDBCClient.createNonShared(vertx, mysqlClientConfig);
}
 
Example 3
Source File: AuditVerticle.java    From microtrader with MIT License 5 votes vote down vote up
/**
 * 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) throws ClassNotFoundException {
    super.start();

    // Get configuration
    config = ConfigFactory.load();

    // creates the jdbc client.
    JsonObject jdbcConfig = new JsonObject(config.getObject("jdbc").render(ConfigRenderOptions.concise()));
    jdbc = JDBCClient.createNonShared(vertx, jdbcConfig);
    Class.forName(jdbcConfig.getString("driverclass"));

    // Start HTTP server and listen for portfolio events
    EventBus eventBus = vertx.eventBus();
    Future<HttpServer> httpEndpointReady = configureTheHTTPServer();
    httpEndpointReady.setHandler(ar -> {
       if (ar.succeeded()) {
           MessageConsumer<JsonObject> portfolioConsumer = eventBus.consumer(config.getString("portfolio.address"));
           portfolioConsumer.handler(message -> {
               storeInDatabase(message.body());
           });
           future.complete();
       } else {
           future.fail(ar.cause());
       }
    });

    publishHttpEndpoint("audit", config.getString("http.host"), config.getInt("http.public.port"), config.getString("http.root"), ar -> {
        if (ar.failed()) {
            ar.cause().printStackTrace();
        } else {
            System.out.println("Audit (Rest endpoint) service published : " + ar.succeeded());
        }
    });
}
 
Example 4
Source File: PaymentQueryServiceImpl.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
public PaymentQueryServiceImpl(Vertx vertx, JsonObject config) {
  this.jdbc = JDBCClient.createNonShared(vertx, config);
}
 
Example 5
Source File: JdbcRepositoryWrapper.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
public JdbcRepositoryWrapper(Vertx vertx, JsonObject config) {
  this.client = JDBCClient.createNonShared(vertx, config);
}
 
Example 6
Source File: VertxJdbcClientImpl.java    From apiman with Apache License 2.0 4 votes vote down vote up
public VertxJdbcClientImpl(Vertx vertx, JdbcOptionsBean config) {
    jdbcClient = JDBCClient.createNonShared(vertx, parseConfig(config));
}