Search in sources :

Example 1 with MySQLPool

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));
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) MySQLPool(io.vertx.mysqlclient.MySQLPool) PoolOptions(io.vertx.sqlclient.PoolOptions) AbstractVerticle(io.vertx.core.AbstractVerticle)

Example 2 with MySQLPool

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);
}
Also used : MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) PoolOptions(io.vertx.sqlclient.PoolOptions) MySQLPool(io.vertx.mysqlclient.MySQLPool) Test(org.junit.Test) MycatTest(io.mycat.assemble.MycatTest)

Example 3 with MySQLPool

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
}
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)

Example 4 with MySQLPool

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"}
    });
}
Also used : Jooqx(io.zero88.jooqx.Jooqx) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) MySQLPool(io.vertx.mysqlclient.MySQLPool) PoolOptions(io.vertx.sqlclient.PoolOptions) DSLContext(org.jooq.DSLContext) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord)

Example 5 with MySQLPool

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);
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) MySQLConnectionImpl(io.vertx.mysqlclient.impl.MySQLConnectionImpl) Driver(io.vertx.sqlclient.spi.Driver) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) MySQLConnectionFactory(io.vertx.mysqlclient.impl.MySQLConnectionFactory) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) MySQLPool(io.vertx.mysqlclient.MySQLPool) CloseFuture(io.vertx.core.impl.CloseFuture) MySQLConnectionUriParser(io.vertx.mysqlclient.impl.MySQLConnectionUriParser) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxInternal(io.vertx.core.impl.VertxInternal) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Aggregations

MySQLPool (io.vertx.mysqlclient.MySQLPool)7 MySQLConnectOptions (io.vertx.mysqlclient.MySQLConnectOptions)4 PoolOptions (io.vertx.sqlclient.PoolOptions)4 MySQLConnectionImpl (io.vertx.mysqlclient.impl.MySQLConnectionImpl)2 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 MycatTest (io.mycat.assemble.MycatTest)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 ArcContainer (io.quarkus.arc.ArcContainer)1