Skip to content

Commit f9f9879

Browse files
Document tnsnames alias and update example
1 parent fbee9ca commit f9f9879

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

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

2424
import io.r2dbc.spi.ConnectionFactories;
2525
import io.r2dbc.spi.ConnectionFactoryOptions;
26-
import io.r2dbc.spi.Option;
26+
import oracle.r2dbc.OracleR2dbcOptions;
2727
import reactor.core.publisher.Mono;
2828

2929
import static oracle.r2dbc.samples.DatabaseConfig.HOST;
@@ -47,15 +47,16 @@ public class DescriptorURL {
4747

4848
/**
4949
* A TNS descriptor specifying the HOST, PORT, and SERVICE_NAME read from
50-
* {@link DatabaseConfig}.
50+
* {@link DatabaseConfig}. These values can be configured in a
51+
* config.properties file of the current directory.
5152
*/
5253
private static final String DESCRIPTOR = "(DESCRIPTION=" +
5354
"(ADDRESS=(HOST="+HOST+")(PORT="+PORT+")(PROTOCOL=tcp))" +
5455
"(CONNECT_DATA=(SERVICE_NAME="+SERVICE_NAME+")))";
5556

5657
public static void main(String[] args) {
5758
// A descriptor may appear in the query section of an R2DBC URL:
58-
String r2dbcUrl = "r2dbc:oracle://?oracleNetDescriptor="+DESCRIPTOR;
59+
String r2dbcUrl = "r2dbc:oracle://?oracle.r2dbc.descriptor="+DESCRIPTOR;
5960
Mono.from(ConnectionFactories.get(ConnectionFactoryOptions.parse(r2dbcUrl)
6061
.mutate()
6162
.option(ConnectionFactoryOptions.USER, USER)
@@ -67,15 +68,15 @@ public static void main(String[] args) {
6768
"SELECT 'Connected with TNS descriptor' FROM sys.dual")
6869
.execute())
6970
.flatMapMany(result ->
70-
result.map((row, metadata) -> row.get(0, String.class)))
71+
result.map(row -> row.get(0, String.class)))
7172
.concatWith(Mono.from(connection.close()).cast(String.class)))
7273
.toStream()
7374
.forEach(System.out::println);
7475

7576
// A descriptor may also be specified as an Option
7677
Mono.from(ConnectionFactories.get(ConnectionFactoryOptions.builder()
7778
.option(ConnectionFactoryOptions.DRIVER, "oracle")
78-
.option(Option.valueOf("oracleNetDescriptor"), DESCRIPTOR)
79+
.option(OracleR2dbcOptions.DESCRIPTOR, DESCRIPTOR)
7980
.option(ConnectionFactoryOptions.USER, USER)
8081
.option(ConnectionFactoryOptions.PASSWORD, PASSWORD)
8182
.build())

src/main/java/oracle/r2dbc/OracleR2dbcOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ private OracleR2dbcOptions() {}
3535

3636
/**
3737
* Extended {@code Option} that specifies an Oracle Net Connect Descriptor
38-
* of the form "(DESCRIPTION=...)"
38+
* of the form "(DESCRIPTION=...)". If {@link #TNS_ADMIN} is specified,
39+
* then the value of this {@code Option} may be set to a tnsnames.ora
40+
* alias.
3941
*/
4042
public static final Option<CharSequence> DESCRIPTOR =
4143
Option.valueOf("oracle.r2dbc.descriptor");

0 commit comments

Comments
 (0)