Skip to content

Commit d61d8c4

Browse files
Merge pull request #51 from oracle/50-Executor-Option
Executor Option
2 parents 62c6d21 + f9f9879 commit d61d8c4

File tree

7 files changed

+374
-91
lines changed

7 files changed

+374
-91
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())
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
/*
2+
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
3+
4+
This software is dual-licensed to you under the Universal Permissive License
5+
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
6+
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
either license.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
*/
21+
package oracle.r2dbc;
22+
23+
import io.r2dbc.spi.Option;
24+
import oracle.jdbc.OracleConnection;
25+
26+
import java.util.concurrent.Executor;
27+
import java.util.concurrent.ForkJoinPool;
28+
29+
/**
30+
* Extended {@link Option}s supported by the Oracle R2DBC Driver.
31+
*/
32+
public final class OracleR2dbcOptions {
33+
34+
private OracleR2dbcOptions() {}
35+
36+
/**
37+
* Extended {@code Option} that specifies an Oracle Net Connect Descriptor
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.
41+
*/
42+
public static final Option<CharSequence> DESCRIPTOR =
43+
Option.valueOf("oracle.r2dbc.descriptor");
44+
45+
/**
46+
* Extended {@code Option} that specifies an {@link Executor} for executing
47+
* asynchronous tasks. This {@code Option} can not be configured in the
48+
* query section of an R2DBC URL, it must be configured programmatically,
49+
* as in:
50+
* <pre>
51+
* Executor myExecutor = getMyExecutor();
52+
*
53+
* ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
54+
* .option(ConnectionFactoryOptions.DRIVER, "oracle")
55+
* .option(OracleR2dbcOptions.EXECUTOR, myExecutor)
56+
* ...
57+
* .build();
58+
* </pre>
59+
* If this option is not configured, then Oracle R2DBC will use
60+
* {@code ForkJoinPool}'s
61+
* {@linkplain ForkJoinPool#commonPool() common pool} by default.
62+
*/
63+
public static final Option<Executor> EXECUTOR =
64+
Option.valueOf("oracle.r2dbc.executor");
65+
66+
/**
67+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
68+
* {@link OracleConnection#CONNECTION_PROPERTY_TNS_ADMIN}
69+
*/
70+
public static final Option<CharSequence> TNS_ADMIN =
71+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_TNS_ADMIN);
72+
73+
/**
74+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
75+
* {@link OracleConnection#CONNECTION_PROPERTY_WALLET_LOCATION}
76+
*/
77+
public static final Option<CharSequence> TLS_WALLET_LOCATION =
78+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_WALLET_LOCATION);
79+
80+
/**
81+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
82+
* {@link OracleConnection#CONNECTION_PROPERTY_WALLET_PASSWORD}
83+
*/
84+
public static final Option<CharSequence> TLS_WALLET_PASSWORD =
85+
Option.sensitiveValueOf(OracleConnection.CONNECTION_PROPERTY_WALLET_PASSWORD);
86+
87+
/**
88+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
89+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTORE}
90+
*/
91+
public static final Option<CharSequence> TLS_KEYSTORE =
92+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTORE);
93+
94+
/**
95+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
96+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTORETYPE}
97+
*/
98+
public static final Option<CharSequence> TLS_KEYSTORE_TYPE =
99+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTORETYPE);
100+
101+
/**
102+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
103+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTOREPASSWORD}
104+
*/
105+
public static final Option<CharSequence> TLS_KEYSTORE_PASSWORD =
106+
Option.sensitiveValueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_KEYSTOREPASSWORD);
107+
108+
/**
109+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
110+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTORE}
111+
*/
112+
public static final Option<CharSequence> TLS_TRUSTSTORE =
113+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTORE);
114+
115+
/**
116+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
117+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTORETYPE}
118+
*/
119+
public static final Option<CharSequence> TLS_TRUSTSTORE_TYPE =
120+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTORETYPE);
121+
122+
/**
123+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
124+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTOREPASSWORD}
125+
*/
126+
public static final Option<CharSequence> TLS_TRUSTSTORE_PASSWORD =
127+
Option.sensitiveValueOf(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTOREPASSWORD);
128+
129+
/**
130+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
131+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_NET_AUTHENTICATION_SERVICES}
132+
*/
133+
public static final Option<CharSequence> AUTHENTICATION_SERVICES =
134+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_NET_AUTHENTICATION_SERVICES);
135+
136+
/**
137+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
138+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_CERTIFICATE_ALIAS}
139+
*/
140+
public static final Option<CharSequence> TLS_CERTIFICATE_ALIAS =
141+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_CERTIFICATE_ALIAS);
142+
143+
/**
144+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
145+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_SERVER_DN_MATCH}
146+
*/
147+
public static final Option<CharSequence> TLS_SERVER_DN_MATCH =
148+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_SERVER_DN_MATCH);
149+
150+
/**
151+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
152+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_SERVER_CERT_DN}
153+
*/
154+
public static final Option<CharSequence> TLS_SERVER_CERT_DN =
155+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_SERVER_CERT_DN);
156+
157+
/**
158+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
159+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_VERSION}
160+
*/
161+
public static final Option<CharSequence> TLS_VERSION =
162+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_VERSION);
163+
164+
/**
165+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
166+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_CIPHER_SUITES}
167+
*/
168+
public static final Option<CharSequence> TLS_CIPHER_SUITES =
169+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_CIPHER_SUITES);
170+
171+
/**
172+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
173+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_KEYMANAGERFACTORY_ALGORITHM}
174+
*/
175+
public static final Option<CharSequence> TLS_KEYMANAGERFACTORY_ALGORITHM =
176+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_KEYMANAGERFACTORY_ALGORITHM);
177+
178+
/**
179+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
180+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_SSL_TRUSTMANAGERFACTORY_ALGORITHM}
181+
*/
182+
public static final Option<CharSequence> TLS_TRUSTMANAGERFACTORY_ALGORITHM =
183+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_SSL_TRUSTMANAGERFACTORY_ALGORITHM);
184+
185+
/**
186+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
187+
* {@link OracleConnection#CONNECTION_PROPERTY_SSL_CONTEXT_PROTOCOL}
188+
*/
189+
public static final Option<CharSequence> SSL_CONTEXT_PROTOCOL =
190+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_SSL_CONTEXT_PROTOCOL);
191+
192+
/**
193+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
194+
* {@link OracleConnection#CONNECTION_PROPERTY_FAN_ENABLED}
195+
*/
196+
public static final Option<CharSequence> FAN_ENABLED =
197+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_FAN_ENABLED);
198+
199+
/**
200+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
201+
* {@link OracleConnection#CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE}
202+
*/
203+
public static final Option<CharSequence> IMPLICIT_STATEMENT_CACHE_SIZE =
204+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_IMPLICIT_STATEMENT_CACHE_SIZE);
205+
206+
/**
207+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
208+
* {@link OracleConnection#CONNECTION_PROPERTY_DEFAULT_LOB_PREFETCH_SIZE}
209+
*/
210+
public static final Option<CharSequence> DEFAULT_LOB_PREFETCH_SIZE =
211+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_DEFAULT_LOB_PREFETCH_SIZE);
212+
213+
/**
214+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
215+
* {@link OracleConnection#CONNECTION_PROPERTY_THIN_NET_DISABLE_OUT_OF_BAND_BREAK}
216+
*/
217+
public static final Option<CharSequence> DISABLE_OUT_OF_BAND_BREAK =
218+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_THIN_NET_DISABLE_OUT_OF_BAND_BREAK);
219+
220+
/**
221+
* Configures the Oracle JDBC Connection used by Oracle R2DBC as specified by:
222+
* {@link OracleConnection#CONNECTION_PROPERTY_ENABLE_QUERY_RESULT_CACHE}
223+
*/
224+
public static final Option<CharSequence> ENABLE_QUERY_RESULT_CACHE =
225+
Option.valueOf(OracleConnection.CONNECTION_PROPERTY_ENABLE_QUERY_RESULT_CACHE);
226+
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
import io.r2dbc.spi.IsolationLevel;
2929
import io.r2dbc.spi.R2dbcException;
3030
import io.r2dbc.spi.Statement;
31+
import oracle.r2dbc.OracleR2dbcOptions;
3132
import org.reactivestreams.Publisher;
3233
import reactor.core.publisher.Mono;
3334

3435
import javax.sql.DataSource;
3536
import java.time.Duration;
3637
import java.util.Optional;
38+
import java.util.concurrent.Executor;
39+
import java.util.concurrent.ForkJoinPool;
3740

3841
/**
3942
* <p>
@@ -102,6 +105,12 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {
102105
/** JDBC data source that this factory uses to open connections */
103106
private final DataSource dataSource;
104107

108+
/**
109+
* Executor configured by {@link oracle.r2dbc.OracleR2dbcOptions#EXECUTOR},
110+
* or a default one if none was configured.
111+
*/
112+
private final Executor executor;
113+
105114
/**
106115
* <p>
107116
* Timeout applied to the execution of {@link Statement}s created by
@@ -189,6 +198,19 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {
189198
: Duration.parse(timeout.toString()))
190199
.orElse(Duration.ZERO);
191200

201+
Object executor = options.getValue(OracleR2dbcOptions.EXECUTOR);
202+
if (executor == null) {
203+
this.executor = ForkJoinPool.commonPool();
204+
}
205+
else if (executor instanceof Executor) {
206+
this.executor = (Executor) executor;
207+
}
208+
else {
209+
throw new IllegalArgumentException(
210+
"Value of " + OracleR2dbcOptions.EXECUTOR
211+
+ " is not an instance of Executor: " + executor.getClass());
212+
}
213+
192214
}
193215

194216
/**
@@ -221,7 +243,7 @@ public Publisher<Connection> create() {
221243
// to a particular connection.
222244
ReactiveJdbcAdapter adapter = ReactiveJdbcAdapter.getOracleAdapter();
223245

224-
return Mono.fromDirect(adapter.publishConnection(dataSource))
246+
return Mono.fromDirect(adapter.publishConnection(dataSource, executor))
225247
.flatMap(conn -> {
226248
OracleConnectionImpl connection =
227249
new OracleConnectionImpl(conn, adapter);

0 commit comments

Comments
 (0)