io.vertx.mysqlclient.MySQLPool Java Examples

The following examples show how to use io.vertx.mysqlclient.MySQLPool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MySQLTest.java    From vertx-auth with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
  // Create the client pool
  mysql = MySQLPool.pool(
    rule.vertx(),
    // default config
    new MySQLConnectOptions()
      .setPort(container.getMappedPort(3306))
      .setHost(container.getContainerIpAddress())
      .setDatabase("testschema")
      .setUser("mysql")
      .setPassword("password"),
    // default pool config
    new PoolOptions()
      .setMaxSize(5));
}
 
Example #2
Source File: MySQLPoolRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<MySQLPool> configureMySQLPool(RuntimeValue<Vertx> vertx,
        DataSourcesRuntimeConfig dataSourcesRuntimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactiveMySQLConfig dataSourceReactiveMySQLConfig,
        LegacyDataSourcesRuntimeConfig legacyDataSourcesRuntimeConfig,
        LegacyDataSourceReactiveMySQLConfig legacyDataSourceReactiveMySQLConfig,
        boolean isLegacy,
        ShutdownContext shutdown) {

    MySQLPool mysqlPool;
    if (!isLegacy) {
        mysqlPool = initialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
                dataSourceReactiveRuntimeConfig,
                dataSourceReactiveMySQLConfig);
    } else {
        mysqlPool = legacyInitialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
                legacyDataSourcesRuntimeConfig.defaultDataSource, legacyDataSourceReactiveMySQLConfig);
    }

    shutdown.addShutdownTask(mysqlPool::close);
    return new RuntimeValue<>(mysqlPool);
}
 
Example #3
Source File: MySQLPoolRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private MySQLPool legacyInitialize(Vertx vertx, DataSourceRuntimeConfig dataSourceRuntimeConfig,
        LegacyDataSourceRuntimeConfig legacyDataSourceRuntimeConfig,
        LegacyDataSourceReactiveMySQLConfig legacyDataSourceReactiveMySQLConfig) {
    PoolOptions poolOptions = legacyToPoolOptionsLegacy(legacyDataSourceRuntimeConfig);
    MySQLConnectOptions mysqlConnectOptions = legacyToMySQLConnectOptions(dataSourceRuntimeConfig,
            legacyDataSourceRuntimeConfig, legacyDataSourceReactiveMySQLConfig);
    return MySQLPool.pool(vertx, mysqlConnectOptions, poolOptions);
}
 
Example #4
Source File: VertxMySqlContainer.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
public SqlConnection createVertxConnection() {
	String url = getVertxUrl();
	CountDownLatch countDown = new CountDownLatch( 1 );
	AtomicReference<AsyncResult<SqlConnection>> result = new AtomicReference<>();
	MySQLPool.pool( url ).getConnection( ar -> {
		result.set( ar );
		countDown.countDown();
	});
	await(countDown);
	SqlConnection con = result.get().result();
	if (con != null)
		return con;
	else
		throw new ContainerLaunchException( "Failed to obtain a connection", result.get().cause() );
}
 
Example #5
Source File: MySQLPoolRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private MySQLPool initialize(Vertx vertx, DataSourceRuntimeConfig dataSourceRuntimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactiveMySQLConfig dataSourceReactiveMySQLConfig) {
    PoolOptions poolOptions = toPoolOptions(dataSourceRuntimeConfig, dataSourceReactiveRuntimeConfig,
            dataSourceReactiveMySQLConfig);
    MySQLConnectOptions mysqlConnectOptions = toMySQLConnectOptions(dataSourceRuntimeConfig,
            dataSourceReactiveRuntimeConfig, dataSourceReactiveMySQLConfig);
    if (dataSourceReactiveRuntimeConfig.threadLocal.isPresent() &&
            dataSourceReactiveRuntimeConfig.threadLocal.get()) {
        return new ThreadLocalMySQLPool(vertx, mysqlConnectOptions, poolOptions);
    }
    return MySQLPool.pool(vertx, mysqlConnectOptions, poolOptions);
}
 
Example #6
Source File: MySQLPoolProducer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Produces the RX MySQL Pool instance. The instance is created lazily.
 *
 * @return the RX MySQL pool instance
 * @deprecated The RX API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool()} instead.
 */
@Singleton
@Produces
@Deprecated
public io.vertx.reactivex.mysqlclient.MySQLPool rxMySQLPool() {
    LOGGER.warn(
            "`io.vertx.reactivex.mysqlclient.MySQLPool` is deprecated and will be removed in a future version - it is "
                    + "recommended to switch to `io.vertx.mutiny.mysqlclient.MySQLPool`");
    return io.vertx.reactivex.mysqlclient.MySQLPool.newInstance(mysqlPool);
}
 
Example #7
Source File: MySQLPoolProducer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Produces the Axle MySQL Pool instance. The instance is created lazily.
 *
 * @return the Axle MySQL pool instance
 * @deprecated The Axle API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool()} instead.
 */
@Singleton
@Produces
@Deprecated
public io.vertx.axle.mysqlclient.MySQLPool axleMySQLPool() {
    LOGGER.warn(
            "`io.vertx.axle.mysqlclient.MySQLPool` is deprecated and will be removed in a future version - it is "
                    + "recommended to switch to `io.vertx.mutiny.mysqlclient.MySQLPool`");
    return io.vertx.axle.mysqlclient.MySQLPool.newInstance(mysqlPool);
}
 
Example #8
Source File: MySQLPoolProducer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
/**
 * @return the <em>mutiny</em> MySQL Pool instance. The instance is created lazily.
 */
@Singleton
@Produces
public io.vertx.mutiny.mysqlclient.MySQLPool mutinyMySQLPool() {
    return io.vertx.mutiny.mysqlclient.MySQLPool.newInstance(mysqlPool);
}
 
Example #9
Source File: ReactiveMySQLClientProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
ServiceStartBuildItem build(BuildProducer<FeatureBuildItem> feature,
        BuildProducer<MySQLPoolBuildItem> mysqlPool,
        BuildProducer<VertxPoolBuildItem> vertxPool,
        MySQLPoolRecorder recorder,
        VertxBuildItem vertx,
        BuildProducer<SyntheticBeanBuildItem> syntheticBeans, ShutdownContextBuildItem shutdown,
        BuildProducer<ExtensionSslNativeSupportBuildItem> sslNativeSupport,
        DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, DataSourcesRuntimeConfig dataSourcesRuntimeConfig,
        DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactiveMySQLConfig dataSourceReactiveMySQLConfig,
        LegacyDataSourcesRuntimeConfig legacyDataSourcesRuntimeConfig,
        LegacyDataSourceReactiveMySQLConfig legacyDataSourceReactiveMySQLConfig) {

    feature.produce(new FeatureBuildItem(Feature.REACTIVE_MYSQL_CLIENT));
    // Make sure the MySQLPoolProducer is initialized before the StartupEvent is fired
    ServiceStartBuildItem serviceStart = new ServiceStartBuildItem("reactive-mysql-client");

    // Note: we had to tweak that logic to support the legacy configuration
    if (dataSourcesBuildTimeConfig.defaultDataSource.dbKind.isPresent()
            && ((!DatabaseKind.isMySQL(dataSourcesBuildTimeConfig.defaultDataSource.dbKind.get())
                    && !DatabaseKind.isMariaDB(dataSourcesBuildTimeConfig.defaultDataSource.dbKind.get()))
                    || !dataSourceReactiveBuildTimeConfig.enabled)) {
        return serviceStart;
    }

    boolean isLegacy = !dataSourcesBuildTimeConfig.defaultDataSource.dbKind.isPresent();

    RuntimeValue<MySQLPool> mySqlPool = recorder.configureMySQLPool(vertx.getVertx(),
            dataSourcesRuntimeConfig, dataSourceReactiveRuntimeConfig, dataSourceReactiveMySQLConfig,
            legacyDataSourcesRuntimeConfig, legacyDataSourceReactiveMySQLConfig, isLegacy,
            shutdown);
    mysqlPool.produce(new MySQLPoolBuildItem(mySqlPool));

    // Synthetic bean for MySQLPool
    syntheticBeans.produce(SyntheticBeanBuildItem.configure(MySQLPool.class).addType(Pool.class).scope(Singleton.class)
            .runtimeValue(mySqlPool)
            .setRuntimeInit().done());

    boolean isDefault = true; // assume always the default pool for now
    vertxPool.produce(new VertxPoolBuildItem(mySqlPool, DatabaseKind.MYSQL, isDefault));

    // Enable SSL support by default
    sslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(Feature.REACTIVE_MYSQL_CLIENT));

    return serviceStart;
}
 
Example #10
Source File: MySQLPoolBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<MySQLPool> getMySQLPool() {
    return mysqlPool;
}
 
Example #11
Source File: ThreadLocalMySQLPool.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected MySQLPool createThreadLocalPool() {
    return MySQLPool.pool(vertx, mySQLConnectOptions, poolOptions);
}
 
Example #12
Source File: ReactiveMySQLDataSourceHealthCheck.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@PostConstruct
protected void init() {
    mySQLPool = Arc.container().instance(MySQLPool.class).get();
}
 
Example #13
Source File: MySQLTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
  vertx = Vertx.vertx();
  pool = MySQLPool.pool(vertx, connectOptions(), new PoolOptions());
}
 
Example #14
Source File: MySQLDriver.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
  return MySQLPool.pool(wrap(options), poolOptions);
}
 
Example #15
Source File: MySQLDriver.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolOptions) {
  return MySQLPool.pool(vertx, wrap(options), poolOptions);
}
 
Example #16
Source File: MySQLTransactionTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Pool createPool() {
  return MySQLPool.pool(vertx, new MySQLConnectOptions(rule.options()), new PoolOptions().setMaxSize(1));
}
 
Example #17
Source File: MySQLTransactionTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Pool nonTxPool() {
  return MySQLPool.pool(vertx, new MySQLConnectOptions(rule.options()), new PoolOptions().setMaxSize(1));
}
 
Example #18
Source File: MySQLTracingTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Pool createPool(Vertx vertx) {
  return MySQLPool.pool(vertx, rule.options(), new PoolOptions());
}
 
Example #19
Source File: MySQLPoolBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public MySQLPoolBuildItem(RuntimeValue<MySQLPool> mysqlPool) {
    this.mysqlPool = mysqlPool;
}