Skip to content

Commit a003a2d

Browse files
Guard JDBC Connection with AsyncLock
1 parent 30576c1 commit a003a2d

File tree

4 files changed

+610
-38
lines changed

4 files changed

+610
-38
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@
9999
*/
100100
final class OracleConnectionFactoryImpl implements ConnectionFactory {
101101

102-
/** Adapts Oracle JDBC Driver APIs into Reactive Streams APIs */
103-
private final ReactiveJdbcAdapter adapter;
104-
105102
/** JDBC data source that this factory uses to open connections */
106103
private final DataSource dataSource;
107104

@@ -173,8 +170,8 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {
173170
*/
174171
OracleConnectionFactoryImpl(ConnectionFactoryOptions options) {
175172
OracleR2dbcExceptions.requireNonNull(options, "options is null.");
176-
adapter = ReactiveJdbcAdapter.getOracleAdapter();
177-
dataSource = adapter.createDataSource(options);
173+
dataSource = ReactiveJdbcAdapter.getOracleAdapter()
174+
.createDataSource(options);
178175

179176
// Handle any Options that Oracle JDBC doesn't
180177
if (options.hasOption(ConnectionFactoryOptions.LOCK_WAIT_TIMEOUT)) {
@@ -218,15 +215,21 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {
218215
*/
219216
@Override
220217
public Publisher<Connection> create() {
221-
return Mono.defer(() ->
222-
Mono.fromDirect(adapter.publishConnection(dataSource)))
223-
.flatMap(conn -> {
224-
OracleConnectionImpl connection =
225-
new OracleConnectionImpl(conn, adapter);
226-
227-
return Mono.from(connection.setStatementTimeout(statementTimeout))
228-
.thenReturn(connection);
229-
});
218+
return Mono.defer(() -> {
219+
220+
// Create a new adapter for each connection. The adapter guards access
221+
// to a particular connection.
222+
ReactiveJdbcAdapter adapter = ReactiveJdbcAdapter.getOracleAdapter();
223+
224+
return Mono.fromDirect(adapter.publishConnection(dataSource))
225+
.flatMap(conn -> {
226+
OracleConnectionImpl connection =
227+
new OracleConnectionImpl(conn, adapter);
228+
229+
return Mono.from(connection.setStatementTimeout(statementTimeout))
230+
.thenReturn(connection);
231+
});
232+
});
230233
}
231234

232235
/**

0 commit comments

Comments
 (0)