4646import oracle .sql .INTERVALYM ;
4747import oracle .sql .TIMESTAMPLTZ ;
4848import oracle .sql .TIMESTAMPTZ ;
49+ import org .reactivestreams .Publisher ;
4950
5051import java .math .BigDecimal ;
5152import java .nio .ByteBuffer ;
9394class 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