Skip to content

Commit dca2ece

Browse files
Merge branch 'main' of https://github.com/oracle/oracle-r2dbc into 1-1-0-dep-update
2 parents e0a46e3 + 4b68ec7 commit dca2ece

25 files changed

+2239
-667
lines changed

.github/workflows/startup/01_createUser.sql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
-- v$transaction (to verify if TransactionDefinitions are applied).
3737
-- v$session (to verify if VSESSION_* Options are applied).
3838
ALTER SESSION SET CONTAINER=xepdb1;
39-
CREATE ROLE r2dbc_test_user;
40-
GRANT SELECT ON v_$open_cursor TO r2dbc_test_user;
41-
GRANT SELECT ON v_$transaction TO r2dbc_test_user;
42-
GRANT SELECT ON v_$session TO r2dbc_test_user;
39+
CREATE ROLE r2dbc_test_role;
40+
GRANT SELECT ON v_$open_cursor TO r2dbc_test_role;
41+
GRANT SELECT ON v_$transaction TO r2dbc_test_role;
42+
GRANT SELECT ON v_$session TO r2dbc_test_role;
43+
GRANT CREATE VIEW TO r2dbc_test_role;
4344

4445
CREATE USER test IDENTIFIED BY test;
45-
GRANT connect, resource, unlimited tablespace, r2dbc_test_user TO test;
46+
GRANT connect, resource, unlimited tablespace, r2dbc_test_role TO test;
4647
ALTER USER test DEFAULT TABLESPACE users;
4748
ALTER USER test TEMPORARY TABLESPACE temp;

.github/workflows/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ echo "HOST=localhost" >> src/test/resources/config.properties
8181
echo "PORT=1521" >> src/test/resources/config.properties
8282
echo "USER=test" >> src/test/resources/config.properties
8383
echo "PASSWORD=test" >> src/test/resources/config.properties
84-
echo "CONNECT_TIMEOUT=60" >> src/test/resources/config.properties
85-
echo "SQL_TIMEOUT=60" >> src/test/resources/config.properties
84+
echo "CONNECT_TIMEOUT=120" >> src/test/resources/config.properties
85+
echo "SQL_TIMEOUT=120" >> src/test/resources/config.properties
8686
mvn clean compile test

README.md

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,22 @@ are supported by Oracle R2DBC:
191191
- `HOST`
192192
- `PORT`
193193
- `DATABASE`
194+
- The database option is interpreted as the
195+
[service name](https://docs.oracle.com/en/database/oracle/oracle-database/21/netag/identifying-and-accessing-database.html#GUID-153861C1-16AD-41EC-A179-074146B722E6)
196+
of an Oracle Database instance. _System Identifiers (SID) are not recognized_.
194197
- `USER`
195198
- `PASSWORD`
196199
- `SSL`
197200
- `CONNECT_TIMEOUT`
198201
- `STATEMENT_TIMEOUT`.
199-
200-
> Oracle R2DBC interprets the `DATABASE` option as the
201-
> [service name](https://docs.oracle.com/en/database/oracle/oracle-database/21/netag/identifying-and-accessing-database.html#GUID-153861C1-16AD-41EC-A179-074146B722E6)
202-
> of an Oracle Database instance. _System Identifiers (SID) are not recognized_.
202+
- `PROTOCOL`
203+
- (For inclusion in the next release) Accepted protocol values are "tcps", "ldap", and "ldaps"
203204

204205
#### Support for Extended R2DBC Options
205206
Oracle R2DBC extends the standard set of R2DBC options to offer functionality
206207
that is specific to Oracle Database and the Oracle JDBC Driver. Extended options
207208
are declared in the
208-
[OracleR2dbcOptions](src/main/java/oracle/r2dbc/OracleR2dbcOptions.java)
209-
class.
209+
[OracleR2dbcOptions](src/main/java/oracle/r2dbc/OracleR2dbcOptions.java) class.
210210

211211
#### Configuring an Oracle Net Descriptor
212212
The `oracle.r2dbc.OracleR2dbcOptions.DESCRIPTOR` option may be used to configure
@@ -234,6 +234,22 @@ located:
234234
r2dbc:oracle://?oracle.r2dbc.descriptor=myAlias&TNS_ADMIN=/path/to/tnsnames/
235235
```
236236

237+
#### (For inclusion in the next release) Configuring an LDAP URL
238+
Use `ldap` or `ldaps` as the URL protocol to have an Oracle Net Descriptor
239+
retrieved from an LDAP server:
240+
```
241+
r2dbc:oracle:ldap://ldap.example.com:7777/sales,cn=OracleContext,dc=com
242+
r2dbc:oracle:ldaps://ldap.example.com:7778/sales,cn=OracleContext,dc=com
243+
```
244+
Use a space separated list of LDAP URIs for fail over and load balancing:
245+
```
246+
r2dbc:oracle:ldap://ldap1.example.com:7777/sales,cn=OracleContext,dc=com%20ldap://ldap2.example.com:7777/sales,cn=OracleContext,dc=com%20ldap://ldap3.example.com:7777/sales,cn=OracleContext,dc=com
247+
```
248+
> Space characters in a URL must be percent encoded as `%20`
249+
250+
An LDAP server request will **block a thread for network I/O** when Oracle R2DBC
251+
creates a new connection.
252+
237253
#### Configuring a java.util.concurrent.Executor
238254
The `oracle.r2dbc.OracleR2dbcOptions.EXECUTOR` option configures a
239255
`java.util.concurrent.Executor` for executing asynchronous callbacks. The
@@ -344,12 +360,32 @@ Oracle R2DBC's implementation of Publishers that emit multiple items will
344360
typically defer execution until a Subscriber signals demand, and not support
345361
multiple subscribers.
346362

347-
### Errors
363+
### Errors and Warnings
348364
Oracle R2DBC creates R2dbcExceptions having the same ORA-XXXXX error codes
349-
used by Oracle Database and Oracle JDBC.
365+
used by Oracle Database and Oracle JDBC. The
366+
[Database Error Messages](https://docs.oracle.com/en/database/oracle/oracle-database/21/errmg/ORA-00000.html#GUID-27437B7F-F0C3-4F1F-9C6E-6780706FB0F6)
367+
document provides a reference for all ORA-XXXXX error codes.
350368

351-
A reference for the ORA-XXXXX error codes can be found
352-
[here](https://docs.oracle.com/en/database/oracle/oracle-database/21/errmg/ORA-00000.html#GUID-27437B7F-F0C3-4F1F-9C6E-6780706FB0F6)
369+
Warning messages from Oracle Database are emitted as
370+
`oracle.r2dbc.OracleR2dbcWarning` segments. These segments may be consumed using
371+
`Result.flatMap(Function)`:
372+
```java
373+
result.flatMap(segment -> {
374+
if (segment instanceof OracleR2dbcWarning) {
375+
logWarning(((OracleR2dbcWarning)segment).getMessage());
376+
return emptyPublisher();
377+
}
378+
else if (segment instanceof Result.Message){
379+
... handle an error ...
380+
}
381+
else {
382+
... handle other segment types ...
383+
}
384+
})
385+
```
386+
Unlike the errors of standard `Result.Message` segments, if a warning is not
387+
consumed by `flatMap`, then it will be silently discarded when a `Result` is
388+
consumed using the `map` or `getRowsUpdated` methods.
353389

354390
### Transactions
355391
Oracle R2DBC uses READ COMMITTED as the default transaction isolation level.
@@ -488,12 +524,13 @@ for the out parameters is emitted last, after the `Result` for each cursor.
488524
Oracle R2DBC supports type mappings between Java and SQL for non-standard data
489525
types of Oracle Database.
490526

491-
| Oracle SQL Type | Java Type |
492-
|---------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
493-
| [JSON](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-E441F541-BA31-4E8C-B7B4-D2FB8C42D0DF) | `javax.json.JsonObject` or `oracle.sql.json.OracleJsonObject` |
494-
| [DATE](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-5405B652-C30E-4F4F-9D33-9A4CB2110F1B) | `java.time.LocalDateTime` |
495-
| [INTERVAL DAY TO SECOND](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-B03DD036-66F8-4BD3-AF26-6D4433EBEC1C) | `java.time.Duration` |
496-
| [INTERVAL YEAR TO MONTH](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-ED59E1B3-BA8D-4711-B5C8-B0199C676A95) | `java.time.Period` |
527+
| Oracle SQL Type | Java Type |
528+
|---------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
529+
| [JSON](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-E441F541-BA31-4E8C-B7B4-D2FB8C42D0DF) | `javax.json.JsonObject` or `oracle.sql.json.OracleJsonObject` |
530+
| [DATE](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-5405B652-C30E-4F4F-9D33-9A4CB2110F1B) | `java.time.LocalDateTime` |
531+
| [INTERVAL DAY TO SECOND](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-B03DD036-66F8-4BD3-AF26-6D4433EBEC1C) | `java.time.Duration` |
532+
| [INTERVAL YEAR TO MONTH](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-ED59E1B3-BA8D-4711-B5C8-B0199C676A95) | `java.time.Period` |
533+
| [SYS_REFCURSOR](https://docs.oracle.com/en/database/oracle/oracle-database/21/lnpls/static-sql.html#GUID-470A7A99-888A-46C2-BDAF-D4710E650F27) | `io.r2dbc.spi.Result` |
497534
> Unlike the standard SQL type named "DATE", the Oracle Database type named
498535
> "DATE" stores values for year, month, day, hour, minute, and second. The
499536
> standard SQL type only stores year, month, and day. LocalDateTime objects are able
@@ -533,6 +570,35 @@ prefetched entirely, a smaller prefetch size can be configured using the
533570
option, and the LOB can be consumed as a stream. By mapping LOB columns to
534571
`Blob` or `Clob` objects, the content can be consumed as a reactive stream.
535572

573+
### REF Cursors
574+
Use the `oracle.r2dbc.OracleR2dbcTypes.REF_CURSOR` type to bind `SYS_REFCURSOR` out
575+
parameters:
576+
```java
577+
Publisher<Result> executeProcedure(Connection connection) {
578+
connection.createStatement(
579+
"BEGIN example_procedure(:cursor_parameter); END;")
580+
.bind("cursor_parameter", Parameters.out(OracleR2dbcTypes.REF_CURSOR))
581+
.execute()
582+
}
583+
```
584+
A `SYS_REFCURSOR` out parameter can be mapped to an `io.r2dbc.spi.Result`:
585+
```java
586+
Publisher<Result> mapOutParametersResult(Result outParametersResult) {
587+
return outParametersResult.map(outParameters ->
588+
outParameters.get("cursor_parameter", Result.class));
589+
}
590+
```
591+
The rows of a `SYS_REFCURSOR` may be consumed from the `Result` it is
592+
mapped to:
593+
```java
594+
Publisher<ExampleObject> mapRefCursorRows(Result refCursorResult) {
595+
return refCursorResult.map(row ->
596+
new ExampleObject(
597+
row.get("id_column", Long.class),
598+
row.get("value_column", String.class)));
599+
}
600+
```
601+
536602
## Secure Programming Guidelines
537603
The following security related guidelines should be adhered to when programming
538604
with the Oracle R2DBC Driver.

pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@
8787
<arg>-Xlint:-processing</arg>
8888
<arg>-Xlint:-serial</arg>
8989
</compilerArgs>
90+
<!-- LDAP URL tests require the java.naming module -->
91+
<!-- Maven seems to ignore the forceJavacCompilerUse.
92+
This results in an error when passing the addModules option to
93+
the javax.tools API. For this reason, Oracle R2DBC's module-info is
94+
declaring a depency on the java.naming module.
95+
TODO: Figure out how to make maven compile tests correctly, and
96+
remove the java.naming depenency from Oracle R2DBC.
97+
<fork>true</fork>
98+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
99+
<testCompilerArgument>- -add-modules java.naming</testCompilerArgument>
100+
-->
90101
<showWarnings>true</showWarnings>
91102
<release>${java.version}</release>
92103
</configuration>
@@ -150,6 +161,7 @@
150161
<artifactId>maven-surefire-plugin</artifactId>
151162
<version>3.0.0-M5</version>
152163
<configuration>
164+
<!-- Include tests in the oracle.r2dbc.test package -->
153165
<includes>
154166
<include>**/*Test.java</include>
155167
<include>**/*TestKit.java</include>
@@ -283,7 +295,6 @@
283295
<scope>test</scope>
284296
</dependency>
285297
-->
286-
287298
</dependencies>
288299

289300
<profiles>

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
with oracle.r2dbc.impl.OracleConnectionFactoryProviderImpl;
3131

3232
requires java.sql;
33+
requires java.naming;
3334
requires com.oracle.database.jdbc;
3435
requires reactor.core;
3536
requires transitive org.reactivestreams;

0 commit comments

Comments
 (0)