Java Code Examples for io.vertx.mysqlclient.MySQLConnectOptions

The following examples show how to use io.vertx.mysqlclient.MySQLConnectOptions. 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: 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 2
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 3
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 4
Source Project: vertx-sql-client   Source File: MySQLTest.java    License: Apache License 2.0 5 votes vote down vote up
public static MySQLConnectOptions connectOptions() {
  Integer port = server.getMappedPort(3306);
  String ip = server.getContainerIpAddress();
  return new MySQLConnectOptions()
    .setPort(port)
    .setHost(ip)
    .setDatabase("testschema")
    .setUser("mysql")
    .setPassword("password");
}
 
Example 5
Source Project: vertx-sql-client   Source File: MySQLDriver.java    License: Apache License 2.0 5 votes vote down vote up
private static MySQLConnectOptions wrap(SqlConnectOptions options) {
  if (options instanceof MySQLConnectOptions) {
    return (MySQLConnectOptions) options; 
  } else {
    return new MySQLConnectOptions(options);
  }
}
 
Example 6
Source Project: vertx-sql-client   Source File: MySQLConnectionImpl.java    License: Apache License 2.0 5 votes vote down vote up
public static Future<MySQLConnection> connect(Vertx vertx, MySQLConnectOptions options) {
  ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext();
  MySQLConnectionFactory client;
  try {
    client = new MySQLConnectionFactory(ctx, options);
  } catch (Exception e) {
    return ctx.failedFuture(e);
  }
  QueryTracer tracer = ctx.tracer() == null ? null : new QueryTracer(ctx.tracer(), options);
  Promise<MySQLConnection> promise = ctx.promise();
  ctx.dispatch(null, v -> connect(client, ctx, tracer, null, promise));
  return promise.future();
}
 
Example 7
Source Project: vertx-sql-client   Source File: MySQLPoolImpl.java    License: Apache License 2.0 5 votes vote down vote up
public static MySQLPoolImpl create(ContextInternal context, boolean closeVertx, MySQLConnectOptions connectOptions, PoolOptions poolOptions) {
  QueryTracer tracer = context.tracer() == null ? null : new QueryTracer(context.tracer(), connectOptions);
  VertxMetrics vertxMetrics = context.owner().metricsSPI();
  ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(connectOptions.getSocketAddress(), "sql", connectOptions.getMetricsName()) : null;
  MySQLPoolImpl pool = new MySQLPoolImpl(context, new MySQLConnectionFactory(context, connectOptions), tracer, metrics, poolOptions);
  CloseFuture closeFuture = pool.closeFuture();
  if (closeVertx) {
    closeFuture.onComplete(ar -> context.owner().close());
  } else {
    context.addCloseHook(closeFuture);
  }
  return pool;
}
 
Example 8
Source Project: vertx-sql-client   Source File: MySQLRule.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized MySQLConnectOptions startServer() throws Exception {
  initServer();
  server.start();

  return new MySQLConnectOptions()
    .setPort(server.getMappedPort(3306))
    .setHost(server.getContainerIpAddress())
    .setDatabase("testschema")
    .setUser("mysql")
    .setPassword("password");
}
 
Example 9
Source Project: quarkus   Source File: ThreadLocalMySQLPool.java    License: Apache License 2.0 4 votes vote down vote up
public ThreadLocalMySQLPool(Vertx vertx, MySQLConnectOptions mySQLConnectOptions, PoolOptions poolOptions) {
    super(vertx, poolOptions);
    this.mySQLConnectOptions = mySQLConnectOptions;
}
 
Example 10
Source Project: vertx-sql-client   Source File: MySQLDriver.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean acceptsOptions(SqlConnectOptions options) {
  return options instanceof MySQLConnectOptions || SqlConnectOptions.class.equals(options.getClass());
}
 
Example 11
Source Project: vertx-sql-client   Source File: MySQLConnectionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public MySQLConnectionFactory(ContextInternal context, MySQLConnectOptions options) {
  NetClientOptions netClientOptions = new NetClientOptions(options);

  this.context = context;
  this.host = options.getHost();
  this.port = options.getPort();
  this.username = options.getUser();
  this.password = options.getPassword();
  this.database = options.getDatabase();
  this.connectionAttributes = options.getProperties() == null ? null : Collections.unmodifiableMap(options.getProperties());
  MySQLCollation collation;
  if (options.getCollation() != null) {
    // override the collation if configured
    collation = MySQLCollation.valueOfName(options.getCollation());
    charsetEncoding = Charset.forName(collation.mappedJavaCharsetName());
  } else {
    String charset = options.getCharset();
    if (charset == null) {
      collation = MySQLCollation.DEFAULT_COLLATION;
    } else {
      collation = MySQLCollation.valueOfName(MySQLCollation.getDefaultCollationFromCharsetName(charset));
    }
    String characterEncoding = options.getCharacterEncoding();
    if (characterEncoding == null) {
      charsetEncoding = Charset.defaultCharset();
    } else {
      charsetEncoding = Charset.forName(options.getCharacterEncoding());
    }
  }
  this.collation = collation;
  this.useAffectedRows = options.isUseAffectedRows();
  this.sslMode = options.getSslMode();

  // server RSA public key
  Buffer serverRsaPublicKey = null;
  if (options.getServerRsaPublicKeyValue() != null) {
    serverRsaPublicKey = options.getServerRsaPublicKeyValue();
  } else {
    if (options.getServerRsaPublicKeyPath() != null) {
      serverRsaPublicKey = context.owner().fileSystem().readFileBlocking(options.getServerRsaPublicKeyPath());
    }
  }
  this.serverRsaPublicKey = serverRsaPublicKey;
  this.initialCapabilitiesFlags = initCapabilitiesFlags();

  // check the SSLMode here
  switch (sslMode) {
    case VERIFY_IDENTITY:
      String hostnameVerificationAlgorithm = netClientOptions.getHostnameVerificationAlgorithm();
      if (hostnameVerificationAlgorithm == null || hostnameVerificationAlgorithm.isEmpty()) {
        throw new IllegalArgumentException("Host verification algorithm must be specified under VERIFY_IDENTITY ssl-mode.");
      }
    case VERIFY_CA:
      TrustOptions trustOptions = netClientOptions.getTrustOptions();
      if (trustOptions == null) {
        throw new IllegalArgumentException("Trust options must be specified under " + sslMode.name() + " ssl-mode.");
      }
      break;
  }

  this.cachePreparedStatements = options.getCachePreparedStatements();
  this.preparedStatementCacheSize = options.getPreparedStatementCacheMaxSize();
  this.preparedStatementCacheSqlFilter = options.getPreparedStatementCacheSqlFilter();

  this.netClient = context.owner().createNetClient(netClientOptions);
}
 
Example 12
Source Project: vertx-sql-client   Source File: MySQLRule.java    License: Apache License 2.0 4 votes vote down vote up
public MySQLConnectOptions options() {
  return new MySQLConnectOptions(options);
}
 
Example 13
Source Project: vertx-sql-client   Source File: MySQLRule.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void before() throws Throwable {
  // use an external database for testing
  if (isTestingWithExternalDatabase() && !ssl) {
    options = MySQLConnectOptions.fromUri(connectionUri);
    databaseServerInfo = DatabaseServerInfo.EXTERNAL;
    return;
  }

  // use an external database for tls testing
  if (isTlsTestingWithExternalDatabase() && ssl) {
    options = MySQLConnectOptions.fromUri(tlsConnectionUri);
    databaseServerInfo = DatabaseServerInfo.EXTERNAL;
    return;
  }

  // We do not need to launch another server if it's a shared instance
  if (this.server != null) {
    return;
  }

  // server type
  DatabaseType databaseType;
  String databaseTypeString = System.getProperty("testing.mysql.database.server");
  if (isSystemPropertyValid(databaseTypeString)) {
    databaseType = parseDatabaseTypeString(databaseTypeString);
  } else {
    // MySQL by default
    databaseType = DatabaseType.MySQL;
  }

  // server version
  String databaseVersionString = System.getProperty("testing.mysql.database.version");
  if (isSystemPropertyValid(databaseVersionString)) {
    this.databaseServerInfo = DatabaseServerInfo.valueOf(databaseType, databaseVersionString);
  } else {
    // use default version for testing servers
    if (databaseType == DatabaseType.MySQL) {
      // 5.7 by default for MySQL
      this.databaseServerInfo = DatabaseServerInfo.MySQL_V5_7;
    } else if (databaseType == DatabaseType.MariaDB) {
      // 10.4 by default for MariaDB
      this.databaseServerInfo = DatabaseServerInfo.MariaDB_V10_4;
    } else {
      throw new IllegalStateException("Unimplemented default version for: " + databaseType);
    }
  }

  options = startServer();
}
 
Example 14
Source Project: vertx-sql-client   Source File: MySQLDataTypeTestBase.java    License: Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  vertx = Vertx.vertx();
  options = new MySQLConnectOptions(MySQLTestBase.options);
}
 
Example 15
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 16
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 17
Source Project: micronaut-sql   Source File: MySQLClientConfiguration.java    License: Apache License 2.0 2 votes vote down vote up
/**
 *
 * @return The options for configuring a connection.
 */
public MySQLConnectOptions getConnectOptions() {
    return connectOptions;
}