|
99 | 99 | */ |
100 | 100 | final class OracleConnectionFactoryImpl implements ConnectionFactory { |
101 | 101 |
|
102 | | - /** Adapts Oracle JDBC Driver APIs into Reactive Streams APIs */ |
103 | | - private final ReactiveJdbcAdapter adapter; |
104 | | - |
105 | 102 | /** JDBC data source that this factory uses to open connections */ |
106 | 103 | private final DataSource dataSource; |
107 | 104 |
|
@@ -173,8 +170,8 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory { |
173 | 170 | */ |
174 | 171 | OracleConnectionFactoryImpl(ConnectionFactoryOptions options) { |
175 | 172 | OracleR2dbcExceptions.requireNonNull(options, "options is null."); |
176 | | - adapter = ReactiveJdbcAdapter.getOracleAdapter(); |
177 | | - dataSource = adapter.createDataSource(options); |
| 173 | + dataSource = ReactiveJdbcAdapter.getOracleAdapter() |
| 174 | + .createDataSource(options); |
178 | 175 |
|
179 | 176 | // Handle any Options that Oracle JDBC doesn't |
180 | 177 | if (options.hasOption(ConnectionFactoryOptions.LOCK_WAIT_TIMEOUT)) { |
@@ -218,15 +215,21 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory { |
218 | 215 | */ |
219 | 216 | @Override |
220 | 217 | 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 | + }); |
230 | 233 | } |
231 | 234 |
|
232 | 235 | /** |
|
0 commit comments