Search in sources :

Example 1 with MySQLConnectionImpl

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
}
Also used : Schema(org.apache.arrow.vector.types.pojo.Schema) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData) SneakyThrows(lombok.SneakyThrows) LoggerFactory(org.slf4j.LoggerFactory) JdbcFieldInfo(org.apache.arrow.adapter.jdbc.JdbcFieldInfo) ObservableOnSubscribe(io.reactivex.rxjava3.core.ObservableOnSubscribe) MySQLPool(io.vertx.mysqlclient.MySQLPool) RootAllocator(org.apache.arrow.memory.RootAllocator) Duration(java.time.Duration) LocalTime(java.time.LocalTime) DataType(io.vertx.mysqlclient.impl.datatype.DataType) BufferAllocator(org.apache.arrow.memory.BufferAllocator) ColumnDefPacket(io.mycat.beans.mysql.packet.ColumnDefPacket) FieldType(org.apache.arrow.vector.types.pojo.FieldType) SQLReplaceable(com.alibaba.druid.sql.ast.SQLReplaceable) Field(org.apache.arrow.vector.types.pojo.Field) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) ColumnDescriptor(io.vertx.sqlclient.desc.ColumnDescriptor) LocalDate(java.time.LocalDate) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) io.vertx.core(io.vertx.core) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) MySQLClient(io.vertx.mysqlclient.MySQLClient) MySQLConnectionImpl(io.vertx.mysqlclient.impl.MySQLConnectionImpl) NonNull(io.reactivex.rxjava3.annotations.NonNull) MySQLException(io.vertx.mysqlclient.MySQLException) Function(java.util.function.Function) JdbcToArrowConfigBuilder(org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder) SQLException(java.sql.SQLException) MySqlASTVisitorAdapter(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter) ImmutableList(com.google.common.collect.ImmutableList) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData) Observable(io.reactivex.rxjava3.core.Observable) RowBaseIterator(io.mycat.api.collector.RowBaseIterator) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) io.vertx.sqlclient(io.vertx.sqlclient) SQLUtils(com.alibaba.druid.sql.SQLUtils) Logger(org.slf4j.Logger) Numeric(io.vertx.sqlclient.data.Numeric) org.apache.arrow.vector(org.apache.arrow.vector) ObservableEmitter(io.reactivex.rxjava3.core.ObservableEmitter) MySQLFieldsType(io.mycat.beans.mysql.MySQLFieldsType) JdbcToArrowConfig(org.apache.arrow.adapter.jdbc.JdbcToArrowConfig) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) MySQLPool(io.vertx.mysqlclient.MySQLPool) CountDownLatch(java.util.concurrent.CountDownLatch) io.vertx.sqlclient(io.vertx.sqlclient) SneakyThrows(lombok.SneakyThrows)

Aggregations

SQLUtils (com.alibaba.druid.sql.SQLUtils)1 SQLReplaceable (com.alibaba.druid.sql.ast.SQLReplaceable)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1 MySqlASTVisitorAdapter (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter)1 ImmutableList (com.google.common.collect.ImmutableList)1 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 MycatMySQLRowMetaData (io.mycat.beans.mycat.MycatMySQLRowMetaData)1 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)1 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)1 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)1 MySQLFieldsType (io.mycat.beans.mysql.MySQLFieldsType)1 ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)1 ColumnDefPacketImpl (io.mycat.beans.mysql.packet.ColumnDefPacketImpl)1 NonNull (io.reactivex.rxjava3.annotations.NonNull)1 Observable (io.reactivex.rxjava3.core.Observable)1 ObservableEmitter (io.reactivex.rxjava3.core.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.rxjava3.core.ObservableOnSubscribe)1 io.vertx.core (io.vertx.core)1 Buffer (io.vertx.core.buffer.Buffer)1