Skip to content

Commit 9fa16c3

Browse files
committed
Polishing
[fixes #341][#373]
1 parent 03ad3f5 commit 9fa16c3

6 files changed

+31
-19
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class ExtendedQueryPostgresqlStatement implements PostgresqlStatement {
5959
private String[] generatedColumns;
6060

6161
ExtendedQueryPostgresqlStatement(ConnectionResources resources, String sql) {
62-
this.resources = Assert.requireNonNull(resources, "context must not be null");
62+
this.resources = Assert.requireNonNull(resources, "resources must not be null");
6363
this.connectionContext = resources.getClient().getContext();
6464
this.sql = Assert.requireNonNull(sql, "sql must not be null");
6565
this.bindings = new Bindings(expectedSize(sql));

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

+11-13
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
*/
4444
final class PostgresqlResult extends AbstractReferenceCounted implements io.r2dbc.postgresql.api.PostgresqlResult {
4545

46-
private static final Predicate<BackendMessage> TAKE_UNTIL = or(CommandComplete.class::isInstance, EmptyQueryResponse.class::isInstance);
47-
48-
private final ConnectionResources context;
46+
private final ConnectionResources resources;
4947

5048
private final Flux<BackendMessage> messages;
5149

@@ -55,10 +53,10 @@ final class PostgresqlResult extends AbstractReferenceCounted implements io.r2db
5553

5654
private volatile RowDescription rowDescription;
5755

58-
private PostgresqlResult(ConnectionResources context, Flux<BackendMessage> messages, ExceptionFactory factory) {
59-
this.context = context;
60-
this.messages = messages;
61-
this.factory = factory;
56+
PostgresqlResult(ConnectionResources resources, Flux<BackendMessage> messages, ExceptionFactory factory) {
57+
this.resources = Assert.requireNonNull(resources, "resources must not be null");
58+
this.messages = Assert.requireNonNull(messages, "messages must not be null");
59+
this.factory = Assert.requireNonNull(factory, "factory must not be null");
6260
}
6361

6462
@Override
@@ -92,7 +90,7 @@ public Mono<Integer> getRowsUpdated() {
9290
public <T> Flux<T> map(BiFunction<Row, RowMetadata, ? extends T> f) {
9391
Assert.requireNonNull(f, "f must not be null");
9492

95-
return this.messages.takeUntil(TAKE_UNTIL)
93+
return this.messages
9694
.handle((message, sink) -> {
9795

9896
try {
@@ -103,12 +101,12 @@ public <T> Flux<T> map(BiFunction<Row, RowMetadata, ? extends T> f) {
103101

104102
if (message instanceof RowDescription) {
105103
this.rowDescription = (RowDescription) message;
106-
this.metadata = PostgresqlRowMetadata.toRowMetadata(this.context.getCodecs(), (RowDescription) message);
104+
this.metadata = PostgresqlRowMetadata.toRowMetadata(this.resources.getCodecs(), (RowDescription) message);
107105
return;
108106
}
109107

110108
if (message instanceof DataRow) {
111-
PostgresqlRow row = PostgresqlRow.toRow(this.context, (DataRow) message, this.rowDescription);
109+
PostgresqlRow row = PostgresqlRow.toRow(this.resources, (DataRow) message, this.rowDescription);
112110
sink.next(f.apply(row, this.metadata));
113111
}
114112

@@ -133,13 +131,13 @@ public ReferenceCounted touch(Object hint) {
133131
@Override
134132
public String toString() {
135133
return "PostgresqlResult{" +
136-
"context=" + this.context +
134+
"context=" + this.resources +
137135
", messages=" + this.messages +
138136
'}';
139137
}
140138

141-
static PostgresqlResult toResult(ConnectionResources context, Flux<BackendMessage> messages, ExceptionFactory factory) {
142-
return new PostgresqlResult(context, messages, factory);
139+
static PostgresqlResult toResult(ConnectionResources resources, Flux<BackendMessage> messages, ExceptionFactory factory) {
140+
return new PostgresqlResult(resources, messages, factory);
143141
}
144142

145143
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class SimpleQueryPostgresqlStatement implements PostgresqlStatement {
5555
private int fetchSize;
5656

5757
SimpleQueryPostgresqlStatement(ConnectionResources resources, String sql) {
58-
this.resources = Assert.requireNonNull(resources, "context must not be null");
58+
this.resources = Assert.requireNonNull(resources, "resources must not be null");
5959
this.sql = Assert.requireNonNull(sql, "sql must not be null");
6060
fetchSize(isBatch() ? NO_LIMIT : this.resources.getConfiguration().getFetchSize(sql));
6161
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ void bindWrongIdentifierFormat() {
143143
}
144144

145145
@Test
146-
void constructorNoContext() {
146+
void constructorNoResources() {
147147
assertThatIllegalArgumentException().isThrownBy(() -> new ExtendedQueryPostgresqlStatement(null, "test-query"))
148-
.withMessage("context must not be null");
148+
.withMessage("resources must not be null");
149149
}
150150

151151
@Test

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

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import java.util.Collections;
2828

29+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
30+
2931
/**
3032
* Unit tests for {@link PostgresqlResult}.
3133
*/
@@ -58,6 +60,18 @@ void toResultEmptyQueryResponse() {
5860
.verifyComplete();
5961
}
6062

63+
@Test
64+
void toResultNoContext() {
65+
assertThatIllegalArgumentException().isThrownBy(() -> PostgresqlResult.toResult(null, Flux.empty(), ExceptionFactory.INSTANCE))
66+
.withMessage("resources must not be null");
67+
}
68+
69+
@Test
70+
void toResultNoMessages() {
71+
assertThatIllegalArgumentException().isThrownBy(() -> PostgresqlResult.toResult(MockContext.empty(), null, ExceptionFactory.INSTANCE))
72+
.withMessage("messages must not be null");
73+
}
74+
6175
@Test
6276
void toResultRowDescriptionRowsUpdated() {
6377
PostgresqlResult result = PostgresqlResult.toResult(MockContext.empty(), Flux.just(new RowDescription(Collections.emptyList()), new DataRow(), new CommandComplete

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ void fetchSizeWithOneQuery() {
106106
}
107107

108108
@Test
109-
void constructorNoContext() {
109+
void constructorNoResources() {
110110
assertThatIllegalArgumentException().isThrownBy(() -> new SimpleQueryPostgresqlStatement(null, "test-query"))
111-
.withMessage("context must not be null");
111+
.withMessage("resources must not be null");
112112
}
113113

114114
@Test

0 commit comments

Comments
 (0)