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