Search in sources :

Example 6 with MSSQLConnectOptions

use of io.vertx.mssqlclient.MSSQLConnectOptions in project vertx-sql-client by eclipse-vertx.

the class MSSQLClientExamples method connecting01.

public void connecting01() {
    // Connect options
    MSSQLConnectOptions connectOptions = new MSSQLConnectOptions().setPort(1433).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
    // Pool options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
    // Create the pooled client
    MSSQLPool client = MSSQLPool.pool(connectOptions, poolOptions);
}
Also used : MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) MSSQLPool(io.vertx.mssqlclient.MSSQLPool)

Example 7 with MSSQLConnectOptions

use of io.vertx.mssqlclient.MSSQLConnectOptions in project quarkus by quarkusio.

the class MSSQLPoolRecorder method initialize.

private MSSQLPool initialize(Vertx vertx, Integer eventLoopCount, DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactiveMSSQLConfig dataSourceReactiveMSSQLConfig) {
    PoolOptions poolOptions = toPoolOptions(eventLoopCount, dataSourceRuntimeConfig, dataSourceReactiveRuntimeConfig, dataSourceReactiveMSSQLConfig);
    MSSQLConnectOptions mssqlConnectOptions = toMSSQLConnectOptions(dataSourceRuntimeConfig, dataSourceReactiveRuntimeConfig, dataSourceReactiveMSSQLConfig);
    if (dataSourceReactiveRuntimeConfig.threadLocal.isPresent()) {
        log.warn("Configuration element 'thread-local' on Reactive datasource connections is deprecated and will be ignored. The started pool will always be based on a per-thread separate pool now.");
    }
    return MSSQLPool.pool(vertx, mssqlConnectOptions, poolOptions);
}
Also used : PoolOptions(io.vertx.sqlclient.PoolOptions) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions)

Example 8 with MSSQLConnectOptions

use of io.vertx.mssqlclient.MSSQLConnectOptions in project quarkus by quarkusio.

the class MSSQLPoolRecorder method toMSSQLConnectOptions.

private MSSQLConnectOptions toMSSQLConnectOptions(DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactiveMSSQLConfig dataSourceReactiveMSSQLConfig) {
    MSSQLConnectOptions mssqlConnectOptions;
    if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
        String url = dataSourceReactiveRuntimeConfig.url.get();
        // clean up the URL to make migrations easier
        if (url.startsWith("vertx-reactive:sqlserver://")) {
            url = url.substring("vertx-reactive:".length());
        }
        mssqlConnectOptions = MSSQLConnectOptions.fromUri(url);
    } else {
        mssqlConnectOptions = new MSSQLConnectOptions();
    }
    if (dataSourceReactiveMSSQLConfig.packetSize.isPresent()) {
        mssqlConnectOptions.setPacketSize(dataSourceReactiveMSSQLConfig.packetSize.getAsInt());
    }
    if (dataSourceRuntimeConfig.username.isPresent()) {
        mssqlConnectOptions.setUser(dataSourceRuntimeConfig.username.get());
    }
    if (dataSourceRuntimeConfig.password.isPresent()) {
        mssqlConnectOptions.setPassword(dataSourceRuntimeConfig.password.get());
    }
    // credentials provider
    if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
        String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
        CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
        String name = dataSourceRuntimeConfig.credentialsProvider.get();
        Map<String, String> credentials = credentialsProvider.getCredentials(name);
        String user = credentials.get(USER_PROPERTY_NAME);
        String password = credentials.get(PASSWORD_PROPERTY_NAME);
        if (user != null) {
            mssqlConnectOptions.setUser(user);
        }
        if (password != null) {
            mssqlConnectOptions.setPassword(password);
        }
    }
    mssqlConnectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);
    mssqlConnectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());
    mssqlConnectOptions.setSsl(dataSourceReactiveMSSQLConfig.ssl);
    mssqlConnectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll);
    configurePemTrustOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePem);
    configureJksTrustOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificateJks);
    configurePfxTrustOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePfx);
    configurePemKeyCertOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePem);
    configureJksKeyCertOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
    configurePfxKeyCertOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);
    if (dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.isPresent()) {
        mssqlConnectOptions.setHostnameVerificationAlgorithm(dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.get());
    }
    return mssqlConnectOptions;
}
Also used : MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Example 9 with MSSQLConnectOptions

use of io.vertx.mssqlclient.MSSQLConnectOptions in project vertx-sql-client by eclipse-vertx.

the class MSSQLDriver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    MSSQLConnectOptions baseConnectOptions = MSSQLConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, 1, options, null, null, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) MSSQLConnectionUriParser(io.vertx.mssqlclient.impl.MSSQLConnectionUriParser) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) MSSQLConnectionFactory(io.vertx.mssqlclient.impl.MSSQLConnectionFactory) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) MSSQLConnectionImpl(io.vertx.mssqlclient.impl.MSSQLConnectionImpl) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) CloseFuture(io.vertx.core.impl.CloseFuture) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) MSSQLPool(io.vertx.mssqlclient.MSSQLPool) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) MSSQLConnectionFactory(io.vertx.mssqlclient.impl.MSSQLConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl)

Example 10 with MSSQLConnectOptions

use of io.vertx.mssqlclient.MSSQLConnectOptions in project vertx-sql-client by eclipse-vertx.

the class MSSQLConnectOptionsProviderTest method testValidUri5.

@Test
public void testValidUri5() {
    connectionUri = "sqlserver://user@myhost";
    actualConfiguration = MSSQLConnectOptions.fromUri(connectionUri);
    expectedConfiguration = new MSSQLConnectOptions().setUser("user").setHost("myhost");
    assertEquals(expectedConfiguration, actualConfiguration);
}
Also used : MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) Test(org.junit.Test)

Aggregations

MSSQLConnectOptions (io.vertx.mssqlclient.MSSQLConnectOptions)14 MSSQLPool (io.vertx.mssqlclient.MSSQLPool)6 Test (org.junit.Test)4 Vertx (io.vertx.core.Vertx)2 PoolOptions (io.vertx.sqlclient.PoolOptions)2 SqlConnectOptions (io.vertx.sqlclient.SqlConnectOptions)2 Collectors (java.util.stream.Collectors)2 CredentialsProvider (io.quarkus.credentials.CredentialsProvider)1 CloseFuture (io.vertx.core.impl.CloseFuture)1 ContextInternal (io.vertx.core.impl.ContextInternal)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 JsonObject (io.vertx.core.json.JsonObject)1 PemTrustOptions (io.vertx.core.net.PemTrustOptions)1 ClientMetrics (io.vertx.core.spi.metrics.ClientMetrics)1 VertxMetrics (io.vertx.core.spi.metrics.VertxMetrics)1 Source (io.vertx.docgen.Source)1 MSSQLConnection (io.vertx.mssqlclient.MSSQLConnection)1 MSSQLConnectionFactory (io.vertx.mssqlclient.impl.MSSQLConnectionFactory)1 MSSQLConnectionImpl (io.vertx.mssqlclient.impl.MSSQLConnectionImpl)1 MSSQLConnectionUriParser (io.vertx.mssqlclient.impl.MSSQLConnectionUriParser)1