-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathDB2Pool.java
More file actions
209 lines (184 loc) · 7 KB
/
DB2Pool.java
File metadata and controls
209 lines (184 loc) · 7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (C) 2019,2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vertx.db2client;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.net.NetClientOptions;
import io.vertx.db2client.impl.Db2PoolOptions;
import io.vertx.db2client.spi.DB2Driver;
import io.vertx.sqlclient.Pool;
import io.vertx.sqlclient.PoolOptions;
import io.vertx.sqlclient.SqlClient;
import io.vertx.sqlclient.SqlConnection;
import io.vertx.sqlclient.impl.Utils;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import static io.vertx.db2client.DB2ConnectOptions.fromUri;
/**
* A pool of DB2 connections.
*/
@VertxGen
public interface DB2Pool extends Pool {
/**
* Like {@link #pool(String, PoolOptions)} with default options.
*/
static DB2Pool pool(String connectionUri) {
return pool(connectionUri, new PoolOptions());
}
/**
* Like {@link #pool(DB2ConnectOptions, PoolOptions)} with
* {@code database} build from {@code connectionUri}.
*/
static DB2Pool pool(String connectionUri, PoolOptions options) {
return pool(fromUri(connectionUri), options);
}
/**
* Like {@link #pool(Vertx, String,PoolOptions)} with default options.
*/
static DB2Pool pool(Vertx vertx, String connectionUri) {
return pool(vertx, fromUri(connectionUri), new PoolOptions());
}
/**
* Like {@link #pool(Vertx, DB2ConnectOptions, PoolOptions)} with
* {@code database} build from {@code connectionUri}.
*/
static DB2Pool pool(Vertx vertx, String connectionUri, PoolOptions options) {
return pool(vertx, fromUri(connectionUri), options);
}
/**
* Create a connection pool to the DB2 {@code database} configured with the given {@code options}.
*
* @param database the options for the connection
* @param options the options for creating the pool
* @return the connection pool
*/
static DB2Pool pool(DB2ConnectOptions database, PoolOptions options) {
return pool(null, database, options);
}
/**
* Like {@link #pool(DB2ConnectOptions, PoolOptions)} with a specific
* {@link Vertx} instance.
*/
static DB2Pool pool(Vertx vertx, DB2ConnectOptions database, PoolOptions options) {
return pool(vertx, Collections.singletonList(database), options);
}
/**
* Create a connection pool to the DB2 {@code databases} with round-robin selection.
* Round-robin is applied when a new connection is created by the pool.
*
* @param databases the list of servers
* @param options the options for creating the pool
* @return the connection pool
*/
static DB2Pool pool(List<DB2ConnectOptions> databases, PoolOptions options) {
return pool(null, databases, options);
}
/**
* Like {@link #pool(List, PoolOptions)} with a specific
* {@link Vertx} instance.
*/
static DB2Pool pool(Vertx vertx, List<DB2ConnectOptions> databases, PoolOptions options) {
return (DB2Pool) DB2Driver.INSTANCE.createPool(vertx, Utils.roundRobinSupplier(databases), options, new NetClientOptions());
}
/**
* Create a connection pool to the DB2 {@code databases}. The supplier is called
* to provide the options when a new connection is created by the pool.
*
* @param databases the databases supplier
* @param poolOptions the options for creating the pool
* @return the connection pool
*/
static DB2Pool pool(Supplier<Future<DB2ConnectOptions>> databases, PoolOptions poolOptions) {
return pool(null, databases, poolOptions);
}
/**
* Like {@link #pool(Supplier, PoolOptions)} with a specific {@link Vertx} instance.
*/
static DB2Pool pool(Vertx vertx, Supplier<Future<DB2ConnectOptions>> databases, PoolOptions poolOptions) {
return (DB2Pool) DB2Driver.INSTANCE.createPool(vertx, databases, poolOptions, new NetClientOptions());
}
/**
* Like {@link #client(String, PoolOptions)} with default options.
*/
static SqlClient client(String connectionUri) {
return client(connectionUri, new PoolOptions());
}
/**
* Like {@link #client(DB2ConnectOptions, PoolOptions)} with
* {@code database} build from {@code connectionUri}.
*/
static SqlClient client(String connectionUri, PoolOptions options) {
return client(fromUri(connectionUri), options);
}
/**
* Like {@link #client(Vertx, String, PoolOptions)} with default options.
*/
static SqlClient client(Vertx vertx, String connectionUri) {
return client(vertx, fromUri(connectionUri), new PoolOptions());
}
/**
* Like {@link #client(Vertx, DB2ConnectOptions, PoolOptions)} with
* {@code database} build from {@code connectionUri}.
*/
static SqlClient client(Vertx vertx, String connectionUri, PoolOptions options) {
return client(vertx, fromUri(connectionUri), options);
}
/**
* Create a pooled client to the DB2 {@code database} configured with the given {@code options}.
*
* @param database the options for the connection
* @param options the options for creating the pool
* @return the connection pool
*/
static SqlClient client(DB2ConnectOptions database, PoolOptions options) {
return client(null, database, options);
}
/**
* Like {@link #client(DB2ConnectOptions, PoolOptions)} with a specific
* {@link Vertx} instance.
*/
static SqlClient client(Vertx vertx, DB2ConnectOptions database, PoolOptions options) {
return client(vertx, Collections.singletonList(database), options);
}
/**
* Create a client backed by a connection pool to the DB2 {@code databases} with round-robin selection.
* Round-robin is applied when a new connection is created by the pool.
*
* @param databases the list of servers
* @param options the options for creating the pool
* @return the pooled client
*/
static SqlClient client(List<DB2ConnectOptions> databases, PoolOptions options) {
return client(null, databases, options);
}
/**
* Like {@link #client(List, PoolOptions)} with a specific
* {@link Vertx} instance.
*/
static SqlClient client(Vertx vertx, List<DB2ConnectOptions> databases, PoolOptions options) {
return DB2Driver.INSTANCE.createPool(vertx, Utils.roundRobinSupplier(databases), new Db2PoolOptions(options).setPipelined(true), new NetClientOptions());
}
@Override
DB2Pool connectHandler(Handler<SqlConnection> handler);
@Fluent
DB2Pool connectionProvider(Function<Context, Future<SqlConnection>> provider);
}