Skip to content

Commit d60f279

Browse files
committed
Expose the supplier in the API
1 parent c3a7539 commit d60f279

File tree

3 files changed

+105
-10
lines changed

3 files changed

+105
-10
lines changed

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/MSSQLPool.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package io.vertx.mssqlclient;
1313

1414
import io.vertx.codegen.annotations.Fluent;
15+
import io.vertx.codegen.annotations.GenIgnore;
1516
import io.vertx.codegen.annotations.VertxGen;
1617
import io.vertx.core.Context;
1718
import io.vertx.core.Future;
@@ -20,9 +21,9 @@
2021
import io.vertx.mssqlclient.spi.MSSQLDriver;
2122
import io.vertx.sqlclient.*;
2223

23-
import java.util.Collections;
2424
import java.util.List;
2525
import java.util.function.Function;
26+
import java.util.function.Supplier;
2627

2728
import static io.vertx.mssqlclient.MSSQLConnectOptions.fromUri;
2829

@@ -75,7 +76,7 @@ static MSSQLPool pool(MSSQLConnectOptions database, PoolOptions options) {
7576
* Like {@link #pool(MSSQLConnectOptions, PoolOptions)} with a specific {@link Vertx} instance.
7677
*/
7778
static MSSQLPool pool(Vertx vertx, MSSQLConnectOptions database, PoolOptions options) {
78-
return pool(vertx, Collections.singletonList(database), options);
79+
return pool(vertx, () -> database, options);
7980
}
8081

8182
/**
@@ -97,6 +98,27 @@ static MSSQLPool pool(Vertx vertx, List<MSSQLConnectOptions> databases, PoolOpti
9798
return (MSSQLPool) MSSQLDriver.INSTANCE.createPool(vertx, databases, options);
9899
}
99100

101+
/**
102+
* Create a connection pool to the SQL Server {@code databases}. The supplier is called
103+
* to provide the options when a new connection is created by the pool.
104+
*
105+
* @param databases the databases supplier
106+
* @param options the options for creating the pool
107+
* @return the connection pool
108+
*/
109+
@GenIgnore
110+
static MSSQLPool pool(Supplier<MSSQLConnectOptions> databases, PoolOptions options) {
111+
return pool(null, databases, options);
112+
}
113+
114+
/**
115+
* Like {@link #pool(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
116+
*/
117+
@GenIgnore
118+
static MSSQLPool pool(Vertx vertx, Supplier<MSSQLConnectOptions> databases, PoolOptions options) {
119+
return (MSSQLPool) MSSQLDriver.INSTANCE.createPool(vertx, databases, options);
120+
}
121+
100122
@Override
101123
MSSQLPool connectHandler(Handler<SqlConnection> handler);
102124

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLPool.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package io.vertx.mysqlclient;
1313

1414
import io.vertx.codegen.annotations.Fluent;
15+
import io.vertx.codegen.annotations.GenIgnore;
1516
import io.vertx.codegen.annotations.VertxGen;
1617
import io.vertx.core.Context;
1718
import io.vertx.core.Future;
@@ -24,9 +25,9 @@
2425
import io.vertx.sqlclient.SqlClient;
2526
import io.vertx.sqlclient.SqlConnection;
2627

27-
import java.util.Collections;
2828
import java.util.List;
2929
import java.util.function.Function;
30+
import java.util.function.Supplier;
3031

3132
import static io.vertx.mysqlclient.MySQLConnectOptions.fromUri;
3233

@@ -79,7 +80,7 @@ static MySQLPool pool(MySQLConnectOptions database, PoolOptions options) {
7980
* Like {@link #pool(MySQLConnectOptions, PoolOptions)} with a specific {@link Vertx} instance.
8081
*/
8182
static MySQLPool pool(Vertx vertx, MySQLConnectOptions database, PoolOptions options) {
82-
return pool(vertx, Collections.singletonList(database), options);
83+
return pool(vertx, () -> database, options);
8384
}
8485

8586
/**
@@ -101,7 +102,26 @@ static MySQLPool pool(Vertx vertx, List<MySQLConnectOptions> databases, PoolOpti
101102
return (MySQLPool) MySQLDriver.INSTANCE.createPool(vertx, databases, options);
102103
}
103104

105+
/**
106+
* Create a connection pool to the MySQL {@code databases}. The supplier is called
107+
* to provide the options when a new connection is created by the pool.
108+
*
109+
* @param databases the server supplier
110+
* @param options the options for creating the pool
111+
* @return the connection pool
112+
*/
113+
@GenIgnore
114+
static MySQLPool pool(Supplier<MySQLConnectOptions> databases, PoolOptions options) {
115+
return pool(null, databases, options);
116+
}
104117

118+
/**
119+
* Like {@link #pool(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
120+
*/
121+
@GenIgnore
122+
static MySQLPool pool(Vertx vertx, Supplier<MySQLConnectOptions> databases, PoolOptions options) {
123+
return (MySQLPool) MySQLDriver.INSTANCE.createPool(vertx, databases, options);
124+
}
105125
/**
106126
* Like {@link #client(String, PoolOptions)} with a default {@code poolOptions}.
107127
*/
@@ -137,14 +157,14 @@ static SqlClient client(Vertx vertx, String connectionUri, PoolOptions poolOptio
137157
* @return the client
138158
*/
139159
static SqlClient client(MySQLConnectOptions connectOptions, PoolOptions poolOptions) {
140-
return client(null, Collections.singletonList(connectOptions), poolOptions);
160+
return client(null, () -> connectOptions, poolOptions);
141161
}
142162

143163
/**
144164
* Like {@link #client(MySQLConnectOptions, PoolOptions)} with a specific {@link Vertx} instance.
145165
*/
146166
static SqlClient client(Vertx vertx, MySQLConnectOptions connectOptions, PoolOptions poolOptions) {
147-
return client(vertx, Collections.singletonList(connectOptions), poolOptions);
167+
return client(vertx, () -> connectOptions, poolOptions);
148168
}
149169

150170
/**
@@ -166,6 +186,26 @@ static SqlClient client(List<MySQLConnectOptions> databases, PoolOptions options
166186
return client(null, databases, options);
167187
}
168188

189+
/**
190+
* Like {@link #client(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
191+
*/
192+
@GenIgnore
193+
static SqlClient client(Vertx vertx, Supplier<MySQLConnectOptions> mySQLConnectOptions, PoolOptions options) {
194+
return MySQLDriver.INSTANCE.createPool(vertx, mySQLConnectOptions, new MySQLPoolOptions(options).setPipelined(true));
195+
}
196+
197+
/**
198+
* Create a client backed by a connection pool to the MySQL {@code databases}. The supplier is called
199+
* to provide the options when a new connection is created by the pool.
200+
*
201+
* @param databases the databases supplier
202+
* @param options the options for creating the pool
203+
* @return the pooled client
204+
*/
205+
@GenIgnore
206+
static SqlClient client(Supplier<MySQLConnectOptions> databases, PoolOptions options) {
207+
return client(null, databases, options);
208+
}
169209

170210
@Override
171211
MySQLPool connectHandler(Handler<SqlConnection> handler);

vertx-pg-client/src/main/java/io/vertx/pgclient/PgPool.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import io.vertx.sqlclient.SqlClient;
3232
import io.vertx.sqlclient.SqlConnection;
3333

34-
import java.util.Collections;
3534
import java.util.List;
3635
import java.util.function.Function;
3736
import java.util.function.Supplier;
@@ -108,7 +107,7 @@ static PgPool pool(PgConnectOptions database, PoolOptions options) {
108107
* Like {@link #pool(PgConnectOptions, PoolOptions)} with a specific {@link Vertx} instance.
109108
*/
110109
static PgPool pool(Vertx vertx, PgConnectOptions database, PoolOptions options) {
111-
return pool(vertx, Collections.singletonList(database), options);
110+
return pool(vertx, () -> database, options);
112111
}
113112

114113
/**
@@ -131,7 +130,20 @@ static PgPool pool(Vertx vertx, List<PgConnectOptions> databases, PoolOptions po
131130
}
132131

133132
/**
134-
* Like {@link #pool(List, PoolOptions)} with a specific {@link Vertx} instance.
133+
* Create a connection pool to the PostgreSQL {@code databases}. The supplier is called
134+
* to provide the options when a new connection is created by the pool.
135+
*
136+
* @param databases the databases supplier
137+
* @param poolOptions the options for creating the pool
138+
* @return the connection pool
139+
*/
140+
@GenIgnore
141+
static PgPool pool(Supplier<PgConnectOptions> databases, PoolOptions poolOptions) {
142+
return pool(null, databases, poolOptions);
143+
}
144+
145+
/**
146+
* Like {@link #pool(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
135147
*/
136148
@GenIgnore
137149
static PgPool pool(Vertx vertx, Supplier<PgConnectOptions> databases, PoolOptions poolOptions) {
@@ -201,7 +213,7 @@ static SqlClient client(PgConnectOptions database, PoolOptions options) {
201213
* Like {@link #client(PgConnectOptions, PoolOptions)} with a specific {@link Vertx} instance.
202214
*/
203215
static SqlClient client(Vertx vertx, PgConnectOptions database, PoolOptions options) {
204-
return client(vertx, Collections.singletonList(database), options);
216+
return client(vertx, () -> database, options);
205217
}
206218

207219
/**
@@ -223,6 +235,27 @@ static SqlClient client(List<PgConnectOptions> databases, PoolOptions options) {
223235
return client(null, databases, options);
224236
}
225237

238+
/**
239+
* Like {@link #client(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
240+
*/
241+
@GenIgnore
242+
static SqlClient client(Vertx vertx, Supplier<PgConnectOptions> databases, PoolOptions options) {
243+
return PgDriver.INSTANCE.createPool(vertx, databases, new PgPoolOptions(options).setPipelined(true));
244+
}
245+
246+
/**
247+
* Create a client backed by a connection pool to the PostgreSQL {@code databases}. The supplier is called
248+
* to provide the options when a new connection is created by the pool.
249+
*
250+
* @param databases the databases supplier
251+
* @param options the options for creating the pool
252+
* @return the pooled client
253+
*/
254+
@GenIgnore
255+
static SqlClient client(Supplier<PgConnectOptions> databases, PoolOptions options) {
256+
return client(null, databases, options);
257+
}
258+
226259
@Override
227260
PgPool connectHandler(Handler<SqlConnection> handler);
228261

0 commit comments

Comments
 (0)