Skip to content

Commit ba7a5f2

Browse files
Updating ojdbc11 and README
1 parent 06021b5 commit ba7a5f2

File tree

7 files changed

+336
-227
lines changed

7 files changed

+336
-227
lines changed

README.md

Lines changed: 73 additions & 103 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<groupId>com.oracle.database.r2dbc</groupId>
2828
<artifactId>oracle-r2dbc</artifactId>
29-
<version>1.2.0</version>
29+
<version>1.3.0</version>
3030
<name>oracle-r2dbc</name>
3131
<description>
3232
Oracle R2DBC Driver implementing version 1.0.0 of the R2DBC SPI for Oracle Database.
@@ -65,9 +65,9 @@
6565

6666
<properties>
6767
<java.version>11</java.version>
68-
<ojdbc.version>23.5.0.24.07</ojdbc.version>
68+
<ojdbc.version>23.6.0.24.10</ojdbc.version>
6969
<r2dbc.version>1.0.0.RELEASE</r2dbc.version>
70-
<reactor.version>3.5.11</reactor.version>
70+
<reactor.version>3.6.11</reactor.version>
7171
<reactive-streams.version>1.0.3</reactive-streams.version>
7272
<junit.version>5.9.1</junit.version>
7373
<spring-jdbc.version>5.3.19</spring-jdbc.version>

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

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
import java.sql.SQLException;
3939
import java.sql.Savepoint;
4040
import java.time.Duration;
41-
import java.util.Queue;
42-
import java.util.concurrent.ConcurrentLinkedQueue;
41+
import java.util.Set;
42+
import java.util.concurrent.ConcurrentHashMap;
4343

4444
import static io.r2dbc.spi.IsolationLevel.READ_COMMITTED;
4545
import static io.r2dbc.spi.IsolationLevel.SERIALIZABLE;
4646
import static io.r2dbc.spi.TransactionDefinition.ISOLATION_LEVEL;
4747
import static io.r2dbc.spi.TransactionDefinition.LOCK_WAIT_TIMEOUT;
4848
import static io.r2dbc.spi.TransactionDefinition.NAME;
4949
import static io.r2dbc.spi.TransactionDefinition.READ_ONLY;
50-
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireNonNull;
5150
import static oracle.r2dbc.impl.OracleR2dbcExceptions.fromJdbc;
51+
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireNonNull;
5252
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireOpenConnection;
5353
import static oracle.r2dbc.impl.OracleR2dbcExceptions.runJdbc;
5454
import static oracle.r2dbc.impl.OracleR2dbcExceptions.toR2dbcException;
@@ -129,10 +129,10 @@ final class OracleConnectionImpl implements Connection, Lifecycle {
129129
private TransactionDefinition currentTransaction = null;
130130

131131
/**
132-
* A queue of tasks that must complete before the {@link #jdbcConnection} is
133-
* closed.
132+
* A set of tasks that must complete before the {@link #jdbcConnection} is
133+
* closed. The tasks are executed by subscribing to a Publisher.
134134
*/
135-
private final Queue<Publisher<?>> closeTasks = new ConcurrentLinkedQueue<>();
135+
private final Set<Publisher<?>> closeTasks = ConcurrentHashMap.newKeySet();
136136

137137
/**
138138
* Constructs a new connection that uses the specified {@code adapter} to
@@ -393,30 +393,36 @@ public Publisher<Void> close() {
393393
/**
394394
* <p>
395395
* Adds a publisher that must be subscribed to and must terminate before
396-
* closing the JDBC connection. This can be used to ensure that a publisher
397-
* has completed a task before the {@link #jdbcConnection()} has been closed
398-
* and becomes unusable.
396+
* closing the JDBC connection. This method can be used to ensure that certain
397+
* tasks are completed before the {@link #jdbcConnection()} is closed and
398+
* becomes unusable.
399399
* </p><p>
400-
* <i> A call to this method should always be accompanied with a call to
401-
* {@link #removeCloseTask(Publisher)}</i>: If the publisher is subscribed to
402-
* and it terminates before {@link #close()} is called, then any reference
403-
* to the Publisher must be removed so that it can be garbage collected.
400+
* The publisher returned by this method emits the same result as the
401+
* publisher passed into this method. However, when the returned publisher
402+
* terminates, it will also remove any reference to the publisher that was
403+
* passed into this method. <i>If the returned publisher is never subscribed
404+
* to, then the reference will not be cleared until the connection is
405+
* closed!</i> So, this method should only be used in cases where the user is
406+
* responsible for subscribing to the returned publisher, in the same way they
407+
* would be responsible for calling close() on an AutoCloseable. If the user
408+
* is not responsible for subscribing, then there is no reasonable way for
409+
* them to reduce the number object references that this method will create;
410+
* They would either need to close this connection, or subscribe to a
411+
* publisher when there is no obligation to do so.
404412
* </p>
405-
* @param publisher Publisher that must terminate before closing the JDBC
406-
* connection. Not null.
413+
*
414+
* @param publisher Publisher that must be subscribed to before closing the
415+
* JDBC connection. Not null.
416+
*
417+
* @return A publisher that emits the same result as the publisher passed into
418+
* this method, and clears any reference to it when terminated. Not null.
407419
*/
408-
void addCloseTask(Publisher<?> publisher) {
420+
<T> Publisher<T> addCloseTask(Publisher<T> publisher) {
409421
closeTasks.add(publisher);
410-
}
411422

412-
/**
413-
* Removes a publisher that was previously added with
414-
* {@link #addCloseTask(Publisher)}.
415-
*
416-
* @param publisher Publisher to remove. Not null.
417-
*/
418-
void removeCloseTask(Publisher<?> publisher) {
419-
closeTasks.remove(publisher);
423+
return Publishers.concatTerminal(
424+
publisher,
425+
Mono.fromRunnable(() -> closeTasks.remove(publisher)));
420426
}
421427

422428
/**
@@ -876,7 +882,7 @@ public Publisher<Void> preRelease() {
876882
* Returns the JDBC connection that this R2DBC connection executes database
877883
* calls with.
878884
*
879-
* @return The JDBC connection that backs this R2DBC connection. Not null.
885+
* @return The JDBC connection which backs this R2DBC connection. Not null.
880886
*/
881887
java.sql.Connection jdbcConnection() {
882888
return jdbcConnection;

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

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import oracle.sql.INTERVALYM;
4747
import oracle.sql.TIMESTAMPLTZ;
4848
import oracle.sql.TIMESTAMPTZ;
49+
import org.reactivestreams.Publisher;
4950

5051
import java.math.BigDecimal;
5152
import java.nio.ByteBuffer;
@@ -93,6 +94,9 @@
9394
class OracleReadableImpl implements io.r2dbc.spi.Readable {
9495

9596

97+
/** The R2DBC connection that created this readable */
98+
private final OracleConnectionImpl r2dbcConnection;
99+
96100
/** The JDBC connection that created this readable */
97101
private final java.sql.Connection jdbcConnection;
98102

@@ -117,21 +121,21 @@ class OracleReadableImpl implements io.r2dbc.spi.Readable {
117121
* {@code jdbcReadable} and obtains metadata of the values from
118122
* {@code resultMetadata}.
119123
* </p>
120-
* @param jdbcConnection JDBC connection that created the
124+
* @param r2dbcConnection R2DBC connection that created the
121125
* {@code jdbcReadable}. Not null.
122126
* @param jdbcReadable Readable values from a JDBC Driver. Not null.
123127
* @param readablesMetadata Metadata of each value. Not null.
124128
* @param adapter Adapts JDBC calls into reactive streams. Not null.
125129
*/
126130
private OracleReadableImpl(
127-
java.sql.Connection jdbcConnection, DependentCounter dependentCounter,
128-
JdbcReadable jdbcReadable, ReadablesMetadata<?> readablesMetadata,
129-
ReactiveJdbcAdapter adapter) {
130-
this.jdbcConnection = jdbcConnection;
131+
OracleConnectionImpl r2dbcConnection, DependentCounter dependentCounter,
132+
JdbcReadable jdbcReadable, ReadablesMetadata<?> readablesMetadata) {
133+
this.r2dbcConnection = r2dbcConnection;
134+
this.jdbcConnection = r2dbcConnection.jdbcConnection();
131135
this.dependentCounter = dependentCounter;
132136
this.jdbcReadable = jdbcReadable;
133137
this.readablesMetadata = readablesMetadata;
134-
this.adapter = adapter;
138+
this.adapter = r2dbcConnection.adapter();
135139
}
136140

137141
/**
@@ -151,11 +155,10 @@ private OracleReadableImpl(
151155
* {@code metadata}. Not null.
152156
*/
153157
static Row createRow(
154-
java.sql.Connection jdbcConnection, DependentCounter dependentCounter,
155-
JdbcReadable jdbcReadable, RowMetadataImpl metadata,
156-
ReactiveJdbcAdapter adapter) {
158+
OracleConnectionImpl r2dbcConnection, DependentCounter dependentCounter,
159+
JdbcReadable jdbcReadable, RowMetadataImpl metadata) {
157160
return new RowImpl(
158-
jdbcConnection, dependentCounter, jdbcReadable, metadata, adapter);
161+
r2dbcConnection, dependentCounter, jdbcReadable, metadata);
159162
}
160163

161164
/**
@@ -164,7 +167,7 @@ static Row createRow(
164167
* the provided {@code jdbcReadable} and {@code rowMetadata}. The metadata
165168
* object is used to determine the default type mapping of column values.
166169
* </p>
167-
* @param jdbcConnection JDBC connection that created the
170+
* @param r2dbcConnection R2DBC connection that created the
168171
* {@code jdbcReadable}. Not null.
169172
* @param dependentCounter Counter that is increased for each dependent
170173
* {@code Result} created by the returned {@code OutParameters}
@@ -175,11 +178,10 @@ static Row createRow(
175178
* {@code metadata}. Not null.
176179
*/
177180
static OutParameters createOutParameters(
178-
java.sql.Connection jdbcConnection, DependentCounter dependentCounter,
179-
JdbcReadable jdbcReadable, OutParametersMetadataImpl metadata,
180-
ReactiveJdbcAdapter adapter) {
181+
OracleConnectionImpl r2dbcConnection, DependentCounter dependentCounter,
182+
JdbcReadable jdbcReadable, OutParametersMetadataImpl metadata) {
181183
return new OutParametersImpl(
182-
jdbcConnection, dependentCounter, jdbcReadable, metadata, adapter);
184+
r2dbcConnection, dependentCounter, jdbcReadable, metadata);
183185
}
184186

185187
/**
@@ -335,11 +337,16 @@ private ByteBuffer getByteBuffer(int index) {
335337
*/
336338
private Blob getBlob(int index) {
337339
java.sql.Blob jdbcBlob = jdbcReadable.getObject(index, java.sql.Blob.class);
338-
return jdbcBlob == null
339-
? null
340-
: OracleLargeObjects.createBlob(
341-
adapter.publishBlobRead(jdbcBlob),
342-
adapter.publishBlobFree(jdbcBlob));
340+
341+
if (jdbcBlob == null)
342+
return null;
343+
344+
Publisher<Void> freePublisher =
345+
r2dbcConnection.addCloseTask(adapter.publishBlobFree(jdbcBlob));
346+
347+
return OracleLargeObjects.createBlob(
348+
adapter.publishBlobRead(jdbcBlob),
349+
freePublisher);
343350
}
344351

345352
/**
@@ -367,11 +374,15 @@ private Clob getClob(int index) {
367374
jdbcClob = jdbcReadable.getObject(index, java.sql.Clob.class);
368375
}
369376

370-
return jdbcClob == null
371-
? null
372-
: OracleLargeObjects.createClob(
373-
adapter.publishClobRead(jdbcClob),
374-
adapter.publishClobFree(jdbcClob));
377+
if (jdbcClob == null)
378+
return null;
379+
380+
Publisher<Void> freePublisher =
381+
r2dbcConnection.addCloseTask(adapter.publishClobFree(jdbcClob));
382+
383+
return OracleLargeObjects.createClob(
384+
adapter.publishClobRead(jdbcClob),
385+
freePublisher);
375386
}
376387

377388
/**
@@ -685,11 +696,10 @@ private OracleR2dbcObjectImpl getOracleR2dbcObject(int index) {
685696
return null;
686697

687698
return new OracleR2dbcObjectImpl(
688-
jdbcConnection,
699+
r2dbcConnection,
689700
dependentCounter,
690701
new StructJdbcReadable(oracleStruct),
691-
ReadablesMetadata.createAttributeMetadata(oracleStruct),
692-
adapter);
702+
ReadablesMetadata.createAttributeMetadata(oracleStruct));
693703
}
694704

695705
/**
@@ -956,7 +966,7 @@ private Result getResult(int index) {
956966

957967
dependentCounter.increment();
958968
return OracleResultImpl.createQueryResult(
959-
dependentCounter, resultSet, adapter);
969+
r2dbcConnection, dependentCounter, resultSet);
960970
}
961971

962972
/**
@@ -994,17 +1004,16 @@ private static final class RowImpl
9941004
* {@code jdbcReadable}, and uses the specified {@code rowMetadata} to
9951005
* determine the default type mapping of column values.
9961006
* </p>
997-
* @param jdbcConnection JDBC connection that created the
1007+
* @param r2dbcConnection R2DBC connection that created the
9981008
* {@code jdbcReadable}. Not null.
9991009
* @param jdbcReadable Row data from the Oracle JDBC Driver. Not null.
10001010
* @param metadata Meta-data for the specified row. Not null.
10011011
* @param adapter Adapts JDBC calls into reactive streams. Not null.
10021012
*/
10031013
private RowImpl(
1004-
java.sql.Connection jdbcConnection, DependentCounter dependentCounter,
1005-
JdbcReadable jdbcReadable, RowMetadataImpl metadata,
1006-
ReactiveJdbcAdapter adapter) {
1007-
super(jdbcConnection, dependentCounter, jdbcReadable, metadata, adapter);
1014+
OracleConnectionImpl r2dbcConnection, DependentCounter dependentCounter,
1015+
JdbcReadable jdbcReadable, RowMetadataImpl metadata) {
1016+
super(r2dbcConnection, dependentCounter, jdbcReadable, metadata);
10081017
this.metadata = metadata;
10091018
}
10101019

@@ -1044,10 +1053,9 @@ private static final class OutParametersImpl
10441053
* @param adapter Adapts JDBC calls into reactive streams. Not null.
10451054
*/
10461055
private OutParametersImpl(
1047-
java.sql.Connection jdbcConnection, DependentCounter dependentCounter,
1048-
JdbcReadable jdbcReadable, OutParametersMetadataImpl metadata,
1049-
ReactiveJdbcAdapter adapter) {
1050-
super(jdbcConnection, dependentCounter, jdbcReadable, metadata, adapter);
1056+
OracleConnectionImpl r2dbcConnection, DependentCounter dependentCounter,
1057+
JdbcReadable jdbcReadable, OutParametersMetadataImpl metadata) {
1058+
super(r2dbcConnection, dependentCounter, jdbcReadable, metadata);
10511059
this.metadata = metadata;
10521060
}
10531061

@@ -1068,20 +1076,18 @@ private final class OracleR2dbcObjectImpl
10681076
* {@code jdbcReadable} and obtains metadata of the values from
10691077
* {@code outParametersMetaData}.
10701078
* </p>
1071-
* @param jdbcConnection JDBC connection that created the
1079+
* @param r2dbcConnection R2DBC connection that created the
10721080
* {@code jdbcReadable}. Not null.
10731081
* @param structJdbcReadable Readable values from a JDBC Driver. Not null.
10741082
* @param metadata Metadata of each value. Not null.
10751083
* @param adapter Adapts JDBC calls into reactive streams. Not null.
10761084
*/
10771085
private OracleR2dbcObjectImpl(
1078-
java.sql.Connection jdbcConnection,
1086+
OracleConnectionImpl r2dbcConnection,
10791087
DependentCounter dependentCounter,
10801088
StructJdbcReadable structJdbcReadable,
1081-
OracleR2dbcObjectMetadataImpl metadata,
1082-
ReactiveJdbcAdapter adapter) {
1083-
super(
1084-
jdbcConnection, dependentCounter, structJdbcReadable, metadata, adapter);
1089+
OracleR2dbcObjectMetadataImpl metadata) {
1090+
super(r2dbcConnection, dependentCounter, structJdbcReadable, metadata);
10851091
this.metadata = metadata;
10861092
}
10871093

0 commit comments

Comments
 (0)