Skip to content

Commit a6a2c01

Browse files
authored
Oracle URL parsing enhancements (eclipse-vertx#1153)
* Add missing Oracle EZConnect properties to OracleConnectOptions Signed-off-by: Thomas Segismont <tsegismont@gmail.com> * Refactored OracleConnectionUriParser and OracleDatabaseHelper Now they both support EZConnect url format. Also, connection properties decoding has been implemented. Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent 8ade82e commit a6a2c01

File tree

6 files changed

+652
-106
lines changed

6 files changed

+652
-106
lines changed

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

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public static OracleConnectOptions wrap(SqlConnectOptions options) {
3434
}
3535
}
3636

37+
public static final String DEFAULT_HOST = "localhost";
38+
public static final int DEFAULT_PORT = 1521;
39+
public static final String DEFAULT_USER = "";
40+
public static final String DEFAULT_PASSWORD = "";
41+
public static final String DEFAULT_DATABASE = "";
42+
43+
private String serviceId;
44+
private String serviceName;
45+
private ServerMode serverMode;
46+
private String instanceName;
3747
// Support TNS_ADMIN (tnsnames.ora, ojdbc.properties).
3848
private String tnsAdmin;
3949

@@ -42,6 +52,10 @@ public OracleConnectOptions() {
4252

4353
public OracleConnectOptions(OracleConnectOptions other) {
4454
super(other);
55+
this.serviceId = other.serviceId;
56+
this.serviceName = other.serviceName;
57+
this.serverMode = other.serverMode;
58+
this.instanceName = other.instanceName;
4559
this.tnsAdmin = other.tnsAdmin;
4660
}
4761

@@ -68,6 +82,80 @@ public static OracleConnectOptions fromUri(String connectionUri) throws IllegalA
6882

6983
// Oracle-specific options
7084

85+
/**
86+
* @return the Oracle service identifier (SID)
87+
*/
88+
public String getServiceId() {
89+
return serviceId;
90+
}
91+
92+
/**
93+
* Set the Oracle service identifier (SID).
94+
* If set, the client will build an Oracle connection URL using SID instead of the EZConnect format.
95+
*
96+
* @param serviceId the service identifier
97+
* @return a reference to this, so the API can be used fluently
98+
*/
99+
public OracleConnectOptions setServiceId(String serviceId) {
100+
this.serviceId = serviceId;
101+
return this;
102+
}
103+
104+
/**
105+
* @return the Oracle service name
106+
*/
107+
public String getServiceName() {
108+
return serviceName;
109+
}
110+
111+
/**
112+
* Set the Oracle service name.
113+
* If set, the client will build an Oracle connection URL in the EZConnect format.
114+
*
115+
* @param serviceName the Oracle service name
116+
* @return a reference to this, so the API can be used fluently
117+
*/
118+
public OracleConnectOptions setServiceName(String serviceName) {
119+
this.serviceName = serviceName;
120+
return this;
121+
}
122+
123+
/**
124+
* @return the server connection mode
125+
*/
126+
public ServerMode getServerMode() {
127+
return serverMode;
128+
}
129+
130+
/**
131+
* Set the server connection mode.
132+
*
133+
* @param serverMode the connection mode
134+
* @return a reference to this, so the API can be used fluently
135+
*/
136+
public OracleConnectOptions setServerMode(ServerMode serverMode) {
137+
this.serverMode = serverMode;
138+
return this;
139+
}
140+
141+
/**
142+
* @return the Oracle instance name
143+
*/
144+
public String getInstanceName() {
145+
return instanceName;
146+
}
147+
148+
/**
149+
* Set the Oracle instance name.
150+
*
151+
* @param instanceName the instance name
152+
* @return a reference to this, so the API can be used fluently
153+
*/
154+
public OracleConnectOptions setInstanceName(String instanceName) {
155+
this.instanceName = instanceName;
156+
return this;
157+
}
158+
71159
public String getTnsAdmin() {
72160
return tnsAdmin;
73161
}
@@ -124,6 +212,13 @@ public String getDatabase() {
124212
return super.getDatabase();
125213
}
126214

215+
/**
216+
* Set the database name.
217+
* If set, the client will build an Oracle connection URL in the EZConnect format using the {@code database} value as service name.
218+
*
219+
* @param database the database name to specify
220+
* @return a reference to this, so the API can be used fluently
221+
*/
127222
@Override
128223
public OracleConnectOptions setDatabase(String database) {
129224
return (OracleConnectOptions) super.setDatabase(database);
@@ -201,6 +296,15 @@ public JsonObject toJson() {
201296
return json;
202297
}
203298

299+
@Override
300+
protected void init() {
301+
this.setHost(DEFAULT_HOST);
302+
this.setPort(DEFAULT_PORT);
303+
this.setUser(DEFAULT_USER);
304+
this.setPassword(DEFAULT_PASSWORD);
305+
this.setDatabase(DEFAULT_DATABASE);
306+
}
307+
204308
@Override
205309
public OracleConnectOptions merge(JsonObject other) {
206310
JsonObject json = toJson();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2011-2022 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
12+
package io.vertx.oracleclient;
13+
14+
import io.vertx.codegen.annotations.VertxGen;
15+
16+
/**
17+
* Describes the server connection mode.
18+
*/
19+
@VertxGen
20+
public enum ServerMode {
21+
22+
DEDICATED("dedicated"), SHARED("shared");
23+
24+
private final String mode;
25+
26+
ServerMode(String mode) {
27+
this.mode = mode;
28+
}
29+
30+
public static ServerMode of(String mode) {
31+
return DEDICATED.mode.equalsIgnoreCase(mode) ? DEDICATED : SHARED.mode.equalsIgnoreCase(mode) ? SHARED : null;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return mode;
37+
}
38+
}

0 commit comments

Comments
 (0)