Skip to content

Commit 527b7e1

Browse files
Merge pull request #23 from oracle/descriptor-option
Add oracle-net-descriptor option
2 parents e7189e4 + f522a36 commit 527b7e1

File tree

8 files changed

+241
-108
lines changed

8 files changed

+241
-108
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ Options. For Options having any of the following names, a CharSequence value may
157157
- [oracle.net.ssl_context_protocol](https://docs.oracle.com/en/database/oracle/oracle-database/21/jajdb/oracle/jdbc/OracleConnection.html?is-external=true#CONNECTION_PROPERTY_SSL_CONTEXT_PROTOCOL)
158158
- [oracle.jdbc.fanEnabled](https://docs.oracle.com/en/database/oracle/oracle-database/21/jajdb/oracle/jdbc/OracleConnection.html?is-external=true#CONNECTION_PROPERTY_FAN_ENABLED)
159159
- [oracle.jdbc.implicitStatementCacheSize](https://docs.oracle.com/en/database/oracle/oracle-database/21/jajdb/oracle/jdbc/OracleConnection.html?is-external=true#CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE)
160-
- Descriptor URLs of the form ```(DESCRIPTION=...)``` may be specified in a tnsnames.ora file.
161-
- The directory containing the tnsnames.ora file may be specified as an ```Option``` having the name "TNS_ADMIN"
162-
- An alias of a tnsnames.ora file may be specified as the value of ```ConnectionFactoryOptions.HOST```.
163-
- An alias of a tnsnames.ora file may be specified with an R2DBC URL: ```r2dbc:oracle://my_alias?TNS_ADMIN=/path/to/tnsnames/```
160+
- Oracle Net Descriptors of the form ```(DESCRIPTION=...)``` may be specified as an io.r2dbc.spi.Option having the name `oracleNetDescriptor`.
161+
- If `oracleNetDescriptor` is specified, then it is invalid to specify any other options that might conflict with information in the descriptor, such as: `HOST`, `PORT`, `DATABASE`, and `SSL`.
162+
- The `oracleNetDescriptor` option may appear in the query section of an R2DBC URL: `r2dbc:oracle://?oracleNetDescriptor=(DESCRIPTION=...)`
163+
- The `oracleNetDescriptor` option may be provided programatically: `ConnectionFactoryOptions.builder().option(Option.valueOf("oracleNetDescriptor"), "(DESCRIPTION=...)")`
164+
- The `oracleNetDescriptor` option may be set as the alias of a descriptor in a tnsnames.ora file. The directory of tnsnames.ora may be set using an io.r2dbc.spi.Option having the name `TNS_ADMIN`: `r2dbc:oracle://?oracleNetDescriptor=myAlias&TNS_ADMIN=/path/to/tnsnames/`
164165

165166

166167
### Thread Safety and Parallel Execution

sample/example-config.properties

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# Values in this properties file configure how sample code connects to a
2-
# database.
3-
4-
# This file contains example values. Create a copy named config.properties in
1+
# Values in this properties file configure how sample code connects to a # database. # This file contains example values. Create a copy named config.properties in
52
# /sample and change the example values to actual values for your test database.
63

74
# Host name of a test database
@@ -11,7 +8,7 @@ HOST=db.host.example.com
118
PORT=1521
129

1310
# Service name of a test database
14-
SERVICE_NAME=db.service.name
11+
DATABASE=db.service.name
1512

1613
# User name authenticated by a test database
1714
USER=db_user

sample/src/main/java/oracle/r2dbc/samples/DatabaseConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class DatabaseConfig {
6161
static final int PORT = Integer.parseInt(CONFIG.getProperty("PORT"));
6262

6363
/** Service name of an Oracle Database */
64-
static final String SERVICE_NAME = CONFIG.getProperty("SERVICE_NAME");
64+
static final String SERVICE_NAME = CONFIG.getProperty("DATABASE");
6565

6666
/** User name that connects to an Oracle Database */
6767
static final String USER = CONFIG.getProperty("USER");

sample/src/main/java/oracle/r2dbc/samples/DescriptorURL.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import io.r2dbc.spi.ConnectionFactories;
2525
import io.r2dbc.spi.ConnectionFactoryOptions;
26+
import io.r2dbc.spi.Option;
2627
import reactor.core.publisher.Mono;
2728

2829
import static oracle.r2dbc.samples.DatabaseConfig.HOST;
@@ -53,8 +54,8 @@ public class DescriptorURL {
5354
"(CONNECT_DATA=(SERVICE_NAME="+SERVICE_NAME+")))";
5455

5556
public static void main(String[] args) {
56-
// A descriptor may appear in the host section of an R2DBC URL:
57-
String r2dbcUrl = "r2dbc:oracle://"+DESCRIPTOR;
57+
// A descriptor may appear in the query section of an R2DBC URL:
58+
String r2dbcUrl = "r2dbc:oracle://?oracleNetDescriptor="+DESCRIPTOR;
5859
Mono.from(ConnectionFactories.get(ConnectionFactoryOptions.parse(r2dbcUrl)
5960
.mutate()
6061
.option(ConnectionFactoryOptions.USER, USER)
@@ -71,11 +72,10 @@ public static void main(String[] args) {
7172
.toStream()
7273
.forEach(System.out::println);
7374

74-
// A descriptor may also be specified as the value of
75-
// ConnectionFactoryOptions.HOST
75+
// A descriptor may also be specified as an Option
7676
Mono.from(ConnectionFactories.get(ConnectionFactoryOptions.builder()
7777
.option(ConnectionFactoryOptions.DRIVER, "oracle")
78-
.option(ConnectionFactoryOptions.HOST, DESCRIPTOR)
78+
.option(Option.valueOf("oracleNetDescriptor"), DESCRIPTOR)
7979
.option(ConnectionFactoryOptions.USER, USER)
8080
.option(ConnectionFactoryOptions.PASSWORD, PASSWORD)
8181
.build())

src/main/java/oracle/r2dbc/impl/OracleConnectionFactoryImpl.java

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import reactor.core.publisher.Mono;
3232

3333
import javax.sql.DataSource;
34+
import java.time.Duration;
3435

3536
/**
3637
* <p>
@@ -48,21 +49,43 @@
4849
* </p>
4950
* <h3 id="required_options">Required Options</h3><p>
5051
* This implementation requires the following options for connection creation:
51-
* </p><ul>
52-
* <li>{@link ConnectionFactoryOptions#DRIVER}</li>
53-
* <li>{@link ConnectionFactoryOptions#HOST}</li>
54-
* </ul>
52+
* </p><dl>
53+
* <dt>{@link ConnectionFactoryOptions#DRIVER}</dt>
54+
* <dd>Must have the value "oracle"</dd>
55+
* <dt>{@link ConnectionFactoryOptions#HOST}</dt>
56+
* <dd>IP address or hostname of an Oracle Database</dd>
57+
* </dl>
5558
* <h3 id="supported_options">Supported Options</h3><p>
56-
* This implementation supports the following well known options for connection
57-
* creation:
58-
* </p><ul>
59-
* <li>{@link ConnectionFactoryOptions#PORT}</li>
60-
* <li>{@link ConnectionFactoryOptions#DATABASE}</li>
61-
* <li>{@link ConnectionFactoryOptions#USER}</li>
62-
* <li>{@link ConnectionFactoryOptions#PASSWORD}</li>
63-
* <li>{@link ConnectionFactoryOptions#CONNECT_TIMEOUT}</li>
64-
* <li>{@link ConnectionFactoryOptions#SSL}</li>
65-
* </ul>
59+
* This implementation supports the following options for connection creation:
60+
* </p><dl>
61+
* <dt>{@link ConnectionFactoryOptions#PORT}</dt>
62+
* <dd>Port number of an Oracle Database</dd>
63+
* <dt>{@link ConnectionFactoryOptions#DATABASE}</dt>
64+
* <dd>Service name (not an SID) of an Oracle Database</dd>
65+
* <dt>{@link ConnectionFactoryOptions#USER}</dt>
66+
* <dd>Name of an Oracle Database user</dd>
67+
* <dt>{@link ConnectionFactoryOptions#PASSWORD}</dt>
68+
* <dd>
69+
* Password of an Oracle Database user. The value may be an instance
70+
* of a mutable {@link CharSequence}, such {@link java.nio.CharBuffer},
71+
* that may be cleared after creating an instance of
72+
* {@code OracleConnectionFactoryImpl}.
73+
* </dd>
74+
* <dt>{@link ConnectionFactoryOptions#CONNECT_TIMEOUT}</dt>
75+
* <dd>
76+
* Maximum wait time when requesting a {@code Connection}. If the
77+
* duration expires, a {@code Connection} {@code Subscriber} receives
78+
* {@code onError} with an {@link io.r2dbc.spi.R2dbcTimeoutException}.
79+
* The duration is rounded up to the nearest whole second. The query
80+
* section of an R2DBC URL may provide a value in the format specified by
81+
* {@link Duration#parse(CharSequence)}.
82+
* </dd>
83+
* <dt>{@link ConnectionFactoryOptions#SSL}</dt>
84+
* <dd>
85+
* If set to {@code true}, the driver connects to Oracle Database using
86+
* TCPS (ie: SSL/TLS).
87+
* </dd>
88+
* </dl>
6689
* <h3 id="extended_options">Supported Options</h3><p>
6790
* This implementation supports extended options having the name of a
6891
* subset of Oracle JDBC connection properties. The list of supported
@@ -117,10 +140,16 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {
117140
* </p>
118141
*
119142
* @param options Options applied when opening a connection to a database.
143+
*
120144
* @throws IllegalArgumentException If the value of a required option is
121145
* null.
146+
*
122147
* @throws IllegalStateException If the value of a required option is not
123148
* specified.
149+
*
150+
* @throws IllegalArgumentException If the {@code oracleNetDescriptor}
151+
* {@code Option} is provided with any other options that might have
152+
* conflicting values, such as {@link ConnectionFactoryOptions#HOST}.
124153
*/
125154
OracleConnectionFactoryImpl(ConnectionFactoryOptions options) {
126155
OracleR2dbcExceptions.requireNonNull(options, "options is null.");
@@ -170,4 +199,4 @@ public Publisher<Connection> create() {
170199
public ConnectionFactoryMetadata getMetadata() {
171200
return () -> "Oracle Database";
172201
}
173-
}
202+
}

src/main/java/oracle/r2dbc/impl/OracleConnectionFactoryProviderImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.ServiceLoader;
2929

30+
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
3031
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireNonNull;
3132

3233
/**
@@ -83,8 +84,13 @@ public OracleConnectionFactoryProviderImpl() { }
8384
* {@code ConnectionFactory} that applies values specified by the {@code
8485
* options} parameter, when opening connections to an Oracle Database.
8586
* </p>
87+
*
8688
* @throws IllegalStateException If any option required by
8789
* {@link OracleConnectionFactoryImpl} is not specified by {@code options}.
90+
*
91+
* @throws IllegalArgumentException If the {@code oracleNetDescriptor}
92+
* {@code Option} is provided with any other options that might have
93+
* conflicting values, such as {@link ConnectionFactoryOptions#HOST}.
8894
*/
8995
@Override
9096
public ConnectionFactory create(ConnectionFactoryOptions options) {
@@ -103,8 +109,7 @@ public ConnectionFactory create(ConnectionFactoryOptions options) {
103109
@Override
104110
public boolean supports(ConnectionFactoryOptions options) {
105111
requireNonNull(options, "options must not be null.");
106-
return DRIVER_IDENTIFIER.equals(
107-
options.getValue(ConnectionFactoryOptions.DRIVER));
112+
return DRIVER_IDENTIFIER.equals(options.getValue(DRIVER));
108113
}
109114

110115
/**
@@ -119,4 +124,4 @@ public String getDriver() {
119124
return DRIVER_IDENTIFIER;
120125
}
121126

122-
}
127+
}

0 commit comments

Comments
 (0)