Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF CURSOR Support #94

Merged
merged 9 commits into from
Oct 17, 2022
Prev Previous commit
Next Next commit
Supporting REF_CURSOR
  • Loading branch information
Michael-A-McMahon committed Sep 19, 2022
commit 4485bd19ea3999d50664e8c00b4dc509c5d70dcf
49 changes: 49 additions & 0 deletions src/main/java/oracle/r2dbc/impl/DependentResults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package oracle.r2dbc.impl;

import io.r2dbc.spi.Result;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Counts the number of results that depend on a statement. When the count
* reaches zero, the statement is closed.
*/
class DependentResults {


private final AtomicInteger count = new AtomicInteger(0);

private final Publisher<Void> closePublisher;

DependentResults(Publisher<Void> closePublisher) {
this.closePublisher = closePublisher;
}

/**
* Add a dependent result. The statement will not be closed until all results
* are removed.
* @param result
*/
void increment() {
count.incrementAndGet();
}

/**
* Removes a dependent result. This method closes the statement if all results
* have been removed.
*
* @return A publisher that completes after closing the statement if the last
* result has been removed. If more results remain, the returned publisher
* does nothing and emits onComplete.
*/
Publisher<Void> decrement() {
return Mono.defer(() ->
count.decrementAndGet() == 0
? Mono.from(closePublisher)
: Mono.empty());
}
}
2 changes: 2 additions & 0 deletions src/main/java/oracle/r2dbc/impl/OracleReadableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class OracleReadableImpl implements io.r2dbc.spi.Readable {
* {@code jdbcReadable} and obtains metadata of the values from
* {@code resultMetadata}.
* </p>
*
* @param jdbcReadable Readable values from a JDBC Driver. Not null.
* @param readablesMetadata Metadata of each value. Not null.
* @param adapter Adapts JDBC calls into reactive streams. Not null.
Expand Down Expand Up @@ -348,6 +349,7 @@ private LocalDateTime getLocalDateTime(int index) {
*/
private Result getResult(int index) {
ResultSet resultSet = jdbcReadable.getObject(index, ResultSet.class);

return resultSet == null
? null
: OracleResultImpl.createQueryResult(resultSet, adapter);
Expand Down
Loading