-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathOracleConnectOptions.java
404 lines (348 loc) · 10.8 KB
/
OracleConnectOptions.java
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
* Copyright (c) 2011-2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.oracleclient;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.tracing.TracingPolicy;
import io.vertx.oracleclient.impl.OracleConnectionUriParser;
import io.vertx.sqlclient.SqlConnectOptions;
import java.util.Map;
import java.util.function.Predicate;
@DataObject
@JsonGen(publicConverter = false)
public class OracleConnectOptions extends SqlConnectOptions {
/**
* @return the {@code options} as Oracle specific connect options
*/
public static OracleConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof OracleConnectOptions) {
return (OracleConnectOptions) options;
} else {
return new OracleConnectOptions(options);
}
}
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 1521;
public static final String DEFAULT_USER = "";
public static final String DEFAULT_PASSWORD = "";
public static final String DEFAULT_DATABASE = "";
public static final boolean DEFAULT_SSL = false;
public static final int DEFAULT_PIPELINING_LIMIT = 1;
private String serviceId;
private String serviceName;
private ServerMode serverMode;
private String instanceName;
private String tnsAlias;
private String tnsAdmin;
private boolean ssl;
private int pipeliningLimit = DEFAULT_PIPELINING_LIMIT;
public OracleConnectOptions() {
super();
}
public OracleConnectOptions(OracleConnectOptions other) {
super(other);
copyFields(other);
}
private void copyFields(OracleConnectOptions other) {
this.serviceId = other.serviceId;
this.serviceName = other.serviceName;
this.serverMode = other.serverMode;
this.instanceName = other.instanceName;
this.tnsAlias = other.tnsAlias;
this.tnsAdmin = other.tnsAdmin;
this.ssl = other.ssl;
this.pipeliningLimit = other.pipeliningLimit;
}
public OracleConnectOptions(SqlConnectOptions options) {
super(options);
if (options instanceof OracleConnectOptions) {
OracleConnectOptions opts = (OracleConnectOptions) options;
copyFields(opts);
}
}
public OracleConnectOptions(JsonObject json) {
super(json);
OracleConnectOptionsConverter.fromJson(json, this);
}
/**
* Provide a {@link OracleConnectOptions} configured from a connection URI.
*
* @param connectionUri the connection URI to configure from
* @return a {@link OracleConnectOptions} parsed from the connection URI
* @throws IllegalArgumentException when the {@code connectionUri} is in an invalid format
*/
public static OracleConnectOptions fromUri(String connectionUri) throws IllegalArgumentException {
JsonObject parsedConfiguration = OracleConnectionUriParser.parse(connectionUri);
return new OracleConnectOptions(parsedConfiguration);
}
// Oracle-specific options
/**
* @return the Oracle service identifier (SID)
*/
public String getServiceId() {
return serviceId;
}
/**
* Set the Oracle service identifier (SID).
* If set, the client will build an Oracle connection URL using SID instead of the EZConnect format.
*
* @param serviceId the service identifier
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setServiceId(String serviceId) {
this.serviceId = serviceId;
return this;
}
/**
* @return the Oracle service name
*/
public String getServiceName() {
return serviceName;
}
/**
* Set the Oracle service name.
* If set, the client will build an Oracle connection URL in the EZConnect format.
*
* @param serviceName the Oracle service name
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setServiceName(String serviceName) {
this.serviceName = serviceName;
return this;
}
/**
* @return the server connection mode
*/
public ServerMode getServerMode() {
return serverMode;
}
/**
* Set the server connection mode.
*
* @param serverMode the connection mode
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setServerMode(ServerMode serverMode) {
this.serverMode = serverMode;
return this;
}
/**
* @return the Oracle instance name
*/
public String getInstanceName() {
return instanceName;
}
/**
* Set the Oracle instance name.
*
* @param instanceName the instance name
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setInstanceName(String instanceName) {
this.instanceName = instanceName;
return this;
}
/**
* @return name of the alias configured in the {@code tnsnames.ora} file
*/
public String getTnsAlias() {
return tnsAlias;
}
/**
* Set the name of an alias configured in the {@code tnsnames.ora} file.
*
* @param tnsAlias the instance name
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setTnsAlias(String tnsAlias) {
this.tnsAlias = tnsAlias;
return this;
}
/**
* @return the path of the directory that contains the {@code tnsnames.ora} file
*/
public String getTnsAdmin() {
return tnsAdmin;
}
/**
* Set the path of the directory that contains the {@code tnsnames.ora} file.
*
* @param tnsAdmin path of the directory
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setTnsAdmin(String tnsAdmin) {
this.tnsAdmin = tnsAdmin;
return this;
}
/**
* Get the pipelining limit count.
*
* @return the pipelining count
*/
public int getPipeliningLimit() {
return pipeliningLimit;
}
/**
* Set the pipelining limit count.
*
* @param pipeliningLimit the count to configure
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setPipeliningLimit(int pipeliningLimit) {
if (pipeliningLimit < 1) {
throw new IllegalArgumentException("pipelining limit can not be less than 1");
}
this.pipeliningLimit = pipeliningLimit;
return this;
}
// Non-specific options
@Override
public String getHost() {
return super.getHost();
}
@Override
public OracleConnectOptions setHost(String host) {
return (OracleConnectOptions) super.setHost(host);
}
@Override
public int getPort() {
return super.getPort();
}
@Override
public OracleConnectOptions setPort(int port) {
return (OracleConnectOptions) super.setPort(port);
}
@Override
public String getUser() {
return super.getUser();
}
@Override
public OracleConnectOptions setUser(String user) {
return (OracleConnectOptions) super.setUser(user);
}
@Override
public String getPassword() {
return super.getPassword();
}
@Override
public OracleConnectOptions setPassword(String password) {
return (OracleConnectOptions) super.setPassword(password);
}
@Override
public String getDatabase() {
return super.getDatabase();
}
/**
* Set the database name.
* If set, the client will build an Oracle connection URL in the EZConnect format using the {@code database} value as service name.
*
* @param database the database name to specify
* @return a reference to this, so the API can be used fluently
*/
@Override
public OracleConnectOptions setDatabase(String database) {
return (OracleConnectOptions) super.setDatabase(database);
}
@Override
public boolean getCachePreparedStatements() {
return super.getCachePreparedStatements();
}
@Override
public OracleConnectOptions setCachePreparedStatements(boolean cachePreparedStatements) {
return (OracleConnectOptions) super.setCachePreparedStatements(cachePreparedStatements);
}
@Override
public int getPreparedStatementCacheMaxSize() {
return super.getPreparedStatementCacheMaxSize();
}
@Override
public OracleConnectOptions setPreparedStatementCacheMaxSize(int preparedStatementCacheMaxSize) {
return (OracleConnectOptions) super.setPreparedStatementCacheMaxSize(preparedStatementCacheMaxSize);
}
@Override
public Predicate<String> getPreparedStatementCacheSqlFilter() {
return super.getPreparedStatementCacheSqlFilter();
}
@GenIgnore
@Override
public OracleConnectOptions setPreparedStatementCacheSqlFilter(Predicate<String> predicate) {
return (OracleConnectOptions) super.setPreparedStatementCacheSqlFilter(predicate);
}
@Override
public OracleConnectOptions setPreparedStatementCacheSqlLimit(int preparedStatementCacheSqlLimit) {
return (OracleConnectOptions) super.setPreparedStatementCacheSqlLimit(preparedStatementCacheSqlLimit);
}
@Override
public Map<String, String> getProperties() {
return super.getProperties();
}
@Override
public OracleConnectOptions setProperties(Map<String, String> properties) {
return (OracleConnectOptions) super.setProperties(properties);
}
@GenIgnore
@Override
public OracleConnectOptions addProperty(String key, String value) {
return (OracleConnectOptions) super.addProperty(key, value);
}
@Override
public SocketAddress getSocketAddress() {
return super.getSocketAddress();
}
@Override
public TracingPolicy getTracingPolicy() {
return super.getTracingPolicy();
}
@Override
public OracleConnectOptions setTracingPolicy(TracingPolicy tracingPolicy) {
return (OracleConnectOptions) super.setTracingPolicy(tracingPolicy);
}
/**
*
* @return is SSL/TLS enabled?
*/
public boolean isSsl() {
return ssl;
}
/**
* Set whether SSL/TLS is enabled
*
* @param ssl true if enabled
* @return a reference to this, so the API can be used fluently
*/
public OracleConnectOptions setSsl(boolean ssl) {
this.ssl = ssl;
return this;
}
@Override
public JsonObject toJson() {
JsonObject json = super.toJson();
OracleConnectOptionsConverter.toJson(this, json);
return json;
}
@Override
protected void init() {
this.setHost(DEFAULT_HOST);
this.setPort(DEFAULT_PORT);
this.setUser(DEFAULT_USER);
this.setPassword(DEFAULT_PASSWORD);
this.setDatabase(DEFAULT_DATABASE);
}
@Override
public OracleConnectOptions merge(JsonObject other) {
JsonObject json = toJson();
json.mergeIn(other);
return new OracleConnectOptions(json);
}
}