Java Code Examples for io.vertx.mysqlclient.MySQLPool

The following examples show how to use io.vertx.mysqlclient.MySQLPool. These examples are extracted from open source projects. 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 Project: quarkus   Source File: MySQLPoolRecorder.java    License: 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 2
Source Project: vertx-auth   Source File: MySQLTest.java    License: 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 3
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 4
Source Project: quarkus   Source File: MySQLPoolProducer.java    License: 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 5
Source Project: quarkus   Source File: MySQLPoolProducer.java    License: 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 6
Source Project: quarkus   Source File: MySQLPoolRecorder.java    License: 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 7
Source Project: quarkus   Source File: MySQLPoolRecorder.java    License: 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 8
Source Project: quarkus   Source File: MySQLPoolBuildItem.java    License: Apache License 2.0 4 votes vote down vote up
public MySQLPoolBuildItem(RuntimeValue<MySQLPool> mysqlPool) {
    this.mysqlPool = mysqlPool;
}
 
Example 9
Source Project: quarkus   Source File: MySQLPoolBuildItem.java    License: Apache License 2.0 4 votes vote down vote up
public RuntimeValue<MySQLPool> getMySQLPool() {
    return mysqlPool;
}
 
Example 10
Source Project: quarkus   Source File: ReactiveMySQLClientProcessor.java    License: 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 11
Source Project: quarkus   Source File: MySQLPoolProducer.java    License: 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 12
Source Project: quarkus   Source File: ThreadLocalMySQLPool.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected MySQLPool createThreadLocalPool() {
    return MySQLPool.pool(vertx, mySQLConnectOptions, poolOptions);
}
 
Example 13
@PostConstruct
protected void init() {
    mySQLPool = Arc.container().instance(MySQLPool.class).get();
}
 
Example 14
Source Project: vertx-sql-client   Source File: MySQLTest.java    License: 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 15
Source Project: vertx-sql-client   Source File: MySQLDriver.java    License: 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 16
Source Project: vertx-sql-client   Source File: MySQLDriver.java    License: 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 17
Source Project: vertx-sql-client   Source File: MySQLTransactionTest.java    License: 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 18
Source Project: vertx-sql-client   Source File: MySQLTransactionTest.java    License: 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 19
Source Project: vertx-sql-client   Source File: MySQLTracingTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Pool createPool(Vertx vertx) {
  return MySQLPool.pool(vertx, rule.options(), new PoolOptions());
}