Skip to content

Commit 96e16d1

Browse files
committed
Update documentation
1 parent 5037e3f commit 96e16d1

File tree

9 files changed

+76
-67
lines changed

9 files changed

+76
-67
lines changed

vertx-db2-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,11 @@ public static void poolSharing3(Vertx vertx, DB2ConnectOptions database, int max
407407
.setEventLoopSize(4));
408408
}
409409

410-
public void dynamicPoolConfig(Vertx vertx, DB2Pool pool) {
411-
pool.connectionProvider(ctx -> {
412-
Future<DB2ConnectOptions> fut = retrieveOptions();
413-
return fut.compose(connectOptions -> {
414-
// Do not forget to close later
415-
ConnectionFactory factory = DB2Driver.INSTANCE.createConnectionFactory(vertx, connectOptions);
416-
return factory.connect(ctx);
417-
});
418-
});
410+
public void dynamicPoolConfig(Vertx vertx, PoolOptions poolOptions) {
411+
DB2Pool pool = DB2Pool.pool(vertx, () -> {
412+
Future<DB2ConnectOptions> connectOptions = retrieveOptions();
413+
return connectOptions;
414+
}, poolOptions);
419415
}
420416

421417
private Future<DB2ConnectOptions> retrieveOptions() {

vertx-db2-client/src/main/java/io/vertx/db2client/DB2Pool.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.vertx.db2client;
1717

1818
import io.vertx.codegen.annotations.Fluent;
19+
import io.vertx.codegen.annotations.GenIgnore;
1920
import io.vertx.codegen.annotations.VertxGen;
2021
import io.vertx.core.Context;
2122
import io.vertx.core.Future;
@@ -31,6 +32,7 @@
3132
import java.util.Collections;
3233
import java.util.List;
3334
import java.util.function.Function;
35+
import java.util.function.Supplier;
3436

3537
import static io.vertx.db2client.DB2ConnectOptions.fromUri;
3638

@@ -109,6 +111,28 @@ static DB2Pool pool(Vertx vertx, List<DB2ConnectOptions> databases, PoolOptions
109111
return (DB2Pool) DB2Driver.INSTANCE.createPool(vertx, databases, options);
110112
}
111113

114+
/**
115+
* Create a connection pool to the DB2 {@code databases}. The supplier is called
116+
* to provide the options when a new connection is created by the pool.
117+
*
118+
* @param databases the databases supplier
119+
* @param poolOptions the options for creating the pool
120+
* @return the connection pool
121+
*/
122+
@GenIgnore
123+
static DB2Pool pool(Supplier<Future<DB2ConnectOptions>> databases, PoolOptions poolOptions) {
124+
return pool(null, databases, poolOptions);
125+
}
126+
127+
128+
/**
129+
* Like {@link #pool(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
130+
*/
131+
@GenIgnore
132+
static DB2Pool pool(Vertx vertx, Supplier<Future<DB2ConnectOptions>> databases, PoolOptions poolOptions) {
133+
return (DB2Pool) DB2Driver.INSTANCE.createPool(vertx, databases, poolOptions);
134+
}
135+
112136
/**
113137
* Like {@link #client(String, PoolOptions)} with default options.
114138
*/

vertx-mssql-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,11 @@ public static void poolSharing3(Vertx vertx, MSSQLConnectOptions database, int m
416416
.setEventLoopSize(4));
417417
}
418418

419-
public void dynamicPoolConfig(Vertx vertx, MSSQLPool pool) {
420-
pool.connectionProvider(ctx -> {
421-
Future<MSSQLConnectOptions> fut = retrieveOptions();
422-
return fut.compose(connectOptions -> {
423-
// Do not forget to close later
424-
ConnectionFactory factory = MSSQLDriver.INSTANCE.createConnectionFactory(vertx, connectOptions);
425-
return factory.connect(ctx);
426-
});
427-
});
419+
public void dynamicPoolConfig(Vertx vertx, PoolOptions poolOptions) {
420+
MSSQLPool pool = MSSQLPool.pool(vertx, () -> {
421+
Future<MSSQLConnectOptions> connectOptions = retrieveOptions();
422+
return connectOptions;
423+
}, poolOptions);
428424
}
429425

430426
private Future<MSSQLConnectOptions> retrieveOptions() {

vertx-mysql-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,11 @@ public static void poolSharing3(Vertx vertx, MySQLConnectOptions database, int m
387387
.setEventLoopSize(4));
388388
}
389389

390-
public void dynamicPoolConfig(Vertx vertx, MySQLPool pool) {
391-
pool.connectionProvider(ctx -> {
392-
Future<MySQLConnectOptions> fut = retrieveOptions();
393-
return fut.compose(connectOptions -> {
394-
// Do not forget to close later
395-
ConnectionFactory factory = MySQLDriver.INSTANCE.createConnectionFactory(vertx, connectOptions);
396-
return factory.connect(ctx);
397-
});
398-
});
390+
public void dynamicPoolConfig(Vertx vertx, PoolOptions poolOptions) {
391+
MySQLPool pool = MySQLPool.pool(vertx, () -> {
392+
Future<MySQLConnectOptions> connectOptions = retrieveOptions();
393+
return connectOptions;
394+
}, poolOptions);
399395
}
400396

401397
private Future<MySQLConnectOptions> retrieveOptions() {

vertx-oracle-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import io.vertx.docgen.Source;
2323
import io.vertx.oracleclient.OracleConnectOptions;
2424
import io.vertx.oracleclient.OraclePool;
25-
import io.vertx.oracleclient.spi.OracleDriver;
2625
import io.vertx.sqlclient.*;
27-
import io.vertx.sqlclient.spi.ConnectionFactory;
2826

2927
import java.util.ArrayList;
3028
import java.util.Arrays;
@@ -338,15 +336,11 @@ public void tracing01(OracleConnectOptions options) {
338336
options.setTracingPolicy(TracingPolicy.ALWAYS);
339337
}
340338

341-
public void dynamicPoolConfig(Vertx vertx, OraclePool pool) {
342-
pool.connectionProvider(ctx -> {
343-
Future<OracleConnectOptions> fut = retrieveOptions();
344-
return fut.compose(connectOptions -> {
345-
// Do not forget to close later
346-
ConnectionFactory factory = OracleDriver.INSTANCE.createConnectionFactory(vertx, connectOptions);
347-
return factory.connect(ctx);
348-
});
349-
});
339+
public void dynamicPoolConfig(Vertx vertx, PoolOptions poolOptions) {
340+
OraclePool pool = OraclePool.pool(vertx, () -> {
341+
Future<OracleConnectOptions> connectOptions = retrieveOptions();
342+
return connectOptions;
343+
}, poolOptions);
350344
}
351345

352346
private Future<OracleConnectOptions> retrieveOptions() {

vertx-oracle-client/src/main/java/io/vertx/oracleclient/OraclePool.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
package io.vertx.oracleclient;
1212

13+
import io.vertx.codegen.annotations.GenIgnore;
1314
import io.vertx.codegen.annotations.VertxGen;
1415
import io.vertx.core.Context;
1516
import io.vertx.core.Future;
@@ -22,6 +23,7 @@
2223

2324
import java.util.Collections;
2425
import java.util.function.Function;
26+
import java.util.function.Supplier;
2527

2628
/**
2729
* Represents a pool of connection to interact with an Oracle database.
@@ -54,6 +56,28 @@ static OraclePool pool(Vertx vertx, String connectionUri, PoolOptions poolOption
5456
return pool(vertx, OracleConnectOptions.fromUri(connectionUri), poolOptions);
5557
}
5658

59+
/**
60+
* Create a connection pool to the Oracle {@code databases}. The supplier is called
61+
* to provide the options when a new connection is created by the pool.
62+
*
63+
* @param databases the databases supplier
64+
* @param poolOptions the options for creating the pool
65+
* @return the connection pool
66+
*/
67+
@GenIgnore
68+
static OraclePool pool(Supplier<Future<OracleConnectOptions>> databases, PoolOptions poolOptions) {
69+
return pool(null, databases, poolOptions);
70+
}
71+
72+
73+
/**
74+
* Like {@link #pool(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
75+
*/
76+
@GenIgnore
77+
static OraclePool pool(Vertx vertx, Supplier<Future<OracleConnectOptions>> databases, PoolOptions poolOptions) {
78+
return (OraclePool) OracleDriver.INSTANCE.createPool(vertx, databases, poolOptions);
79+
}
80+
5781
@Override
5882
OraclePool connectHandler(Handler<SqlConnection> handler);
5983

vertx-pg-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,11 @@ public static void poolSharing3(Vertx vertx, PgConnectOptions database, int maxS
411411
.setEventLoopSize(4));
412412
}
413413

414-
public void dynamicPoolConfig(Vertx vertx, PgPool pool) {
415-
pool.connectionProvider(ctx -> {
416-
Future<PgConnectOptions> fut = retrieveOptions();
417-
return fut.compose(connectOptions -> {
418-
// Do not forget to close later
419-
ConnectionFactory factory = PgDriver.INSTANCE.createConnectionFactory(vertx, connectOptions);
420-
return factory.connect(ctx);
421-
});
422-
});
414+
public void dynamicPoolConfig(Vertx vertx, PoolOptions poolOptions) {
415+
PgPool pool = PgPool.pool(vertx, () -> {
416+
Future<PgConnectOptions> connectOptions = retrieveOptions();
417+
return connectOptions;
418+
}, poolOptions);
423419
}
424420

425421
private Future<PgConnectOptions> retrieveOptions() {

vertx-sql-client/src/main/asciidoc/pool_config.adoc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ has been created and before it is inserted in the pool.
2323

2424
Once you are done with the connection, you should simply close it to signal the pool to use it.
2525

26-
=== Dynamic connection provider
26+
=== Dynamic connection configuration
2727

28-
By default, the pool create connections using {@link io.vertx.sqlclient.spi.ConnectionFactory#connect ConnectionFactory#connect}.
28+
You can configure the pool connection details using a Java supplier instead of an instance of `SqlConnectOptions`.
2929

30-
But you can provide your own implementation in {@link io.vertx.sqlclient.Pool#connectionProvider Pool#connectionProvider}.
31-
32-
Since the provider is asynchronous, it can be used to provide dynamic pool configuration (e.g. password rotation).
30+
Since the supplier is asynchronous, it can be used to provide dynamic pool configuration (e.g. password rotation).
3331

3432
[source,$lang]
3533
----
3634
{@link examples.SqlClientExamples#dynamicPoolConfig}
3735
----
38-
39-
CAUTION: When the connection factory becomes useless (e.g. because of a new configuration) it must be closed to release its resources.

vertx-sql-client/src/main/java/examples/SqlClientExamples.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import io.vertx.core.Vertx;
2323
import io.vertx.core.tracing.TracingPolicy;
2424
import io.vertx.sqlclient.*;
25-
import io.vertx.sqlclient.spi.ConnectionFactory;
2625
import io.vertx.sqlclient.spi.Driver;
2726

2827
import java.util.ArrayList;
@@ -458,17 +457,5 @@ public static void poolSharing3(Vertx vertx, SqlConnectOptions database, int max
458457

459458

460459
public void dynamicPoolConfig(Vertx vertx, Pool pool, Driver driver) {
461-
pool.connectionProvider(ctx -> {
462-
Future<SqlConnectOptions> fut = retrieveOptions();
463-
return fut.compose(connectOptions -> {
464-
// Do not forget to close later
465-
ConnectionFactory factory = driver.createConnectionFactory(vertx, connectOptions);
466-
return factory.connect(ctx);
467-
});
468-
});
469-
}
470-
471-
private Future<SqlConnectOptions> retrieveOptions() {
472-
return null;
473460
}
474461
}

0 commit comments

Comments
 (0)