use of io.vertx.mysqlclient.impl.MySQLConnectionImpl 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
}
Aggregations