Skip to content

Commit 376822a

Browse files
committed
Update documentation
1 parent f3fbd20 commit 376822a

File tree

9 files changed

+77
-67
lines changed

9 files changed

+77
-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-
// Do not forget to close later
412-
ConnectionFactory factory = DB2Driver.INSTANCE.createConnectionFactory(vertx);
413-
pool.connectionProvider(ctx -> {
414-
Future<DB2ConnectOptions> fut = retrieveOptions();
415-
return fut.compose(connectOptions -> {
416-
return factory.connect(ctx, connectOptions);
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-
// Do not forget to close later
421-
ConnectionFactory factory = MSSQLDriver.INSTANCE.createConnectionFactory(vertx);
422-
pool.connectionProvider(ctx -> {
423-
Future<MSSQLConnectOptions> fut = retrieveOptions();
424-
return fut.compose(connectOptions -> {
425-
return factory.connect(ctx, connectOptions);
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-
// Do not forget to close later
392-
ConnectionFactory factory = MySQLDriver.INSTANCE.createConnectionFactory(vertx);
393-
pool.connectionProvider(ctx -> {
394-
Future<MySQLConnectOptions> fut = retrieveOptions();
395-
return fut.compose(connectOptions -> {
396-
return factory.connect(ctx, connectOptions);
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-
// Do not forget to close later
343-
ConnectionFactory factory = OracleDriver.INSTANCE.createConnectionFactory(vertx);
344-
pool.connectionProvider(ctx -> {
345-
Future<OracleConnectOptions> fut = retrieveOptions();
346-
return fut.compose(connectOptions -> {
347-
return factory.connect(ctx, connectOptions);
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: 25 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;
@@ -19,9 +20,11 @@
1920
import io.vertx.sqlclient.Pool;
2021
import io.vertx.sqlclient.PoolOptions;
2122
import io.vertx.sqlclient.SqlConnection;
23+
import io.vertx.sqlclient.impl.SingletonSupplier;
2224

2325
import java.util.Collections;
2426
import java.util.function.Function;
27+
import java.util.function.Supplier;
2528

2629
/**
2730
* Represents a pool of connection to interact with an Oracle database.
@@ -54,6 +57,28 @@ static OraclePool pool(Vertx vertx, String connectionUri, PoolOptions poolOption
5457
return pool(vertx, OracleConnectOptions.fromUri(connectionUri), poolOptions);
5558
}
5659

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

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-
// Do not forget to close later
416-
ConnectionFactory factory = PgDriver.INSTANCE.createConnectionFactory(vertx);
417-
pool.connectionProvider(ctx -> {
418-
Future<PgConnectOptions> fut = retrieveOptions();
419-
return fut.compose(connectOptions -> {
420-
return factory.connect(ctx, connectOptions);
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-
// Do not forget to close later
462-
ConnectionFactory factory = driver.createConnectionFactory(vertx);
463-
pool.connectionProvider(ctx -> {
464-
Future<SqlConnectOptions> fut = retrieveOptions();
465-
return fut.compose(connectOptions -> {
466-
return factory.connect(ctx, connectOptions);
467-
});
468-
});
469-
}
470-
471-
private Future<SqlConnectOptions> retrieveOptions() {
472-
return null;
473460
}
474461
}

0 commit comments

Comments
 (0)