use of io.vertx.mysqlclient.MySQLPool in project vertx-sql-client by eclipse-vertx.
the class SqlClientExamples method poolSharing1.
public void poolSharing1(Vertx vertx, MySQLConnectOptions database, int maxSize) {
MySQLPool pool = MySQLPool.pool(database, new PoolOptions().setMaxSize(maxSize));
vertx.deployVerticle(() -> new AbstractVerticle() {
@Override
public void start() throws Exception {
// Use the pool
}
}, new DeploymentOptions().setInstances(4));
}
use of io.vertx.mysqlclient.MySQLPool in project Mycat2 by MyCATApache.
the class ClientTest method tesVertx.
@Test
public void tesVertx() throws Exception {
MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(8066).setHost("localhost").setDatabase("mysql").setUser("root").setPassword("123456");
// Pool options
PoolOptions poolOptions = new PoolOptions().setMaxSize(1);
// Create the client pool
MySQLPool client = MySQLPool.pool(connectOptions, poolOptions);
// A simple query
client.query("SELECT 1").execute().toCompletionStage().toCompletableFuture().get(10, TimeUnit.SECONDS);
client.close().toCompletionStage().toCompletableFuture().get(1, TimeUnit.SECONDS);
}
use of io.vertx.mysqlclient.MySQLPool in project Mycat2 by MyCATApache.
the class NewVertxConnectionImpl method main.
@SneakyThrows
public static void main(String[] args) {
MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("localhost").setDatabase("mysql").setUser("root").setPassword("123456");
PoolOptions poolOptions = new PoolOptions().setMaxSize(1);
MySQLPool client = MySQLPool.pool(connectOptions, poolOptions);
Future<SqlConnection> connectionFuture = client.getConnection();
PreparedStatement preparedStatement1 = connectionFuture.flatMap(connection -> connection.prepare("SELECT 1")).toCompletionStage().toCompletableFuture().get();
Cursor cursor = preparedStatement1.cursor();
io.vertx.sqlclient.RowSet<Row> rows = cursor.read(8192).toCompletionStage().toCompletableFuture().get();
CountDownLatch countDownLatch = new CountDownLatch(1);
cursor.close().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> voidAsyncResult) {
countDownLatch.countDown();
}
});
countDownLatch.await();
System.out.println();
// MySQLConnectOptions connectOptions = new MySQLConnectOptions()
// .setPort(3306)
// .setHost("0.0.0.0")
// .setDatabase("mysql")
// .setUser("root")
// .setPassword("123456");
//
// // Pool options
// PoolOptions poolOptions = new PoolOptions()
// .setMaxSize(5);
//
// for (int j = 0; j < 10; j++) {
// // Create the client pool
// MySQLPool client = (MySQLPoolImpl) MySQLPool.pool(connectOptions, poolOptions);
// Future<MySQLConnectionImpl> connectionFuture = (Future) client.getConnection();
// connectionFuture.onSuccess(new Handler<MySQLConnectionImpl>() {
// @Override
// public void handle(MySQLConnectionImpl mySQLConnection) {
//
// }
// });
// List<Future> futures = new ArrayList<>();
// for (int i = 0; i < 1; i++) {
// Future<io.vertx.sqlclient.RowSet<Row>> rowSetFuture = client
// .query("SELECT 1")
// .execute().onComplete(rowSetAsyncResult -> client.close());
// futures.add(rowSetFuture);
// }
// System.out.println("aaaaaaaaaaaaaaaaaaa");
// CompositeFuture.join(futures).toCompletionStage().toCompletableFuture().get();
// System.out.println("bbbbbbb");
// client.close().toCompletionStage().toCompletableFuture().get();
// System.out.println("cccccccccccccccccc");
// A simple query
}
use of io.vertx.mysqlclient.MySQLPool in project jooqx by zero88.
the class JooqxFeature method jsonRecord.
/**
* Vertx JsonObject vs jOOQ Record... Ya, merging: JsonRecord
*/
@Override
public void jsonRecord(Vertx vertx) {
MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
MySQLPool mySQLPool = MySQLPool.pool(vertx, connectOptions, new PoolOptions().setMaxSize(5));
// jOOQ DSL
DSLContext dsl = DSL.using(SQLDialect.MYSQL);
// Build jOOQ query
SelectForUpdateStep<AuthorsRecord> q = dsl.selectFrom(Tables.AUTHORS).where(Tables.AUTHORS.NAME.eq("zero88")).limit(1).offset(1);
// Build jOOQx
Jooqx jooqx = Jooqx.builder().setVertx(vertx).setDSL(dsl).setSqlClient(mySQLPool).build();
jooqx.execute(q, DSLAdapter.fetchJsonRecord(q.asTable()), ar -> {
System.out.println(ar.result().toJson());
// output: {"id":88,"name":"zero88","country":"VN"}
});
}
use of io.vertx.mysqlclient.MySQLPool in project vertx-sql-client by eclipse-vertx.
the class MySQLDriver method newPool.
@Override
public MySQLPool newPool(Vertx vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
VertxInternal vx = (VertxInternal) vertx;
PoolImpl pool;
if (options.isShared()) {
pool = vx.createSharedClient(SHARED_CLIENT_KEY, options.getName(), closeFuture, cf -> newPoolImpl(vx, databases, options, cf));
} else {
pool = newPoolImpl(vx, databases, options, closeFuture);
}
return new MySQLPoolImpl(vx, closeFuture, pool);
}
Aggregations