@Override protected AsyncSqlService createService(Vertx vertx, JsonObject config) { return AsyncSqlService.createMySqlService(vertx, config); } }
@Override protected AsyncSqlService createService(Vertx vertx, JsonObject config) { return AsyncSqlService.createPostgreSqlService(vertx, config); } }
/** * Returns a connection that can be used to perform SQL operations on. It's important to remember to close the * connection when you are done, so it is returned to the pool. * @param handler the handler which is called when the <code>JdbcConnection</code> object is ready for use. */ public void getConnection(Handler<AsyncResult<SqlConnection>> handler) { this.delegate.getConnection(new Handler<AsyncResult<io.vertx.ext.sql.SqlConnection>>() { public void handle(AsyncResult<io.vertx.ext.sql.SqlConnection> event) { AsyncResult<SqlConnection> f; if (event.succeeded()) { f = InternalHelper.<SqlConnection>result(new SqlConnection(event.result())); } else { f = InternalHelper.<SqlConnection>failure(event.cause()); } handler.handle(f); } }); }
service.start(createHandler(msg)); break; service.stop(createHandler(msg)); break; service.getConnection(res -> { if (res.failed()) { msg.fail(-1, res.cause().getMessage());
/** * Called to start the service * @param whenDone */ public void start(Handler<AsyncResult<Void>> whenDone) { this.delegate.start(whenDone); }
/** * Called to stop the service * @param whenDone */ public void stop(Handler<AsyncResult<Void>> whenDone) { this.delegate.stop(whenDone); }
/** * Create an event bus proxy to a service which lives somewhere on the network and is listening on the specified * event bus address * @param vertx the Vert.x instance * @param address the address on the event bus where the service is listening * @return */ public static AsyncSqlService createEventBusProxy(Vertx vertx, String address) { AsyncSqlService ret= AsyncSqlService.newInstance(io.vertx.ext.asyncsql.AsyncSqlService.createEventBusProxy((io.vertx.core.Vertx) vertx.getDelegate(), address)); return ret; }
@Override public void start(Future<Void> startFuture) throws Exception { final JsonObject conf = config(); final CountDownLatch cdl = new CountDownLatch(1); final Handler<AsyncResult<Void>> simpleEndHandler = res -> { cdl.countDown(); if (res.failed()) { startFuture.fail(res.cause()); } else { if (cdl.getCount() == 0 && !startFuture.isComplete()) { startFuture.complete(); } } }; // Create the service object final String address = conf.getString("address"); if (address == null) { throw new IllegalStateException("address field must be specified in config for service verticle"); } service = createService(vertx, conf); ProxyHelper.registerService(AsyncSqlService.class, vertx, service, address); service.start(simpleEndHandler); }
@Override public void stop(Future<Void> stopFuture) throws Exception { if (service != null) { service.stop(res -> { if (res.failed()) { stopFuture.fail(res.cause()); } else { stopFuture.complete(); } }); } }
/** * Create a PostgreSQL service * @param vertx the Vert.x instance * @param config the config * @return the service */ public static AsyncSqlService createPostgreSqlService(Vertx vertx, JsonObject config) { AsyncSqlService ret= AsyncSqlService.newInstance(io.vertx.ext.asyncsql.AsyncSqlService.createPostgreSqlService((io.vertx.core.Vertx) vertx.getDelegate(), config)); return ret; }
/** * Create a MySQL service * @param vertx the Vert.x instance * @param config the config * @return the service */ public static AsyncSqlService createMySqlService(Vertx vertx, JsonObject config) { AsyncSqlService ret= AsyncSqlService.newInstance(io.vertx.ext.asyncsql.AsyncSqlService.createMySqlService((io.vertx.core.Vertx) vertx.getDelegate(), config)); return ret; }