use of io.vertx.sqlclient.SqlConnectOptions in project vertx-sql-client by eclipse-vertx.
the class DB2Driver method newPoolImpl.
private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
DB2ConnectOptions baseConnectOptions = DB2ConnectOptions.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;
boolean pipelinedPool = options instanceof Db2PoolOptions && ((Db2PoolOptions) options).isPipelined();
int pipeliningLimit = pipelinedPool ? baseConnectOptions.getPipeliningLimit() : 1;
PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, pipeliningLimit, 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.sqlclient.SqlConnectOptions in project vertx-sql-client by eclipse-vertx.
the class PgConnectionAutoRetryTest method initialConnector.
@Override
protected void initialConnector(int proxyPort) {
SqlConnectOptions proxyOptions = new PgConnectOptions(options);
proxyOptions.setPort(proxyPort);
proxyOptions.setHost("localhost");
connectionConnector = ClientConfig.CONNECT.connect(vertx, proxyOptions);
poolConnector = ClientConfig.POOLED.connect(vertx, proxyOptions);
}
use of io.vertx.sqlclient.SqlConnectOptions in project hibernate-reactive by hibernate.
the class DefaultSqlClientPoolConfiguration method connectOptions.
@Override
public SqlConnectOptions connectOptions(URI uri) {
String scheme = uri.getScheme();
String path = scheme.equals("oracle") ? oraclePath(uri) : uri.getPath();
String database = path.length() > 0 ? path.substring(1) : "";
if (scheme.equals("db2") && database.indexOf(':') > 0) {
// DB2 URLs are a bit odd and have the format:
// jdbc:db2://<HOST>:<PORT>/<DB>:key1=value1;key2=value2;
database = database.substring(0, database.indexOf(':'));
}
String host = scheme.equals("oracle") ? oracleHost(uri) : uri.getHost();
int port = scheme.equals("oracle") ? oraclePort(uri) : uri.getPort();
int index = uri.toString().indexOf(';');
if (scheme.equals("sqlserver") && index > 0) {
// SQL Server separates parameters in the url with a semicolon (';')
// and the URI class doesn't get the right value for host and port when the url
// contains parameters
URI uriWithoutParams = URI.create(uri.toString().substring(0, index));
host = uriWithoutParams.getHost();
port = uriWithoutParams.getPort();
}
if (port == -1) {
port = defaultPort(scheme);
}
// see if the credentials were specified via properties
String username = user;
String password = pass;
Map<String, String> extraProps = new HashMap<>();
if (username == null || password == null) {
// if not, look for URI-style user info first
String userInfo = uri.getUserInfo();
if (userInfo != null) {
String[] bits = userInfo.split(":");
username = bits[0];
if (bits.length > 1) {
password = bits[1];
}
} else {
// check the query for named parameters
// in case it's a JDBC-style URL
String[] params = {};
// jdbc:db2://<HOST>:<PORT>/<DB>:key1=value1;key2=value2;
if (scheme.equals("db2")) {
int queryIndex = uri.getPath().indexOf(':') + 1;
if (queryIndex > 0) {
params = uri.getPath().substring(queryIndex).split(";");
}
} else if (scheme.contains("sqlserver")) {
// SQL Server separates parameters in the url with a semicolon (';')
// Ex: jdbc:sqlserver://<server>:<port>;<database>=AdventureWorks;user=<user>;password=<password>
String query = uri.getQuery();
String rawQuery = uri.getRawQuery();
String s = uri.toString();
int queryIndex = s.indexOf(';') + 1;
if (queryIndex > 0) {
params = s.substring(queryIndex).split(";");
}
} else {
final String query = scheme.equals("oracle") ? oracleQuery(uri) : uri.getQuery();
if (query != null) {
params = query.split("&");
}
}
for (String param : params) {
if (param.startsWith("user=")) {
username = param.substring(5);
} else if (param.startsWith("pass=")) {
password = param.substring(5);
} else if (param.startsWith("password=")) {
password = param.substring(9);
} else if (param.startsWith("database=")) {
database = param.substring(9);
} else {
final int position = param.indexOf("=");
if (position != -1) {
// We assume the first '=' is the one separating key and value
String key = param.substring(0, position);
String value = param.substring(position + 1);
extraProps.put(key, value);
} else {
// A key without a value
extraProps.put(param, null);
}
}
}
}
}
if (username == null) {
throw new HibernateError("database username not specified (set the property 'javax.persistence.jdbc.user', or include it as a parameter in the connection URL)");
}
SqlConnectOptions connectOptions = new SqlConnectOptions().setHost(host).setPort(port).setDatabase(database).setUser(username);
if (password != null) {
connectOptions.setPassword(password);
}
for (String key : extraProps.keySet()) {
connectOptions.addProperty(key, extraProps.get(key));
}
// enable the prepared statement cache by default
connectOptions.setCachePreparedStatements(true);
if (cacheMaxSize != null) {
if (cacheMaxSize <= 0) {
LOG.preparedStatementCacheDisabled();
connectOptions.setCachePreparedStatements(false);
} else {
LOG.preparedStatementCacheMaxSize(cacheMaxSize);
connectOptions.setCachePreparedStatements(true);
connectOptions.setPreparedStatementCacheMaxSize(cacheMaxSize);
}
}
if (sqlLimit != null) {
LOG.preparedStatementCacheSQLLimit(sqlLimit);
connectOptions.setPreparedStatementCacheSqlLimit(sqlLimit);
}
return connectOptions;
}
use of io.vertx.sqlclient.SqlConnectOptions in project hibernate-reactive by hibernate.
the class JdbcUrlParserTest method assertOptions.
/**
* Create the default {@link SqlConnectOptions} with the given extra properties
* and assert that's correct.
*/
private void assertOptions(String url, String expectedDbName, Map<String, String> parameters) {
URI uri = DefaultSqlClientPool.parse(url);
SqlConnectOptions options = new DefaultSqlClientPoolConfiguration().connectOptions(uri);
// These keys won't be mapped as properties
String username = parameters.remove("user");
String password = parameters.remove("password");
parameters.remove("database");
assertThat(options).as("URL: " + url).isNotNull();
assertThat(options.getUser()).as("URL: " + url).isEqualTo(username);
assertThat(options.getPassword()).as("URL: " + url).isEqualTo(password);
assertThat(options.getDatabase()).as("URL: " + url).isEqualTo(expectedDbName);
assertThat(options.getHost()).as("URL: " + url).isEqualTo("localhost");
assertThat(options.getPort()).as("URL: " + url).isEqualTo(dbType().getDefaultPort());
// Check extra properties
assertThat(options.getProperties()).as("URL: " + url).containsExactlyInAnyOrderEntriesOf(parameters);
}
use of io.vertx.sqlclient.SqlConnectOptions in project hibernate-reactive by hibernate.
the class DefaultPortTest method testDefaultPortIsSet.
@Test
public void testDefaultPortIsSet() throws URISyntaxException {
DefaultSqlClientPoolConfiguration configuration = new DefaultSqlClientPoolConfiguration();
configuration.configure(requiredProperties());
SqlConnectOptions sqlConnectOptions = configuration.connectOptions(new URI(scheme() + "://localhost/database"));
Assertions.assertThat(sqlConnectOptions.getPort()).as("Default port not defined for " + dbType()).isEqualTo(dbType().getDefaultPort());
}
Aggregations