Skip to content

Commit 0db9a7b

Browse files
committed
wip
1 parent 9cc2f09 commit 0db9a7b

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/main/java/io/r2dbc/postgresql/PostgresqlCopyIn.java

+7-17
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@
3131
import io.r2dbc.postgresql.message.frontend.Query;
3232
import io.r2dbc.postgresql.util.Assert;
3333
import org.reactivestreams.Publisher;
34-
import reactor.core.Disposable;
3534
import reactor.core.publisher.Flux;
3635
import reactor.core.publisher.Mono;
37-
import reactor.core.publisher.Sinks;
38-
import reactor.core.scheduler.Schedulers;
3936

4037
import java.nio.ByteBuffer;
4138

@@ -48,8 +45,6 @@ final class PostgresqlCopyIn {
4845

4946
private final ConnectionResources context;
5047

51-
private volatile boolean cancelled = false;
52-
5348
PostgresqlCopyIn(ConnectionResources context) {
5449
this.context = Assert.requireNonNull(context, "context must not be null");
5550
}
@@ -66,14 +61,15 @@ private Mono<Long> copyIn(String sql, Flux<FrontendMessage> frontendMessages) {
6661

6762
Flux<BackendMessage> backendMessages = frontendMessages
6863
.doOnNext(client::send)
69-
.doOnError(e -> !(e instanceof IllegalArgumentException), (e) -> {
70-
copyFail(e.getMessage()).subscribe();
71-
})
64+
.doOnError(e -> !(e instanceof IllegalArgumentException), (e) -> sendCopyFail(e.getMessage()))
7265
.doOnDiscard(ReferenceCounted.class, ReferenceCountUtil::release)
7366
.thenMany(client.exchange(Mono.just(CopyDone.INSTANCE)));
7467

7568
return startCopy(sql)
7669
.concatWith(backendMessages)
70+
.doOnCancel(() -> {
71+
sendCopyFail("Cancelled");
72+
})
7773
.as(messages -> toResult(context, messages, ExceptionFactory.INSTANCE).getRowsUpdated());
7874
}
7975

@@ -90,21 +86,15 @@ private Flux<BackendMessage> startCopy(String sql) {
9086
});
9187
}
9288

93-
private Flux<BackendMessage> copyFail(String message) {
94-
if (!cancelled) {
95-
cancelled = true;
96-
return context.getClient()
97-
.exchange(backendMessage -> backendMessage instanceof CommandComplete, Mono.just(new CopyFail("Copy operation failed: " + message)));
98-
}
99-
100-
return Flux.empty();
89+
private void sendCopyFail(String message) {
90+
context.getClient().exchange(m -> m instanceof CommandComplete, Mono.just(new CopyFail("Copy operation failed: " + message)))
91+
.subscribe();
10192
}
10293

10394
@Override
10495
public String toString() {
10596
return "PostgresqlCopyIn{" +
10697
"context=" + this.context +
107-
", cancelled=" + this.cancelled +
10898
'}';
10999
}
110100

src/test/java/io/r2dbc/postgresql/PostgresqlCopyInIntegrationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
package io.r2dbc.postgresql;
1818

1919
import io.r2dbc.postgresql.ExceptionFactory.PostgresqlBadGrammarException;
20-
import org.junit.Ignore;
2120
import org.junit.jupiter.api.AfterEach;
2221
import org.junit.jupiter.api.BeforeEach;
23-
import org.junit.jupiter.api.Disabled;
2422
import org.junit.jupiter.api.Test;
2523
import org.springframework.jdbc.core.JdbcOperations;
2624
import reactor.core.publisher.Flux;

0 commit comments

Comments
 (0)